@jwn-js/common 2.2.3 → 2.2.5

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.
Files changed (82) hide show
  1. package/ApiError.js +1 -37
  2. package/ApiError.mjs +1 -35
  3. package/Jwt-7tQL-rwa.js +1 -0
  4. package/Jwt-CDdbxwvH.js +1 -0
  5. package/Jwt.js +1 -8
  6. package/Jwt.mjs +1 -2
  7. package/Memcached.js +9 -166
  8. package/Memcached.mjs +9 -164
  9. package/Server.js +1 -316
  10. package/Server.mjs +1 -313
  11. package/cookieParse.js +1 -25
  12. package/cookieParse.mjs +1 -23
  13. package/cookieString.js +1 -22
  14. package/cookieString.mjs +1 -20
  15. package/docs/classes/ApiError.html +2 -2
  16. package/docs/classes/AsyncJwt.html +2 -2
  17. package/docs/classes/Controller.html +2 -2
  18. package/docs/classes/Jwt.html +2 -2
  19. package/docs/classes/Memcached.html +2 -2
  20. package/docs/classes/Model.html +2 -2
  21. package/docs/classes/Server.html +2 -2
  22. package/docs/classes/Ssr.html +2 -2
  23. package/docs/classes/Web.html +2 -2
  24. package/docs/functions/action.html +2 -2
  25. package/docs/functions/body.html +2 -2
  26. package/docs/functions/codeToStatus.html +2 -2
  27. package/docs/functions/config.html +2 -2
  28. package/docs/functions/connection.html +2 -2
  29. package/docs/functions/context.html +2 -2
  30. package/docs/functions/controller-1.html +2 -2
  31. package/docs/functions/cookies.html +2 -2
  32. package/docs/functions/db.html +2 -2
  33. package/docs/functions/headers.html +2 -2
  34. package/docs/functions/home.html +2 -2
  35. package/docs/functions/hostname.html +2 -2
  36. package/docs/functions/http.html +2 -2
  37. package/docs/functions/init.html +2 -2
  38. package/docs/functions/json.html +2 -2
  39. package/docs/functions/logerror.html +2 -2
  40. package/docs/functions/method.html +2 -2
  41. package/docs/functions/mixin.html +2 -2
  42. package/docs/functions/mount.html +2 -2
  43. package/docs/functions/pool.html +2 -2
  44. package/docs/functions/protocol.html +2 -2
  45. package/docs/functions/request.html +2 -2
  46. package/docs/functions/selectControllersSchema.html +1 -1
  47. package/docs/functions/stream.html +2 -2
  48. package/docs/functions/subaction.html +2 -2
  49. package/docs/functions/url.html +2 -2
  50. package/docs/functions/xml.html +2 -2
  51. package/docs/index.html +2 -2
  52. package/docs/interfaces/ApiErrorMessage.html +2 -2
  53. package/docs/interfaces/ContextSsr.html +2 -2
  54. package/docs/interfaces/ContextWeb.html +2 -2
  55. package/docs/interfaces/OptionsSsr.html +2 -2
  56. package/docs/interfaces/OptionsWeb.html +2 -2
  57. package/docs/interfaces/ResponseOptions.html +2 -2
  58. package/docs/interfaces/Route.html +2 -2
  59. package/docs/interfaces/Schema.html +2 -2
  60. package/docs/interfaces/ServerHandler.html +2 -2
  61. package/docs/interfaces/ServerOptions.html +2 -2
  62. package/docs/interfaces/ServerWebsocket.html +2 -2
  63. package/docs/modules.html +2 -2
  64. package/docs/types/ServerRoutes.html +1 -1
  65. package/docs/variables/helpers.html +2 -2
  66. package/index.js +4 -1473
  67. package/index.mjs +4 -1417
  68. package/jsonBody.js +1 -25
  69. package/jsonBody.mjs +1 -23
  70. package/multipartBody.js +1 -42
  71. package/multipartBody.mjs +1 -40
  72. package/package.json +2 -2
  73. package/readConfig.js +1 -11
  74. package/readConfig.mjs +1 -9
  75. package/readConfigSync.js +1 -11
  76. package/readConfigSync.mjs +1 -9
  77. package/staticBody.js +1 -205
  78. package/staticBody.mjs +1 -200
  79. package/urlencodedBody.js +1 -26
  80. package/urlencodedBody.mjs +1 -24
  81. package/Jwt-B4QZ2Ypb.js +0 -80
  82. package/Jwt-Be4GWrIO.js +0 -75
