anote-server-libs 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/services/utils.js +14 -5
- package/services/utils.ts +12 -5
package/package.json
CHANGED
package/services/utils.js
CHANGED
|
@@ -87,30 +87,39 @@ function idempotent(repo, debug, logger) {
|
|
|
87
87
|
if (!call) {
|
|
88
88
|
const jsonTerminator = res.json;
|
|
89
89
|
const endTerminator = res.end;
|
|
90
|
+
const writeTerminator = res.write;
|
|
91
|
+
let response = '';
|
|
90
92
|
res.json = (function (obj) {
|
|
91
93
|
repo.ApiCall.create({
|
|
92
94
|
id: idempotenceKey,
|
|
93
95
|
responseCode: res.statusCode,
|
|
94
96
|
responseJson: jsonStringify(obj),
|
|
95
97
|
expiresAt: new Date(Date.now() + 24 * 60 * 60 * 1000)
|
|
96
|
-
}).then(() => jsonTerminator(obj), err => {
|
|
98
|
+
}).then(() => jsonTerminator.call(res, obj), err => {
|
|
97
99
|
if (err)
|
|
98
100
|
logger.warn('Cannot save idempotent key: %j', err);
|
|
99
|
-
jsonTerminator(obj);
|
|
101
|
+
jsonTerminator.call(res, obj);
|
|
100
102
|
});
|
|
101
103
|
}).bind(res);
|
|
102
104
|
res.end = (function (buf) {
|
|
105
|
+
if (buf)
|
|
106
|
+
response = response + buf.toString();
|
|
103
107
|
repo.ApiCall.create({
|
|
104
108
|
id: idempotenceKey,
|
|
105
109
|
responseCode: res.statusCode,
|
|
106
|
-
responseJson:
|
|
110
|
+
responseJson: response,
|
|
107
111
|
expiresAt: new Date(Date.now() + 24 * 60 * 60 * 1000)
|
|
108
|
-
}).then(() => endTerminator(), err => {
|
|
112
|
+
}).then(() => endTerminator.call(res, buf), err => {
|
|
109
113
|
if (err)
|
|
110
114
|
logger.warn('Cannot save idempotent key: %j', err);
|
|
111
|
-
endTerminator();
|
|
115
|
+
endTerminator.call(res, buf);
|
|
112
116
|
});
|
|
113
117
|
}).bind(res);
|
|
118
|
+
res.write = (function (buf) {
|
|
119
|
+
if (buf)
|
|
120
|
+
response = response + buf.toString();
|
|
121
|
+
writeTerminator.call(res, buf);
|
|
122
|
+
}).bind(res);
|
|
114
123
|
next();
|
|
115
124
|
}
|
|
116
125
|
else
|
package/services/utils.ts
CHANGED
|
@@ -86,28 +86,35 @@ export function idempotent(repo: BaseModelRepository, debug: boolean, logger: Lo
|
|
|
86
86
|
if(!call) {
|
|
87
87
|
const jsonTerminator = res.json;
|
|
88
88
|
const endTerminator = res.end;
|
|
89
|
+
const writeTerminator = res.write;
|
|
90
|
+
let response = '';
|
|
89
91
|
res.json = (function(obj: any) {
|
|
90
92
|
repo.ApiCall.create({
|
|
91
93
|
id: idempotenceKey,
|
|
92
94
|
responseCode: res.statusCode,
|
|
93
95
|
responseJson: jsonStringify(obj),
|
|
94
96
|
expiresAt: new Date(Date.now() + 24 * 60 * 60 * 1000)
|
|
95
|
-
}).then(() => jsonTerminator(obj), err => {
|
|
97
|
+
}).then(() => jsonTerminator.call(res, obj), err => {
|
|
96
98
|
if(err) logger.warn('Cannot save idempotent key: %j', err);
|
|
97
|
-
jsonTerminator(obj);
|
|
99
|
+
jsonTerminator.call(res, obj);
|
|
98
100
|
});
|
|
99
101
|
}).bind(res);
|
|
100
102
|
res.end = (function(buf: string) {
|
|
103
|
+
if(buf) response = response + buf.toString();
|
|
101
104
|
repo.ApiCall.create({
|
|
102
105
|
id: idempotenceKey,
|
|
103
106
|
responseCode: res.statusCode,
|
|
104
|
-
responseJson:
|
|
107
|
+
responseJson: response,
|
|
105
108
|
expiresAt: new Date(Date.now() + 24 * 60 * 60 * 1000)
|
|
106
|
-
}).then(() => endTerminator(), err => {
|
|
109
|
+
}).then(() => endTerminator.call(res, buf), err => {
|
|
107
110
|
if(err) logger.warn('Cannot save idempotent key: %j', err);
|
|
108
|
-
endTerminator();
|
|
111
|
+
endTerminator.call(res, buf);
|
|
109
112
|
});
|
|
110
113
|
}).bind(res);
|
|
114
|
+
res.write = (function(buf: string) {
|
|
115
|
+
if(buf) response = response + buf.toString();
|
|
116
|
+
writeTerminator.call(res, buf);
|
|
117
|
+
}).bind(res);
|
|
111
118
|
next();
|
|
112
119
|
} else res.status(417).json({
|
|
113
120
|
responseCode: call.responseCode,
|