Skip to content

Commit 1157293

Browse files
committed
Add dummy LibraryEntry code
1 parent 245c1b3 commit 1157293

1 file changed

Lines changed: 34 additions & 3 deletions

File tree

OpenFlowNodeRED/src/node-red-contrib-openflow-storage.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ export class noderedcontribopenflowstorage {
4747
this.saveSettings = (this._saveSettings.bind(this));
4848
this.getSessions = (this._getSessions.bind(this));
4949
this.saveSessions = (this._saveSessions.bind(this));
50-
// this.getLibraryEntry = (this._getLibraryEntry.bind(this));
51-
// this.saveLibraryEntry = (this._saveLibraryEntry.bind(this));
50+
this.getLibraryEntry = (this._getLibraryEntry.bind(this));
51+
this.saveLibraryEntry = (this._saveLibraryEntry.bind(this));
5252
}
5353

5454
// compare contents of two objects and return a list of differences
@@ -967,7 +967,6 @@ export class noderedcontribopenflowstorage {
967967
}
968968
Logger.instanse.info(" _saveSettings - COMPLETE!!! " + new Date().toLocaleTimeString());
969969
}
970-
971970
public async _getSessions(): Promise<any[]> {
972971
let item: any[] = [];
973972
try {
@@ -1015,5 +1014,37 @@ export class noderedcontribopenflowstorage {
10151014
Logger.instanse.error(error);
10161015
}
10171016
}
1017+
public async _saveLibraryEntry(type, path, meta, body): Promise<void> {
1018+
try {
1019+
// if (type === "flows" && !path.endsWith(".json")) {
1020+
// path += ".json";
1021+
// }
1022+
// const filename: string = Config.nodered_id + "_sessions";
1023+
const item = { type, path, meta, body, _type: "library", nodered_id: Config.nodered_id };
1024+
// await this.backupStore.set(filename, JSON.stringify(sessions));
1025+
if (WebSocketClient.instance.isConnected()) {
1026+
this.last_reload = new Date();
1027+
// const result = await NoderedUtil.Query("nodered", { _type: "library", nodered_id: Config.nodered_id }, null, null, 1, 0, null);
1028+
const result = await NoderedUtil.InsertOrUpdateOne("nodered", item, "_type,nodered_id,type,path", 1, true, null);
1029+
this.last_reload = new Date();
1030+
}
1031+
} catch (error) {
1032+
Logger.instanse.error(error);
1033+
}
1034+
}
1035+
public async _getLibraryEntry(type, path): Promise<any> {
1036+
try {
1037+
Logger.instanse.silly("noderedcontribopenflowstorage::_getSessions");
1038+
if (WebSocketClient.instance.isConnected()) {
1039+
const result = await NoderedUtil.Query("nodered", { _type: "library", nodered_id: Config.nodered_id, type, path }, null, null, 1, 0, null);
1040+
if (result.length === 0) { return null; }
1041+
var item = JSON.parse(result[0].sessions);
1042+
return item.body;
1043+
}
1044+
} catch (error) {
1045+
Logger.instanse.error(error);
1046+
}
1047+
return null;
1048+
}
10181049

10191050
}

0 commit comments

Comments
 (0)