package/jsonBody.js CHANGED
@@ -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;
1
+ "use strict";var f=require("./ApiError.js");const a=e=>new Promise((o,t)=>{c(e,r=>o(r),()=>{t(new f.ApiError({message:"Can`t parse request",code:1,statusCode:404}))})});function c(e,o,t){let r=Buffer.from([]);e.onData((s,n)=>{if(r=Buffer.concat([r,Buffer.from(s)]),n)try{o(JSON.parse(r.toString()))}catch{o({})}}),e.onAborted(t)}exports.jsonBody=a;
package/jsonBody.mjs CHANGED
@@ -1,23 +1 @@
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 };
1
+ import{ApiError as s}from"./ApiError.mjs";const a=r=>new Promise((o,t)=>{c(r,e=>o(e),()=>{t(new s({message:"Can`t parse request",code:1,statusCode:404}))})});function c(r,o,t){let e=Buffer.from([]);r.onData((f,n)=>{if(e=Buffer.concat([e,Buffer.from(f)]),n)try{o(JSON.parse(e.toString()))}catch{o({})}}),r.onAborted(t)}export{a as jsonBody};
package/multipartBody.js CHANGED
@@ -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;
1
+ "use strict";var f=require("stream"),h=require("./ApiError.js"),w=require("formidable");const A=(m,u,c={multiples:!0})=>new Promise(async(y,o)=>{const i=new h.ApiError({message:"Can`t parse body",code:1,statusCode:404});m.onAborted(()=>i);try{const r=new f.PassThrough;r.headers={},u.forEach((e,a)=>r.headers[e]=a),m.onData((e,a)=>{r.write(Buffer.from(Buffer.from(e))),r.resume(),a&&r.end()});const l=w(c),n=e=>({size:e.size,path:e.filepath,name:e.originalFilename,type:e.mimetype,mtime:e.mtime,newFilename:e.newFilename});l.parse(r,(e,a,t)=>{e&&o(e);const p={};Object.keys(t).map(s=>{p[s]=Array.isArray(t[s])?t[s].map(d=>n(d)):n(t[s])}),a.files=p,y(a)})}catch{o(i)}});exports.multipartBody=A;
package/multipartBody.mjs CHANGED
@@ -1,40 +1 @@
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 };
1
+ import{PassThrough as h}from"stream";import{ApiError as u}from"./ApiError.mjs";import w from"formidable";const A=(a,f,c={multiples:!0})=>new Promise(async(y,s)=>{const n=new u({message:"Can`t parse body",code:1,statusCode:404});a.onAborted(()=>n);try{const r=new h;r.headers={},f.forEach((e,t)=>r.headers[e]=t),a.onData((e,t)=>{r.write(Buffer.from(Buffer.from(e))),r.resume(),t&&r.end()});const l=w(c),i=e=>({size:e.size,path:e.filepath,name:e.originalFilename,type:e.mimetype,mtime:e.mtime,newFilename:e.newFilename});l.parse(r,(e,t,o)=>{e&&s(e);const p={};Object.keys(o).map(m=>{p[m]=Array.isArray(o[m])?o[m].map(d=>i(d)):i(o[m])}),t.files=p,y(t)})}catch{s(n)}});export{A as multipartBody};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jwn-js/common",
3
3
  "private": false,
4
- "version": "2.2.3",
4
+ "version": "2.2.5",
5
5
  "description": "@jwn-js/common package",
6
6
  "main": "./index.js",
7
7
  "types": "./index.d.ts",
@@ -42,7 +42,7 @@
42
42
  "formidable": "2",
43
43
  "memjs": "^1.3.0",
44
44
  "reflect-metadata": "^0.1.13",
45
- "uWebSockets.js": "uNetworking/uWebSockets.js#v20.41.0",
45
+ "uWebSockets.js": "uNetworking/uWebSockets.js#v20.42.0",
46
46
  "vite-ssr-vue": "^1.0.6",
47
47
  "xml-js": "^1.6.11"
48
48
  }
