Skip to content

Commit c90d7c6

Browse files
committed
small fixes
1 parent 168c8a9 commit c90d7c6

9 files changed

Lines changed: 96 additions & 63 deletions

File tree

OpenFlow/src/DatabaseConnection.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,10 @@ export class DatabaseConnection {
648648

649649
original = await this.getbyid<T>(q.item._id, q.collectionname, q.jwt);
650650
if (!original) { throw Error("item not found!"); }
651-
if (!this.hasAuthorization(user, original, Rights.update)) { throw new Error("Access denied, no authorization to UpdateOne " + q.item._type + " " + name + " to database"); }
651+
if (!this.hasAuthorization(user, original, Rights.update)) {
652+
var again = this.hasAuthorization(user, original, Rights.update);
653+
throw new Error("Access denied, no authorization to UpdateOne " + q.item._type + " " + name + " to database");
654+
}
652655
if (q.collectionname != "fs.files") {
653656
q.item._modifiedby = user.name;
654657
q.item._modifiedbyid = user._id;

OpenFlow/src/WebSocketServer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ export class WebSocketServer {
6969
cli.Close();
7070
return false;
7171
}
72-
return cli.ping();
72+
cli.ping();
73+
if (!cli.connected() && cli.queuecount() == 0) return false;
74+
return true;
7375
});
7476
if (count !== WebSocketServer._clients.length) {
7577
WebSocketServer._logger.info("new client count: " + WebSocketServer._clients.length);

OpenFlow/src/WebSocketServerClient.ts

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,49 @@ export class WebSocketServerClient {
6161
private error(e: Event): void {
6262
this._logger.error("WebSocket error encountered " + e);
6363
}
64+
public queuecount(): number {
65+
if (this.queues == null) return 0;
66+
var keys = Object.keys(this.queues);
67+
return keys.length;
68+
}
69+
public connected(): boolean {
70+
if (this._socketObject == null) return false;
71+
if (this._socketObject.readyState === this._socketObject.OPEN || this._socketObject.readyState === this._socketObject.CONNECTING) {
72+
return true;
73+
}
74+
if (this._socketObject.readyState === this._socketObject.CLOSED) {
75+
delete this._socketObject;
76+
}
77+
return false;
78+
}
79+
public ping(): void {
80+
try {
81+
let msg: SocketMessage = SocketMessage.fromcommand("ping");
82+
if (this._socketObject == null) {
83+
if (this.queuecount() > 0) {
84+
this.CloseConsumers();
85+
}
86+
return;
87+
}
88+
if (this._socketObject.readyState === this._socketObject.CLOSED || this._socketObject.readyState === this._socketObject.CLOSING) {
89+
if (this.queuecount() > 0) {
90+
this.CloseConsumers();
91+
}
92+
return;
93+
}
94+
this._socketObject.send(msg.tojson());
95+
} catch (error) {
96+
this._logger.error("WebSocketclient::WebSocket error encountered " + error);
97+
this._receiveQueue = [];
98+
this._sendQueue = [];
99+
try {
100+
if (this._socketObject != null) {
101+
this.Close();
102+
}
103+
} catch (error) {
104+
}
105+
}
106+
}
64107
private message(message: string): void { // e: MessageEvent
65108
try {
66109
//this._logger.silly("WebSocket message received " + message);
@@ -87,6 +130,14 @@ export class WebSocketServerClient {
87130
public async Close(): Promise<void> {
88131
await this.CloseConsumers();
89132
if (this._socketObject != null) {
133+
try {
134+
this._socketObject.removeListener("open", (e: Event): void => this.open(e));
135+
this._socketObject.removeListener("message", (e: string): void => this.message(e)); // e: MessageEvent
136+
this._socketObject.removeListener("error", (e: Event): void => this.error(e));
137+
this._socketObject.removeListener("close", (e: CloseEvent): void => this.close(e));
138+
} catch (error) {
139+
this._logger.error("WebSocketclient::Close::removeListener " + error);
140+
}
90141
try {
91142
this._socketObject.close();
92143
} catch (error) {
@@ -158,39 +209,6 @@ export class WebSocketServerClient {
158209
setTimeout(resolve, ms)
159210
})
160211
}
161-
public ping(): boolean {
162-
try {
163-
let msg: SocketMessage = SocketMessage.fromcommand("ping");
164-
var keys = Object.keys(this.queues);
165-
if (this._socketObject == null) {
166-
if (keys.length > 0) {
167-
this.CloseConsumers();
168-
return true;
169-
}
170-
return false;
171-
}
172-
if (this._socketObject.readyState === this._socketObject.CLOSED || this._socketObject.readyState === this._socketObject.CLOSING) {
173-
if (keys.length > 0) {
174-
this.CloseConsumers();
175-
return true;
176-
}
177-
return false;
178-
}
179-
this._socketObject.send(msg.tojson());
180-
return true;
181-
} catch (error) {
182-
this._logger.error("WebSocketclient::WebSocket error encountered " + error);
183-
this._receiveQueue = [];
184-
this._sendQueue = [];
185-
try {
186-
if (this._socketObject != null) {
187-
this._socketObject.close();
188-
}
189-
} catch (error) {
190-
}
191-
return true;
192-
}
193-
}
194212
private ProcessQueue(): void {
195213
let username: string = "Unknown";
196214
if (!NoderedUtil.IsNullUndefinded(this.user)) { username = this.user.username; }

OpenFlow/src/public/Controllers.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,17 +2337,21 @@ export class EntityCtrl extends entityCtrl<Base> {
23372337
return;
23382338
}
23392339
}
2340-
if (this.model._id) {
2341-
await NoderedUtil.UpdateOne(this.collection, null, this.model, 1, false, null);
2342-
} else {
2343-
await NoderedUtil.InsertOne(this.collection, this.model, 1, false, null);
2344-
}
2345-
if (this.collection == "files") {
2346-
this.$location.path("/Files");
2347-
if (!this.$scope.$$phase) { this.$scope.$apply(); }
2348-
return;
2340+
try {
2341+
if (this.model._id) {
2342+
await NoderedUtil.UpdateOne(this.collection, null, this.model, 1, false, null);
2343+
} else {
2344+
await NoderedUtil.InsertOne(this.collection, this.model, 1, false, null);
2345+
}
2346+
if (this.collection == "files") {
2347+
this.$location.path("/Files");
2348+
if (!this.$scope.$$phase) { this.$scope.$apply(); }
2349+
return;
2350+
}
2351+
this.$location.path("/Entities/" + this.collection);
2352+
} catch (error) {
2353+
this.errormessage = error;
23492354
}
2350-
this.$location.path("/Entities/" + this.collection);
23512355
if (!this.$scope.$$phase) { this.$scope.$apply(); }
23522356
}
23532357
removekey(key) {

OpenFlowNodeRED/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openflow-nodered",
3-
"version": "1.0.65",
3+
"version": "1.0.66",
44
"description": "Simple wrapper around NodeRed, RabbitMQ and MongoDB to support a more scaleable NodeRed implementation.\r Also the \"backend\" for [OpenRPA](https://github.com/skadefro/OpenRPA)",
55
"main": "index.js",
66
"scripts": {
@@ -38,7 +38,7 @@
3838
"node-gyp": "^7.0.0",
3939
"node-red": "^1.1.0",
4040
"node-red-node-email": "^1.7.8",
41-
"openflow-api": "^1.0.12",
41+
"openflow-api": "^1.0.13",
4242
"os-service": "^2.2.0",
4343
"passport-saml": "^1.3.3",
4444
"passport-saml-metadata": "^2.3.0",

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,21 @@ export class noderedcontribopenflowstorage {
4545
fs.statSync(packageFile);
4646
this._logger.debug(packageFile + " exists.");
4747
} catch (err) {
48-
var defaultPackage: any = {
49-
"name": "openflow-project",
50-
"license": "MPL-2.0",
51-
"description": "A OpenFlow Node-RED Project",
52-
"version": "0.0.1",
53-
"repository": {
54-
"type": "git",
55-
"url": "git+https://github.com/open-rpa/openflow.git"
56-
},
57-
};
58-
this._logger.debug("creating new packageFile " + packageFile);
59-
fs.writeFileSync(packageFile, JSON.stringify(defaultPackage, null, 4));
6048
}
49+
// Lets overwrite each time!
50+
var defaultPackage: any = {
51+
"name": "openflow-project",
52+
"license": "MPL-2.0",
53+
"description": "A OpenFlow Node-RED Project",
54+
"version": "0.0.1",
55+
"repository": {
56+
"type": "git",
57+
"url": "git+https://github.com/open-rpa/openflow.git"
58+
},
59+
};
60+
this._logger.debug("creating new packageFile " + packageFile);
61+
fs.writeFileSync(packageFile, JSON.stringify(defaultPackage, null, 4));
62+
6163
// var dbsettings = await this._getSettings();
6264
// spawn gettings, so it starts installing
6365
return true;

OpenFlowNodeRED/tsconfig.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@
1212
"dom"
1313
]
1414
// "lib": ["es2015.promise", "dom"]
15-
}
15+
},
16+
"exclude": [
17+
"../dist",
18+
"dist"
19+
]
1620
}

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.65
1+
1.0.66

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openiap",
3-
"version": "1.0.65",
3+
"version": "1.0.66",
44
"description": "Simple wrapper around NodeRed, RabbitMQ and MongoDB to support a more scaleable NodeRed implementation.\r Also the \"backend\" for [OpenRPA](https://github.com/skadefro/OpenRPA)",
55
"main": "index.js",
66
"scripts": {
@@ -58,7 +58,7 @@
5858
"morgan": "^1.10.0",
5959
"multer": "^1.4.2",
6060
"multer-gridfs-storage": "^4.2.0",
61-
"openflow-api": "^1.0.12",
61+
"openflow-api": "^1.0.13",
6262
"os-service": "^2.2.0",
6363
"passport": "^0.4.1",
6464
"passport-google-oauth20": "^2.0.0",

0 commit comments

Comments
 (0)