@blocklet/uploader-server 0.1.99 → 0.1.101
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/es/middlewares/companion.js +39 -0
- package/es/utils.js +2 -2
- package/lib/middlewares/companion.js +39 -0
- package/lib/utils.js +2 -2
- package/package.json +5 -5
|
@@ -3,6 +3,7 @@ import bodyParser from "body-parser";
|
|
|
3
3
|
import session from "express-session";
|
|
4
4
|
import crypto from "crypto";
|
|
5
5
|
const secret = crypto.randomBytes(32).toString("hex");
|
|
6
|
+
const REWRITE_500_STATUS_CODE = 400;
|
|
6
7
|
export function initCompanion({
|
|
7
8
|
path,
|
|
8
9
|
express,
|
|
@@ -44,6 +45,44 @@ export function initCompanion({
|
|
|
44
45
|
hackerCompanion.options.providerOptions = dynamicProviderOptions;
|
|
45
46
|
}
|
|
46
47
|
});
|
|
48
|
+
const originalStatus = res.status.bind(res);
|
|
49
|
+
const originalSendStatus = res.sendStatus.bind(res);
|
|
50
|
+
const originalWriteHead = res.writeHead.bind(res);
|
|
51
|
+
res.status = (code) => {
|
|
52
|
+
if (code >= 500) {
|
|
53
|
+
return originalStatus(REWRITE_500_STATUS_CODE);
|
|
54
|
+
}
|
|
55
|
+
return originalStatus(code);
|
|
56
|
+
};
|
|
57
|
+
res.sendStatus = (code) => {
|
|
58
|
+
if (code >= 500) {
|
|
59
|
+
return originalSendStatus(REWRITE_500_STATUS_CODE);
|
|
60
|
+
}
|
|
61
|
+
return originalSendStatus(code);
|
|
62
|
+
};
|
|
63
|
+
res.writeHead = (statusCode, ...args) => {
|
|
64
|
+
if (res.headersSent) {
|
|
65
|
+
return originalWriteHead(statusCode, ...args);
|
|
66
|
+
}
|
|
67
|
+
const newStatusCode = statusCode >= 500 ? REWRITE_500_STATUS_CODE : statusCode;
|
|
68
|
+
return originalWriteHead(newStatusCode, ...args);
|
|
69
|
+
};
|
|
70
|
+
let _statusCode = res.statusCode;
|
|
71
|
+
Object.defineProperty(res, "statusCode", {
|
|
72
|
+
configurable: true,
|
|
73
|
+
// Allow further redefinition if necessary
|
|
74
|
+
enumerable: true,
|
|
75
|
+
get() {
|
|
76
|
+
return _statusCode;
|
|
77
|
+
},
|
|
78
|
+
set(code) {
|
|
79
|
+
if (code >= 500) {
|
|
80
|
+
_statusCode = REWRITE_500_STATUS_CODE;
|
|
81
|
+
} else {
|
|
82
|
+
_statusCode = code;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
47
86
|
next();
|
|
48
87
|
},
|
|
49
88
|
companionApp
|
package/es/utils.js
CHANGED
|
@@ -86,10 +86,10 @@ export async function proxyImageDownload(req, res, next) {
|
|
|
86
86
|
}
|
|
87
87
|
} catch (err) {
|
|
88
88
|
logger.error("Proxy url failed: ", err);
|
|
89
|
-
res.status(
|
|
89
|
+
res.status(400).send("Proxy url failed");
|
|
90
90
|
}
|
|
91
91
|
} else {
|
|
92
|
-
res.status(
|
|
92
|
+
res.status(400).send('Parameter "url" is required');
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
export function setPDFDownloadHeader(req, res) {
|
|
@@ -10,6 +10,7 @@ var _expressSession = _interopRequireDefault(require("express-session"));
|
|
|
10
10
|
var _crypto = _interopRequireDefault(require("crypto"));
|
|
11
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
12
|
const secret = _crypto.default.randomBytes(32).toString("hex");
|
|
13
|
+
const REWRITE_500_STATUS_CODE = 400;
|
|
13
14
|
function initCompanion({
|
|
14
15
|
path,
|
|
15
16
|
express,
|
|
@@ -53,6 +54,44 @@ function initCompanion({
|
|
|
53
54
|
hackerCompanion.options.providerOptions = dynamicProviderOptions;
|
|
54
55
|
}
|
|
55
56
|
});
|
|
57
|
+
const originalStatus = res.status.bind(res);
|
|
58
|
+
const originalSendStatus = res.sendStatus.bind(res);
|
|
59
|
+
const originalWriteHead = res.writeHead.bind(res);
|
|
60
|
+
res.status = code => {
|
|
61
|
+
if (code >= 500) {
|
|
62
|
+
return originalStatus(REWRITE_500_STATUS_CODE);
|
|
63
|
+
}
|
|
64
|
+
return originalStatus(code);
|
|
65
|
+
};
|
|
66
|
+
res.sendStatus = code => {
|
|
67
|
+
if (code >= 500) {
|
|
68
|
+
return originalSendStatus(REWRITE_500_STATUS_CODE);
|
|
69
|
+
}
|
|
70
|
+
return originalSendStatus(code);
|
|
71
|
+
};
|
|
72
|
+
res.writeHead = (statusCode, ...args) => {
|
|
73
|
+
if (res.headersSent) {
|
|
74
|
+
return originalWriteHead(statusCode, ...args);
|
|
75
|
+
}
|
|
76
|
+
const newStatusCode = statusCode >= 500 ? REWRITE_500_STATUS_CODE : statusCode;
|
|
77
|
+
return originalWriteHead(newStatusCode, ...args);
|
|
78
|
+
};
|
|
79
|
+
let _statusCode = res.statusCode;
|
|
80
|
+
Object.defineProperty(res, "statusCode", {
|
|
81
|
+
configurable: true,
|
|
82
|
+
// Allow further redefinition if necessary
|
|
83
|
+
enumerable: true,
|
|
84
|
+
get() {
|
|
85
|
+
return _statusCode;
|
|
86
|
+
},
|
|
87
|
+
set(code) {
|
|
88
|
+
if (code >= 500) {
|
|
89
|
+
_statusCode = REWRITE_500_STATUS_CODE;
|
|
90
|
+
} else {
|
|
91
|
+
_statusCode = code;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
56
95
|
next();
|
|
57
96
|
}, companionApp);
|
|
58
97
|
newCompanion.handle = app;
|
package/lib/utils.js
CHANGED
|
@@ -109,10 +109,10 @@ async function proxyImageDownload(req, res, next) {
|
|
|
109
109
|
}
|
|
110
110
|
} catch (err) {
|
|
111
111
|
logger.error("Proxy url failed: ", err);
|
|
112
|
-
res.status(
|
|
112
|
+
res.status(400).send("Proxy url failed");
|
|
113
113
|
}
|
|
114
114
|
} else {
|
|
115
|
-
res.status(
|
|
115
|
+
res.status(400).send('Parameter "url" is required');
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
function setPDFDownloadHeader(req, res) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/uploader-server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.101",
|
|
4
4
|
"description": "blocklet upload server",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"axios": "^1.7.8"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@abtnode/cron": "^1.16.
|
|
53
|
-
"@blocklet/constant": "^1.16.
|
|
54
|
-
"@blocklet/logger": "^1.16.
|
|
55
|
-
"@blocklet/sdk": "^1.16.
|
|
52
|
+
"@abtnode/cron": "^1.16.44",
|
|
53
|
+
"@blocklet/constant": "^1.16.44",
|
|
54
|
+
"@blocklet/logger": "^1.16.44",
|
|
55
|
+
"@blocklet/sdk": "^1.16.44",
|
|
56
56
|
"@tus/file-store": "1.0.0",
|
|
57
57
|
"@tus/server": "1.0.0",
|
|
58
58
|
"@uppy/companion": "4.15.1",
|