@jwn-js/common 2.2.1 → 2.2.3
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/ApiError.js +37 -1
- package/ApiError.mjs +35 -1
- package/Jwt-B4QZ2Ypb.js +80 -0
- package/Jwt-Be4GWrIO.js +75 -0
- package/Jwt.js +8 -1
- package/Jwt.mjs +2 -1
- package/Memcached.js +166 -9
- package/Memcached.mjs +164 -9
- package/Server.js +316 -1
- package/Server.mjs +313 -1
- package/cookieParse.js +25 -1
- package/cookieParse.mjs +23 -1
- package/cookieString.js +22 -1
- package/cookieString.mjs +20 -1
- package/docs/classes/ApiError.html +2 -2
- package/docs/classes/AsyncJwt.html +2 -2
- package/docs/classes/Controller.html +2 -2
- package/docs/classes/Jwt.html +2 -2
- package/docs/classes/Memcached.html +2 -2
- package/docs/classes/Model.html +2 -2
- package/docs/classes/Server.html +2 -2
- package/docs/classes/Ssr.html +2 -2
- package/docs/classes/Web.html +2 -2
- package/docs/functions/action.html +2 -2
- package/docs/functions/body.html +2 -2
- package/docs/functions/codeToStatus.html +2 -2
- package/docs/functions/config.html +2 -2
- package/docs/functions/connection.html +2 -2
- package/docs/functions/context.html +2 -2
- package/docs/functions/controller-1.html +2 -2
- package/docs/functions/cookies.html +2 -2
- package/docs/functions/db.html +2 -2
- package/docs/functions/headers.html +2 -2
- package/docs/functions/home.html +2 -2
- package/docs/functions/hostname.html +2 -2
- package/docs/functions/http.html +2 -2
- package/docs/functions/init.html +2 -2
- package/docs/functions/json.html +2 -2
- package/docs/functions/logerror.html +2 -2
- package/docs/functions/method.html +2 -2
- package/docs/functions/mixin.html +2 -2
- package/docs/functions/mount.html +2 -2
- package/docs/functions/pool.html +2 -2
- package/docs/functions/protocol.html +2 -2
- package/docs/functions/request.html +2 -2
- package/docs/functions/selectControllersSchema.html +1 -1
- package/docs/functions/stream.html +2 -2
- package/docs/functions/subaction.html +2 -2
- package/docs/functions/url.html +2 -2
- package/docs/functions/xml.html +2 -2
- package/docs/index.html +2 -2
- package/docs/interfaces/ApiErrorMessage.html +2 -2
- package/docs/interfaces/ContextSsr.html +2 -2
- package/docs/interfaces/ContextWeb.html +2 -2
- package/docs/interfaces/OptionsSsr.html +2 -2
- package/docs/interfaces/OptionsWeb.html +2 -2
- package/docs/interfaces/ResponseOptions.html +2 -2
- package/docs/interfaces/Route.html +2 -2
- package/docs/interfaces/Schema.html +2 -2
- package/docs/interfaces/ServerHandler.html +2 -2
- package/docs/interfaces/ServerOptions.html +2 -2
- package/docs/interfaces/ServerWebsocket.html +2 -2
- package/docs/modules.html +2 -2
- package/docs/types/ServerRoutes.html +1 -1
- package/docs/variables/helpers.html +2 -2
- package/index.js +1473 -4
- package/index.mjs +1417 -4
- package/jsonBody.js +25 -1
- package/jsonBody.mjs +23 -1
- package/multipartBody.js +42 -1
- package/multipartBody.mjs +40 -1
- package/package.json +1 -1
- package/readConfig.js +11 -1
- package/readConfig.mjs +9 -1
- package/readConfigSync.js +11 -1
- package/readConfigSync.mjs +9 -1
- package/staticBody.js +205 -1
- package/staticBody.mjs +200 -1
- package/urlencodedBody.js +26 -1
- package/urlencodedBody.mjs +24 -1
- package/Jwt-7tQL-rwa.js +0 -1
- package/Jwt-CDdbxwvH.js +0 -1
package/jsonBody.js
CHANGED
|
@@ -1 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ApiError = require('./ApiError.js');
|
|
4
|
+
|
|
5
|
+
const jsonBody = (res) => new Promise((resolve, reject) => {
|
|
6
|
+
readJson(res, (obj) => resolve(obj), () => {
|
|
7
|
+
reject(new ApiError.ApiError({ message: "Can`t parse request", code: 1, statusCode: 404 }));
|
|
8
|
+
});
|
|
9
|
+
});
|
|
10
|
+
function readJson(res, cb, err) {
|
|
11
|
+
let buffer = Buffer.from([]);
|
|
12
|
+
res.onData((ab, isLast) => {
|
|
13
|
+
buffer = Buffer.concat([buffer, Buffer.from(ab)]);
|
|
14
|
+
if (isLast) {
|
|
15
|
+
try {
|
|
16
|
+
cb(JSON.parse(buffer.toString()));
|
|
17
|
+
} catch (e) {
|
|
18
|
+
cb({});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
res.onAborted(err);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
exports.jsonBody = jsonBody;
|
package/jsonBody.mjs
CHANGED
|
@@ -1 +1,23 @@
|
|
|
1
|
-
import{ApiError
|
|
1
|
+
import { ApiError } from './ApiError.mjs';
|
|
2
|
+
|
|
3
|
+
const jsonBody = (res) => new Promise((resolve, reject) => {
|
|
4
|
+
readJson(res, (obj) => resolve(obj), () => {
|
|
5
|
+
reject(new ApiError({ message: "Can`t parse request", code: 1, statusCode: 404 }));
|
|
6
|
+
});
|
|
7
|
+
});
|
|
8
|
+
function readJson(res, cb, err) {
|
|
9
|
+
let buffer = Buffer.from([]);
|
|
10
|
+
res.onData((ab, isLast) => {
|
|
11
|
+
buffer = Buffer.concat([buffer, Buffer.from(ab)]);
|
|
12
|
+
if (isLast) {
|
|
13
|
+
try {
|
|
14
|
+
cb(JSON.parse(buffer.toString()));
|
|
15
|
+
} catch (e) {
|
|
16
|
+
cb({});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
res.onAborted(err);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { jsonBody };
|
package/multipartBody.js
CHANGED
|
@@ -1 +1,42 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var stream = require('stream');
|
|
4
|
+
var ApiError = require('./ApiError.js');
|
|
5
|
+
var formidable = require('formidable');
|
|
6
|
+
|
|
7
|
+
const multipartBody = (res, req, options = { multiples: true }) => new Promise(async (resolve, reject) => {
|
|
8
|
+
const err = new ApiError.ApiError({ message: "Can`t parse body", code: 1, statusCode: 404 });
|
|
9
|
+
res.onAborted(() => err);
|
|
10
|
+
try {
|
|
11
|
+
const stream$1 = new stream.PassThrough();
|
|
12
|
+
stream$1.headers = {};
|
|
13
|
+
req.forEach((key, val) => stream$1.headers[key] = val);
|
|
14
|
+
res.onData((chunk, isLast) => {
|
|
15
|
+
stream$1.write(Buffer.from(Buffer.from(chunk)));
|
|
16
|
+
stream$1.resume();
|
|
17
|
+
isLast && stream$1.end();
|
|
18
|
+
});
|
|
19
|
+
const form = formidable(options);
|
|
20
|
+
const adapter = (row) => ({
|
|
21
|
+
size: row.size,
|
|
22
|
+
path: row.filepath,
|
|
23
|
+
name: row.originalFilename,
|
|
24
|
+
type: row.mimetype,
|
|
25
|
+
mtime: row.mtime,
|
|
26
|
+
newFilename: row.newFilename
|
|
27
|
+
});
|
|
28
|
+
form.parse(stream$1, (err2, fields, files) => {
|
|
29
|
+
err2 && reject(err2);
|
|
30
|
+
const output = {};
|
|
31
|
+
Object.keys(files).map((key) => {
|
|
32
|
+
output[key] = Array.isArray(files[key]) ? files[key].map((row) => adapter(row)) : adapter(files[key]);
|
|
33
|
+
});
|
|
34
|
+
fields.files = output;
|
|
35
|
+
resolve(fields);
|
|
36
|
+
});
|
|
37
|
+
} catch (e) {
|
|
38
|
+
reject(err);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
exports.multipartBody = multipartBody;
|
package/multipartBody.mjs
CHANGED
|
@@ -1 +1,40 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { PassThrough } from 'stream';
|
|
2
|
+
import { ApiError } from './ApiError.mjs';
|
|
3
|
+
import formidable from 'formidable';
|
|
4
|
+
|
|
5
|
+
const multipartBody = (res, req, options = { multiples: true }) => new Promise(async (resolve, reject) => {
|
|
6
|
+
const err = new ApiError({ message: "Can`t parse body", code: 1, statusCode: 404 });
|
|
7
|
+
res.onAborted(() => err);
|
|
8
|
+
try {
|
|
9
|
+
const stream = new PassThrough();
|
|
10
|
+
stream.headers = {};
|
|
11
|
+
req.forEach((key, val) => stream.headers[key] = val);
|
|
12
|
+
res.onData((chunk, isLast) => {
|
|
13
|
+
stream.write(Buffer.from(Buffer.from(chunk)));
|
|
14
|
+
stream.resume();
|
|
15
|
+
isLast && stream.end();
|
|
16
|
+
});
|
|
17
|
+
const form = formidable(options);
|
|
18
|
+
const adapter = (row) => ({
|
|
19
|
+
size: row.size,
|
|
20
|
+
path: row.filepath,
|
|
21
|
+
name: row.originalFilename,
|
|
22
|
+
type: row.mimetype,
|
|
23
|
+
mtime: row.mtime,
|
|
24
|
+
newFilename: row.newFilename
|
|
25
|
+
});
|
|
26
|
+
form.parse(stream, (err2, fields, files) => {
|
|
27
|
+
err2 && reject(err2);
|
|
28
|
+
const output = {};
|
|
29
|
+
Object.keys(files).map((key) => {
|
|
30
|
+
output[key] = Array.isArray(files[key]) ? files[key].map((row) => adapter(row)) : adapter(files[key]);
|
|
31
|
+
});
|
|
32
|
+
fields.files = output;
|
|
33
|
+
resolve(fields);
|
|
34
|
+
});
|
|
35
|
+
} catch (e) {
|
|
36
|
+
reject(err);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export { multipartBody };
|
package/package.json
CHANGED
package/readConfig.js
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path = require('path');
|
|
4
|
+
var fs = require('fs');
|
|
5
|
+
|
|
6
|
+
const readConfig = async (jsonfile) => {
|
|
7
|
+
const file = path.resolve(jsonfile);
|
|
8
|
+
return JSON.parse(await fs.promises.readFile(file, "utf-8"));
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
exports.readConfig = readConfig;
|
package/readConfig.mjs
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import path__default from 'path';
|
|
2
|
+
import { promises } from 'fs';
|
|
3
|
+
|
|
4
|
+
const readConfig = async (jsonfile) => {
|
|
5
|
+
const file = path__default.resolve(jsonfile);
|
|
6
|
+
return JSON.parse(await promises.readFile(file, "utf-8"));
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export { readConfig };
|
package/readConfigSync.js
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path = require('path');
|
|
4
|
+
var fs = require('fs');
|
|
5
|
+
|
|
6
|
+
const readConfigSync = (jsonfile) => {
|
|
7
|
+
const file = path.resolve(jsonfile);
|
|
8
|
+
return JSON.parse(fs.readFileSync(file, "utf-8"));
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
exports.readConfigSync = readConfigSync;
|
package/readConfigSync.mjs
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import path__default from 'path';
|
|
2
|
+
import fs__default from 'fs';
|
|
3
|
+
|
|
4
|
+
const readConfigSync = (jsonfile) => {
|
|
5
|
+
const file = path__default.resolve(jsonfile);
|
|
6
|
+
return JSON.parse(fs__default.readFileSync(file, "utf-8"));
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export { readConfigSync };
|
package/staticBody.js
CHANGED
|
@@ -1 +1,205 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path = require('path');
|
|
4
|
+
var fs = require('fs');
|
|
5
|
+
var ApiError = require('./ApiError.js');
|
|
6
|
+
|
|
7
|
+
const exts = {
|
|
8
|
+
"3gp": "video/3gpp",
|
|
9
|
+
"a": "application/octet-stream",
|
|
10
|
+
"ai": "application/postscript",
|
|
11
|
+
"aif": "audio/x-aiff",
|
|
12
|
+
"aiff": "audio/x-aiff",
|
|
13
|
+
"asc": "application/pgp-signature",
|
|
14
|
+
"asf": "video/x-ms-asf",
|
|
15
|
+
"asm": "text/x-asm",
|
|
16
|
+
"asx": "video/x-ms-asf",
|
|
17
|
+
"atom": "application/atom+xml",
|
|
18
|
+
"au": "audio/basic",
|
|
19
|
+
"avi": "video/x-msvideo",
|
|
20
|
+
"bat": "application/x-msdownload",
|
|
21
|
+
"bin": "application/octet-stream",
|
|
22
|
+
"bmp": "image/bmp",
|
|
23
|
+
"bz2": "application/x-bzip2",
|
|
24
|
+
"c": "text/x-c",
|
|
25
|
+
"cab": "application/vnd.ms-cab-compressed",
|
|
26
|
+
"cc": "text/x-c",
|
|
27
|
+
"chm": "application/vnd.ms-htmlhelp",
|
|
28
|
+
"class": "application/octet-stream",
|
|
29
|
+
"com": "application/x-msdownload",
|
|
30
|
+
"conf": "text/plain",
|
|
31
|
+
"cpp": "text/x-c",
|
|
32
|
+
"crt": "application/x-x509-ca-cert",
|
|
33
|
+
"css": "text/css",
|
|
34
|
+
"csv": "text/csv",
|
|
35
|
+
"cxx": "text/x-c",
|
|
36
|
+
"deb": "application/x-debian-package",
|
|
37
|
+
"der": "application/x-x509-ca-cert",
|
|
38
|
+
"diff": "text/x-diff",
|
|
39
|
+
"djv": "image/vnd.djvu",
|
|
40
|
+
"djvu": "image/vnd.djvu",
|
|
41
|
+
"dll": "application/x-msdownload",
|
|
42
|
+
"dmg": "application/octet-stream",
|
|
43
|
+
"doc": "application/msword",
|
|
44
|
+
"dot": "application/msword",
|
|
45
|
+
"dtd": "application/xml-dtd",
|
|
46
|
+
"dvi": "application/x-dvi",
|
|
47
|
+
"ear": "application/java-archive",
|
|
48
|
+
"eml": "message/rfc822",
|
|
49
|
+
"eps": "application/postscript",
|
|
50
|
+
"exe": "application/x-msdownload",
|
|
51
|
+
"f": "text/x-fortran",
|
|
52
|
+
"f77": "text/x-fortran",
|
|
53
|
+
"f90": "text/x-fortran",
|
|
54
|
+
"flv": "video/x-flv",
|
|
55
|
+
"for": "text/x-fortran",
|
|
56
|
+
"gem": "application/octet-stream",
|
|
57
|
+
"gemspec": "text/x-script.ruby",
|
|
58
|
+
"gif": "image/gif",
|
|
59
|
+
"gz": "application/x-gzip",
|
|
60
|
+
"h": "text/x-c",
|
|
61
|
+
"hh": "text/x-c",
|
|
62
|
+
"htm": "text/html",
|
|
63
|
+
"html": "text/html",
|
|
64
|
+
"ico": "image/vnd.microsoft.icon",
|
|
65
|
+
"ics": "text/calendar",
|
|
66
|
+
"ifb": "text/calendar",
|
|
67
|
+
"iso": "application/octet-stream",
|
|
68
|
+
"jar": "application/java-archive",
|
|
69
|
+
"java": "text/x-java-source",
|
|
70
|
+
"jnlp": "application/x-java-jnlp-file",
|
|
71
|
+
"jpeg": "image/jpeg",
|
|
72
|
+
"jpg": "image/jpeg",
|
|
73
|
+
"js": "application/javascript",
|
|
74
|
+
"json": "application/json",
|
|
75
|
+
"log": "text/plain",
|
|
76
|
+
"m3u": "audio/x-mpegurl",
|
|
77
|
+
"m4v": "video/mp4",
|
|
78
|
+
"man": "text/troff",
|
|
79
|
+
"mathml": "application/mathml+xml",
|
|
80
|
+
"mbox": "application/mbox",
|
|
81
|
+
"mdoc": "text/troff",
|
|
82
|
+
"me": "text/troff",
|
|
83
|
+
"mid": "audio/midi",
|
|
84
|
+
"midi": "audio/midi",
|
|
85
|
+
"mime": "message/rfc822",
|
|
86
|
+
"mml": "application/mathml+xml",
|
|
87
|
+
"mng": "video/x-mng",
|
|
88
|
+
"mov": "video/quicktime",
|
|
89
|
+
"mp3": "audio/mpeg",
|
|
90
|
+
"mp4": "video/mp4",
|
|
91
|
+
"mp4v": "video/mp4",
|
|
92
|
+
"mpeg": "video/mpeg",
|
|
93
|
+
"mpg": "video/mpeg",
|
|
94
|
+
"ms": "text/troff",
|
|
95
|
+
"msi": "application/x-msdownload",
|
|
96
|
+
"odp": "application/vnd.oasis.opendocument.presentation",
|
|
97
|
+
"ods": "application/vnd.oasis.opendocument.spreadsheet",
|
|
98
|
+
"odt": "application/vnd.oasis.opendocument.text",
|
|
99
|
+
"ogg": "application/ogg",
|
|
100
|
+
"p": "text/x-pascal",
|
|
101
|
+
"pas": "text/x-pascal",
|
|
102
|
+
"pbm": "image/x-portable-bitmap",
|
|
103
|
+
"pdf": "application/pdf",
|
|
104
|
+
"pem": "application/x-x509-ca-cert",
|
|
105
|
+
"pgm": "image/x-portable-graymap",
|
|
106
|
+
"pgp": "application/pgp-encrypted",
|
|
107
|
+
"pkg": "application/octet-stream",
|
|
108
|
+
"pl": "text/x-script.perl",
|
|
109
|
+
"pm": "text/x-script.perl-module",
|
|
110
|
+
"png": "image/png",
|
|
111
|
+
"pnm": "image/x-portable-anymap",
|
|
112
|
+
"ppm": "image/x-portable-pixmap",
|
|
113
|
+
"pps": "application/vnd.ms-powerpoint",
|
|
114
|
+
"ppt": "application/vnd.ms-powerpoint",
|
|
115
|
+
"ps": "application/postscript",
|
|
116
|
+
"psd": "image/vnd.adobe.photoshop",
|
|
117
|
+
"py": "text/x-script.python",
|
|
118
|
+
"qt": "video/quicktime",
|
|
119
|
+
"ra": "audio/x-pn-realaudio",
|
|
120
|
+
"rake": "text/x-script.ruby",
|
|
121
|
+
"ram": "audio/x-pn-realaudio",
|
|
122
|
+
"rar": "application/x-rar-compressed",
|
|
123
|
+
"rb": "text/x-script.ruby",
|
|
124
|
+
"rdf": "application/rdf+xml",
|
|
125
|
+
"roff": "text/troff",
|
|
126
|
+
"rpm": "application/x-redhat-package-manager",
|
|
127
|
+
"rss": "application/rss+xml",
|
|
128
|
+
"rtf": "application/rtf",
|
|
129
|
+
"ru": "text/x-script.ruby",
|
|
130
|
+
"s": "text/x-asm",
|
|
131
|
+
"sgm": "text/sgml",
|
|
132
|
+
"sgml": "text/sgml",
|
|
133
|
+
"sh": "application/x-sh",
|
|
134
|
+
"sig": "application/pgp-signature",
|
|
135
|
+
"snd": "audio/basic",
|
|
136
|
+
"so": "application/octet-stream",
|
|
137
|
+
"svg": "image/svg+xml",
|
|
138
|
+
"svgz": "image/svg+xml",
|
|
139
|
+
"swf": "application/x-shockwave-flash",
|
|
140
|
+
"t": "text/troff",
|
|
141
|
+
"tar": "application/x-tar",
|
|
142
|
+
"tbz": "application/x-bzip-compressed-tar",
|
|
143
|
+
"tcl": "application/x-tcl",
|
|
144
|
+
"tex": "application/x-tex",
|
|
145
|
+
"texi": "application/x-texinfo",
|
|
146
|
+
"texinfo": "application/x-texinfo",
|
|
147
|
+
"text": "text/plain",
|
|
148
|
+
"tif": "image/tiff",
|
|
149
|
+
"tiff": "image/tiff",
|
|
150
|
+
"torrent": "application/x-bittorrent",
|
|
151
|
+
"tr": "text/troff",
|
|
152
|
+
"txt": "text/plain",
|
|
153
|
+
"vcf": "text/x-vcard",
|
|
154
|
+
"vcs": "text/x-vcalendar",
|
|
155
|
+
"vrml": "model/vrml",
|
|
156
|
+
"war": "application/java-archive",
|
|
157
|
+
"wav": "audio/x-wav",
|
|
158
|
+
"webp": "image/webp",
|
|
159
|
+
"wma": "audio/x-ms-wma",
|
|
160
|
+
"wmv": "video/x-ms-wmv",
|
|
161
|
+
"wmx": "video/x-ms-wmx",
|
|
162
|
+
"wrl": "model/vrml",
|
|
163
|
+
"wsdl": "application/wsdl+xml",
|
|
164
|
+
"xbm": "image/x-xbitmap",
|
|
165
|
+
"xhtml": "application/xhtml+xml",
|
|
166
|
+
"xls": "application/vnd.ms-excel",
|
|
167
|
+
"xml": "application/xml",
|
|
168
|
+
"xpm": "image/x-xpixmap",
|
|
169
|
+
"xsl": "application/xml",
|
|
170
|
+
"xslt": "application/xslt+xml",
|
|
171
|
+
"yaml": "text/yaml",
|
|
172
|
+
"yml": "text/yaml",
|
|
173
|
+
"zip": "application/zip",
|
|
174
|
+
"ttf": "application/x-font-ttf",
|
|
175
|
+
"woff": "application/x-font-woff",
|
|
176
|
+
"woff2": "application/x-font-woff2"
|
|
177
|
+
};
|
|
178
|
+
const extensions = Object.keys(exts);
|
|
179
|
+
const getExt = (path2) => path2.split(".").pop();
|
|
180
|
+
const getContentType = (ext) => exts[ext.toLowerCase()] || "application/octet-stream";
|
|
181
|
+
async function staticBody(res, req, base) {
|
|
182
|
+
try {
|
|
183
|
+
res.onAborted(() => new ApiError.ApiError({
|
|
184
|
+
message: "Requers is aborted",
|
|
185
|
+
code: 1,
|
|
186
|
+
statusCode: 404
|
|
187
|
+
}));
|
|
188
|
+
let url = req.getUrl().replace(/\.\.\//ig, "").replace(/^\.\/?/, "");
|
|
189
|
+
url = `./${url}`;
|
|
190
|
+
const file = path.resolve(base, url);
|
|
191
|
+
const content = await fs.promises.readFile(file);
|
|
192
|
+
res.cork(() => {
|
|
193
|
+
res.writeStatus("200 OK").writeHeader("content-type", getContentType(getExt(url))).end(content);
|
|
194
|
+
});
|
|
195
|
+
} catch (e) {
|
|
196
|
+
res.cork(() => {
|
|
197
|
+
res.writeStatus("404 Not Found").end(e.message);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
exports.extensions = extensions;
|
|
203
|
+
exports.exts = exts;
|
|
204
|
+
exports.getExt = getExt;
|
|
205
|
+
exports.staticBody = staticBody;
|
package/staticBody.mjs
CHANGED
|
@@ -1 +1,200 @@
|
|
|
1
|
-
import
|
|
1
|
+
import path__default from 'path';
|
|
2
|
+
import { promises } from 'fs';
|
|
3
|
+
import { ApiError } from './ApiError.mjs';
|
|
4
|
+
|
|
5
|
+
const exts = {
|
|
6
|
+
"3gp": "video/3gpp",
|
|
7
|
+
"a": "application/octet-stream",
|
|
8
|
+
"ai": "application/postscript",
|
|
9
|
+
"aif": "audio/x-aiff",
|
|
10
|
+
"aiff": "audio/x-aiff",
|
|
11
|
+
"asc": "application/pgp-signature",
|
|
12
|
+
"asf": "video/x-ms-asf",
|
|
13
|
+
"asm": "text/x-asm",
|
|
14
|
+
"asx": "video/x-ms-asf",
|
|
15
|
+
"atom": "application/atom+xml",
|
|
16
|
+
"au": "audio/basic",
|
|
17
|
+
"avi": "video/x-msvideo",
|
|
18
|
+
"bat": "application/x-msdownload",
|
|
19
|
+
"bin": "application/octet-stream",
|
|
20
|
+
"bmp": "image/bmp",
|
|
21
|
+
"bz2": "application/x-bzip2",
|
|
22
|
+
"c": "text/x-c",
|
|
23
|
+
"cab": "application/vnd.ms-cab-compressed",
|
|
24
|
+
"cc": "text/x-c",
|
|
25
|
+
"chm": "application/vnd.ms-htmlhelp",
|
|
26
|
+
"class": "application/octet-stream",
|
|
27
|
+
"com": "application/x-msdownload",
|
|
28
|
+
"conf": "text/plain",
|
|
29
|
+
"cpp": "text/x-c",
|
|
30
|
+
"crt": "application/x-x509-ca-cert",
|
|
31
|
+
"css": "text/css",
|
|
32
|
+
"csv": "text/csv",
|
|
33
|
+
"cxx": "text/x-c",
|
|
34
|
+
"deb": "application/x-debian-package",
|
|
35
|
+
"der": "application/x-x509-ca-cert",
|
|
36
|
+
"diff": "text/x-diff",
|
|
37
|
+
"djv": "image/vnd.djvu",
|
|
38
|
+
"djvu": "image/vnd.djvu",
|
|
39
|
+
"dll": "application/x-msdownload",
|
|
40
|
+
"dmg": "application/octet-stream",
|
|
41
|
+
"doc": "application/msword",
|
|
42
|
+
"dot": "application/msword",
|
|
43
|
+
"dtd": "application/xml-dtd",
|
|
44
|
+
"dvi": "application/x-dvi",
|
|
45
|
+
"ear": "application/java-archive",
|
|
46
|
+
"eml": "message/rfc822",
|
|
47
|
+
"eps": "application/postscript",
|
|
48
|
+
"exe": "application/x-msdownload",
|
|
49
|
+
"f": "text/x-fortran",
|
|
50
|
+
"f77": "text/x-fortran",
|
|
51
|
+
"f90": "text/x-fortran",
|
|
52
|
+
"flv": "video/x-flv",
|
|
53
|
+
"for": "text/x-fortran",
|
|
54
|
+
"gem": "application/octet-stream",
|
|
55
|
+
"gemspec": "text/x-script.ruby",
|
|
56
|
+
"gif": "image/gif",
|
|
57
|
+
"gz": "application/x-gzip",
|
|
58
|
+
"h": "text/x-c",
|
|
59
|
+
"hh": "text/x-c",
|
|
60
|
+
"htm": "text/html",
|
|
61
|
+
"html": "text/html",
|
|
62
|
+
"ico": "image/vnd.microsoft.icon",
|
|
63
|
+
"ics": "text/calendar",
|
|
64
|
+
"ifb": "text/calendar",
|
|
65
|
+
"iso": "application/octet-stream",
|
|
66
|
+
"jar": "application/java-archive",
|
|
67
|
+
"java": "text/x-java-source",
|
|
68
|
+
"jnlp": "application/x-java-jnlp-file",
|
|
69
|
+
"jpeg": "image/jpeg",
|
|
70
|
+
"jpg": "image/jpeg",
|
|
71
|
+
"js": "application/javascript",
|
|
72
|
+
"json": "application/json",
|
|
73
|
+
"log": "text/plain",
|
|
74
|
+
"m3u": "audio/x-mpegurl",
|
|
75
|
+
"m4v": "video/mp4",
|
|
76
|
+
"man": "text/troff",
|
|
77
|
+
"mathml": "application/mathml+xml",
|
|
78
|
+
"mbox": "application/mbox",
|
|
79
|
+
"mdoc": "text/troff",
|
|
80
|
+
"me": "text/troff",
|
|
81
|
+
"mid": "audio/midi",
|
|
82
|
+
"midi": "audio/midi",
|
|
83
|
+
"mime": "message/rfc822",
|
|
84
|
+
"mml": "application/mathml+xml",
|
|
85
|
+
"mng": "video/x-mng",
|
|
86
|
+
"mov": "video/quicktime",
|
|
87
|
+
"mp3": "audio/mpeg",
|
|
88
|
+
"mp4": "video/mp4",
|
|
89
|
+
"mp4v": "video/mp4",
|
|
90
|
+
"mpeg": "video/mpeg",
|
|
91
|
+
"mpg": "video/mpeg",
|
|
92
|
+
"ms": "text/troff",
|
|
93
|
+
"msi": "application/x-msdownload",
|
|
94
|
+
"odp": "application/vnd.oasis.opendocument.presentation",
|
|
95
|
+
"ods": "application/vnd.oasis.opendocument.spreadsheet",
|
|
96
|
+
"odt": "application/vnd.oasis.opendocument.text",
|
|
97
|
+
"ogg": "application/ogg",
|
|
98
|
+
"p": "text/x-pascal",
|
|
99
|
+
"pas": "text/x-pascal",
|
|
100
|
+
"pbm": "image/x-portable-bitmap",
|
|
101
|
+
"pdf": "application/pdf",
|
|
102
|
+
"pem": "application/x-x509-ca-cert",
|
|
103
|
+
"pgm": "image/x-portable-graymap",
|
|
104
|
+
"pgp": "application/pgp-encrypted",
|
|
105
|
+
"pkg": "application/octet-stream",
|
|
106
|
+
"pl": "text/x-script.perl",
|
|
107
|
+
"pm": "text/x-script.perl-module",
|
|
108
|
+
"png": "image/png",
|
|
109
|
+
"pnm": "image/x-portable-anymap",
|
|
110
|
+
"ppm": "image/x-portable-pixmap",
|
|
111
|
+
"pps": "application/vnd.ms-powerpoint",
|
|
112
|
+
"ppt": "application/vnd.ms-powerpoint",
|
|
113
|
+
"ps": "application/postscript",
|
|
114
|
+
"psd": "image/vnd.adobe.photoshop",
|
|
115
|
+
"py": "text/x-script.python",
|
|
116
|
+
"qt": "video/quicktime",
|
|
117
|
+
"ra": "audio/x-pn-realaudio",
|
|
118
|
+
"rake": "text/x-script.ruby",
|
|
119
|
+
"ram": "audio/x-pn-realaudio",
|
|
120
|
+
"rar": "application/x-rar-compressed",
|
|
121
|
+
"rb": "text/x-script.ruby",
|
|
122
|
+
"rdf": "application/rdf+xml",
|
|
123
|
+
"roff": "text/troff",
|
|
124
|
+
"rpm": "application/x-redhat-package-manager",
|
|
125
|
+
"rss": "application/rss+xml",
|
|
126
|
+
"rtf": "application/rtf",
|
|
127
|
+
"ru": "text/x-script.ruby",
|
|
128
|
+
"s": "text/x-asm",
|
|
129
|
+
"sgm": "text/sgml",
|
|
130
|
+
"sgml": "text/sgml",
|
|
131
|
+
"sh": "application/x-sh",
|
|
132
|
+
"sig": "application/pgp-signature",
|
|
133
|
+
"snd": "audio/basic",
|
|
134
|
+
"so": "application/octet-stream",
|
|
135
|
+
"svg": "image/svg+xml",
|
|
136
|
+
"svgz": "image/svg+xml",
|
|
137
|
+
"swf": "application/x-shockwave-flash",
|
|
138
|
+
"t": "text/troff",
|
|
139
|
+
"tar": "application/x-tar",
|
|
140
|
+
"tbz": "application/x-bzip-compressed-tar",
|
|
141
|
+
"tcl": "application/x-tcl",
|
|
142
|
+
"tex": "application/x-tex",
|
|
143
|
+
"texi": "application/x-texinfo",
|
|
144
|
+
"texinfo": "application/x-texinfo",
|
|
145
|
+
"text": "text/plain",
|
|
146
|
+
"tif": "image/tiff",
|
|
147
|
+
"tiff": "image/tiff",
|
|
148
|
+
"torrent": "application/x-bittorrent",
|
|
149
|
+
"tr": "text/troff",
|
|
150
|
+
"txt": "text/plain",
|
|
151
|
+
"vcf": "text/x-vcard",
|
|
152
|
+
"vcs": "text/x-vcalendar",
|
|
153
|
+
"vrml": "model/vrml",
|
|
154
|
+
"war": "application/java-archive",
|
|
155
|
+
"wav": "audio/x-wav",
|
|
156
|
+
"webp": "image/webp",
|
|
157
|
+
"wma": "audio/x-ms-wma",
|
|
158
|
+
"wmv": "video/x-ms-wmv",
|
|
159
|
+
"wmx": "video/x-ms-wmx",
|
|
160
|
+
"wrl": "model/vrml",
|
|
161
|
+
"wsdl": "application/wsdl+xml",
|
|
162
|
+
"xbm": "image/x-xbitmap",
|
|
163
|
+
"xhtml": "application/xhtml+xml",
|
|
164
|
+
"xls": "application/vnd.ms-excel",
|
|
165
|
+
"xml": "application/xml",
|
|
166
|
+
"xpm": "image/x-xpixmap",
|
|
167
|
+
"xsl": "application/xml",
|
|
168
|
+
"xslt": "application/xslt+xml",
|
|
169
|
+
"yaml": "text/yaml",
|
|
170
|
+
"yml": "text/yaml",
|
|
171
|
+
"zip": "application/zip",
|
|
172
|
+
"ttf": "application/x-font-ttf",
|
|
173
|
+
"woff": "application/x-font-woff",
|
|
174
|
+
"woff2": "application/x-font-woff2"
|
|
175
|
+
};
|
|
176
|
+
const extensions = Object.keys(exts);
|
|
177
|
+
const getExt = (path2) => path2.split(".").pop();
|
|
178
|
+
const getContentType = (ext) => exts[ext.toLowerCase()] || "application/octet-stream";
|
|
179
|
+
async function staticBody(res, req, base) {
|
|
180
|
+
try {
|
|
181
|
+
res.onAborted(() => new ApiError({
|
|
182
|
+
message: "Requers is aborted",
|
|
183
|
+
code: 1,
|
|
184
|
+
statusCode: 404
|
|
185
|
+
}));
|
|
186
|
+
let url = req.getUrl().replace(/\.\.\//ig, "").replace(/^\.\/?/, "");
|
|
187
|
+
url = `./${url}`;
|
|
188
|
+
const file = path__default.resolve(base, url);
|
|
189
|
+
const content = await promises.readFile(file);
|
|
190
|
+
res.cork(() => {
|
|
191
|
+
res.writeStatus("200 OK").writeHeader("content-type", getContentType(getExt(url))).end(content);
|
|
192
|
+
});
|
|
193
|
+
} catch (e) {
|
|
194
|
+
res.cork(() => {
|
|
195
|
+
res.writeStatus("404 Not Found").end(e.message);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export { extensions, exts, getExt, staticBody };
|