package/readConfig.js CHANGED
@@ -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;
1
+ "use strict";var a=require("path"),s=require("fs");const i=async e=>{const r=a.resolve(e);return JSON.parse(await s.promises.readFile(r,"utf-8"))};exports.readConfig=i;
package/readConfig.mjs CHANGED
@@ -1,9 +1 @@
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 };
1
+ import o from"path";import{promises as t}from"fs";const a=async r=>{const e=o.resolve(r);return JSON.parse(await t.readFile(e,"utf-8"))};export{a as readConfig};
package/readConfigSync.js CHANGED
@@ -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;
1
+ "use strict";var n=require("path"),t=require("fs");const a=e=>{const r=n.resolve(e);return JSON.parse(t.readFileSync(r,"utf-8"))};exports.readConfigSync=a;
@@ -1,9 +1 @@
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 };
1
+ import o from"path";import t from"fs";const f=e=>{const r=o.resolve(e);return JSON.parse(t.readFileSync(r,"utf-8"))};export{f as readConfigSync};
package/staticBody.js CHANGED
@@ -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;
1
+ "use strict";var m=require("path"),l=require("fs"),n=require("./ApiError.js");const i={"3gp":"video/3gpp",a:"application/octet-stream",ai:"application/postscript",aif:"audio/x-aiff",aiff:"audio/x-aiff",asc:"application/pgp-signature",asf:"video/x-ms-asf",asm:"text/x-asm",asx:"video/x-ms-asf",atom:"application/atom+xml",au:"audio/basic",avi:"video/x-msvideo",bat:"application/x-msdownload",bin:"application/octet-stream",bmp:"image/bmp",bz2:"application/x-bzip2",c:"text/x-c",cab:"application/vnd.ms-cab-compressed",cc:"text/x-c",chm:"application/vnd.ms-htmlhelp",class:"application/octet-stream",com:"application/x-msdownload",conf:"text/plain",cpp:"text/x-c",crt:"application/x-x509-ca-cert",css:"text/css",csv:"text/csv",cxx:"text/x-c",deb:"application/x-debian-package",der:"application/x-x509-ca-cert",diff:"text/x-diff",djv:"image/vnd.djvu",djvu:"image/vnd.djvu",dll:"application/x-msdownload",dmg:"application/octet-stream",doc:"application/msword",dot:"application/msword",dtd:"application/xml-dtd",dvi:"application/x-dvi",ear:"application/java-archive",eml:"message/rfc822",eps:"application/postscript",exe:"application/x-msdownload",f:"text/x-fortran",f77:"text/x-fortran",f90:"text/x-fortran",flv:"video/x-flv",for:"text/x-fortran",gem:"application/octet-stream",gemspec:"text/x-script.ruby",gif:"image/gif",gz:"application/x-gzip",h:"text/x-c",hh:"text/x-c",htm:"text/html",html:"text/html",ico:"image/vnd.microsoft.icon",ics:"text/calendar",ifb:"text/calendar",iso:"application/octet-stream",jar:"application/java-archive",java:"text/x-java-source",jnlp:"application/x-java-jnlp-file",jpeg:"image/jpeg",jpg:"image/jpeg",js:"application/javascript",json:"application/json",log:"text/plain",m3u:"audio/x-mpegurl",m4v:"video/mp4",man:"text/troff",mathml:"application/mathml+xml",mbox:"application/mbox",mdoc:"text/troff",me:"text/troff",mid:"audio/midi",midi:"audio/midi",mime:"message/rfc822",mml:"application/mathml+xml",mng:"video/x-mng",mov:"video/quicktime",mp3:"audio/mpeg",mp4:"video/mp4",mp4v:"video/mp4",mpeg:"video/mpeg",mpg:"video/mpeg",ms:"text/troff",msi:"application/x-msdownload",odp:"application/vnd.oasis.opendocument.presentation",ods:"application/vnd.oasis.opendocument.spreadsheet",odt:"application/vnd.oasis.opendocument.text",ogg:"application/ogg",p:"text/x-pascal",pas:"text/x-pascal",pbm:"image/x-portable-bitmap",pdf:"application/pdf",pem:"application/x-x509-ca-cert",pgm:"image/x-portable-graymap",pgp:"application/pgp-encrypted",pkg:"application/octet-stream",pl:"text/x-script.perl",pm:"text/x-script.perl-module",png:"image/png",pnm:"image/x-portable-anymap",ppm:"image/x-portable-pixmap",pps:"application/vnd.ms-powerpoint",ppt:"application/vnd.ms-powerpoint",ps:"application/postscript",psd:"image/vnd.adobe.photoshop",py:"text/x-script.python",qt:"video/quicktime",ra:"audio/x-pn-realaudio",rake:"text/x-script.ruby",ram:"audio/x-pn-realaudio",rar:"application/x-rar-compressed",rb:"text/x-script.ruby",rdf:"application/rdf+xml",roff:"text/troff",rpm:"application/x-redhat-package-manager",rss:"application/rss+xml",rtf:"application/rtf",ru:"text/x-script.ruby",s:"text/x-asm",sgm:"text/sgml",sgml:"text/sgml",sh:"application/x-sh",sig:"application/pgp-signature",snd:"audio/basic",so:"application/octet-stream",svg:"image/svg+xml",svgz:"image/svg+xml",swf:"application/x-shockwave-flash",t:"text/troff",tar:"application/x-tar",tbz:"application/x-bzip-compressed-tar",tcl:"application/x-tcl",tex:"application/x-tex",texi:"application/x-texinfo",texinfo:"application/x-texinfo",text:"text/plain",tif:"image/tiff",tiff:"image/tiff",torrent:"application/x-bittorrent",tr:"text/troff",txt:"text/plain",vcf:"text/x-vcard",vcs:"text/x-vcalendar",vrml:"model/vrml",war:"application/java-archive",wav:"audio/x-wav",webp:"image/webp",wma:"audio/x-ms-wma",wmv:"video/x-ms-wmv",wmx:"video/x-ms-wmx",wrl:"model/vrml",wsdl:"application/wsdl+xml",xbm:"image/x-xbitmap",xhtml:"application/xhtml+xml",xls:"application/vnd.ms-excel",xml:"application/xml",xpm:"image/x-xpixmap",xsl:"application/xml",xslt:"application/xslt+xml",yaml:"text/yaml",yml:"text/yaml",zip:"application/zip",ttf:"application/x-font-ttf",woff:"application/x-font-woff",woff2:"application/x-font-woff2"},s=Object.keys(i),p=t=>t.split(".").pop(),r=t=>i[t.toLowerCase()]||"application/octet-stream";async function d(t,e,o){try{t.onAborted(()=>new n.ApiError({message:"Requers is aborted",code:1,statusCode:404}));let a=e.getUrl().replace(/\.\.\//ig,"").replace(/^\.\/?/,"");a=`./${a}`;const c=m.resolve(o,a),x=await l.promises.readFile(c);t.cork(()=>{t.writeStatus("200 OK").writeHeader("content-type",r(p(a))).end(x)})}catch(a){t.cork(()=>{t.writeStatus("404 Not Found").end(a.message)})}}exports.extensions=s,exports.exts=i,exports.getExt=p,exports.staticBody=d;
package/staticBody.mjs CHANGED
@@ -1,200 +1 @@
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 };
1
+ import x from"path";import{promises as l}from"fs";import{ApiError as n}from"./ApiError.mjs";const i={"3gp":"video/3gpp",a:"application/octet-stream",ai:"application/postscript",aif:"audio/x-aiff",aiff:"audio/x-aiff",asc:"application/pgp-signature",asf:"video/x-ms-asf",asm:"text/x-asm",asx:"video/x-ms-asf",atom:"application/atom+xml",au:"audio/basic",avi:"video/x-msvideo",bat:"application/x-msdownload",bin:"application/octet-stream",bmp:"image/bmp",bz2:"application/x-bzip2",c:"text/x-c",cab:"application/vnd.ms-cab-compressed",cc:"text/x-c",chm:"application/vnd.ms-htmlhelp",class:"application/octet-stream",com:"application/x-msdownload",conf:"text/plain",cpp:"text/x-c",crt:"application/x-x509-ca-cert",css:"text/css",csv:"text/csv",cxx:"text/x-c",deb:"application/x-debian-package",der:"application/x-x509-ca-cert",diff:"text/x-diff",djv:"image/vnd.djvu",djvu:"image/vnd.djvu",dll:"application/x-msdownload",dmg:"application/octet-stream",doc:"application/msword",dot:"application/msword",dtd:"application/xml-dtd",dvi:"application/x-dvi",ear:"application/java-archive",eml:"message/rfc822",eps:"application/postscript",exe:"application/x-msdownload",f:"text/x-fortran",f77:"text/x-fortran",f90:"text/x-fortran",flv:"video/x-flv",for:"text/x-fortran",gem:"application/octet-stream",gemspec:"text/x-script.ruby",gif:"image/gif",gz:"application/x-gzip",h:"text/x-c",hh:"text/x-c",htm:"text/html",html:"text/html",ico:"image/vnd.microsoft.icon",ics:"text/calendar",ifb:"text/calendar",iso:"application/octet-stream",jar:"application/java-archive",java:"text/x-java-source",jnlp:"application/x-java-jnlp-file",jpeg:"image/jpeg",jpg:"image/jpeg",js:"application/javascript",json:"application/json",log:"text/plain",m3u:"audio/x-mpegurl",m4v:"video/mp4",man:"text/troff",mathml:"application/mathml+xml",mbox:"application/mbox",mdoc:"text/troff",me:"text/troff",mid:"audio/midi",midi:"audio/midi",mime:"message/rfc822",mml:"application/mathml+xml",mng:"video/x-mng",mov:"video/quicktime",mp3:"audio/mpeg",mp4:"video/mp4",mp4v:"video/mp4",mpeg:"video/mpeg",mpg:"video/mpeg",ms:"text/troff",msi:"application/x-msdownload",odp:"application/vnd.oasis.opendocument.presentation",ods:"application/vnd.oasis.opendocument.spreadsheet",odt:"application/vnd.oasis.opendocument.text",ogg:"application/ogg",p:"text/x-pascal",pas:"text/x-pascal",pbm:"image/x-portable-bitmap",pdf:"application/pdf",pem:"application/x-x509-ca-cert",pgm:"image/x-portable-graymap",pgp:"application/pgp-encrypted",pkg:"application/octet-stream",pl:"text/x-script.perl",pm:"text/x-script.perl-module",png:"image/png",pnm:"image/x-portable-anymap",ppm:"image/x-portable-pixmap",pps:"application/vnd.ms-powerpoint",ppt:"application/vnd.ms-powerpoint",ps:"application/postscript",psd:"image/vnd.adobe.photoshop",py:"text/x-script.python",qt:"video/quicktime",ra:"audio/x-pn-realaudio",rake:"text/x-script.ruby",ram:"audio/x-pn-realaudio",rar:"application/x-rar-compressed",rb:"text/x-script.ruby",rdf:"application/rdf+xml",roff:"text/troff",rpm:"application/x-redhat-package-manager",rss:"application/rss+xml",rtf:"application/rtf",ru:"text/x-script.ruby",s:"text/x-asm",sgm:"text/sgml",sgml:"text/sgml",sh:"application/x-sh",sig:"application/pgp-signature",snd:"audio/basic",so:"application/octet-stream",svg:"image/svg+xml",svgz:"image/svg+xml",swf:"application/x-shockwave-flash",t:"text/troff",tar:"application/x-tar",tbz:"application/x-bzip-compressed-tar",tcl:"application/x-tcl",tex:"application/x-tex",texi:"application/x-texinfo",texinfo:"application/x-texinfo",text:"text/plain",tif:"image/tiff",tiff:"image/tiff",torrent:"application/x-bittorrent",tr:"text/troff",txt:"text/plain",vcf:"text/x-vcard",vcs:"text/x-vcalendar",vrml:"model/vrml",war:"application/java-archive",wav:"audio/x-wav",webp:"image/webp",wma:"audio/x-ms-wma",wmv:"video/x-ms-wmv",wmx:"video/x-ms-wmx",wrl:"model/vrml",wsdl:"application/wsdl+xml",xbm:"image/x-xbitmap",xhtml:"application/xhtml+xml",xls:"application/vnd.ms-excel",xml:"application/xml",xpm:"image/x-xpixmap",xsl:"application/xml",xslt:"application/xslt+xml",yaml:"text/yaml",yml:"text/yaml",zip:"application/zip",ttf:"application/x-font-ttf",woff:"application/x-font-woff",woff2:"application/x-font-woff2"},s=Object.keys(i),p=t=>t.split(".").pop(),r=t=>i[t.toLowerCase()]||"application/octet-stream";async function d(t,o,e){try{t.onAborted(()=>new n({message:"Requers is aborted",code:1,statusCode:404}));let a=o.getUrl().replace(/\.\.\//ig,"").replace(/^\.\/?/,"");a=`./${a}`;const m=x.resolve(e,a),c=await l.readFile(m);t.cork(()=>{t.writeStatus("200 OK").writeHeader("content-type",r(p(a))).end(c)})}catch(a){t.cork(()=>{t.writeStatus("404 Not Found").end(a.message)})}}export{s as extensions,i as exts,p as getExt,d as staticBody};