owebjs 1.1.6 → 1.2.0
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/dist/index.d.ts +1 -5
- package/dist/plugins/ChunkUpload.js +63 -0
- package/dist/plugins/index.js +1 -0
- package/dist/structures/Oweb.js +3 -9
- package/package.json +47 -37
- package/dist/helpers/JwtAuth.js +0 -34
- package/dist/helpers/PluginRegistrar.js +0 -15
package/dist/index.d.ts
CHANGED
|
@@ -47,11 +47,7 @@ declare class Oweb extends _FastifyInstance {
|
|
|
47
47
|
* Sets the internal error handler
|
|
48
48
|
*/
|
|
49
49
|
setInternalErrorHandler(errorHandlerCallback: (request: FastifyRequest, reply: FastifyReply, error: Error) => void): void;
|
|
50
|
-
|
|
51
|
-
*
|
|
52
|
-
* Starts the server
|
|
53
|
-
*/
|
|
54
|
-
start(options?: FastifyListenOptions): Promise<{
|
|
50
|
+
start({ port, host }: FastifyListenOptions): Promise<{
|
|
55
51
|
err: Error;
|
|
56
52
|
address: string;
|
|
57
53
|
}>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "../chunk-NH24FRB3.js";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import nodePath from "node:path";
|
|
6
|
+
var ChunkUploadStatusCode;
|
|
7
|
+
(function(ChunkUploadStatusCode2) {
|
|
8
|
+
ChunkUploadStatusCode2[ChunkUploadStatusCode2["Success"] = 200] = "Success";
|
|
9
|
+
ChunkUploadStatusCode2[ChunkUploadStatusCode2["FileTooLarge"] = 413] = "FileTooLarge";
|
|
10
|
+
ChunkUploadStatusCode2[ChunkUploadStatusCode2["ChunkTooLarge"] = 413] = "ChunkTooLarge";
|
|
11
|
+
ChunkUploadStatusCode2[ChunkUploadStatusCode2["InvalidChunk"] = 400] = "InvalidChunk";
|
|
12
|
+
})(ChunkUploadStatusCode || (ChunkUploadStatusCode = {}));
|
|
13
|
+
async function ChunkUpload(file, options) {
|
|
14
|
+
const { buffer, fileName, currentChunk, totalChunks } = file;
|
|
15
|
+
const { path, maxChunkSize, maxFileSize } = options;
|
|
16
|
+
if (typeof currentChunk !== "number" || typeof totalChunks !== "number" || currentChunk < 1 || totalChunks < 1 || currentChunk > totalChunks) {
|
|
17
|
+
return {
|
|
18
|
+
statusCode: ChunkUploadStatusCode.InvalidChunk
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
if (buffer.length > maxChunkSize) {
|
|
22
|
+
return {
|
|
23
|
+
statusCode: ChunkUploadStatusCode.ChunkTooLarge
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const filePath = nodePath.join(path, fileName);
|
|
27
|
+
const chunkPath = nodePath.join(path, `${fileName}.tmp`);
|
|
28
|
+
fs.mkdirSync(path, {
|
|
29
|
+
recursive: true
|
|
30
|
+
});
|
|
31
|
+
if (currentChunk === totalChunks) {
|
|
32
|
+
if (fs.existsSync(chunkPath)) {
|
|
33
|
+
fs.appendFileSync(chunkPath, buffer);
|
|
34
|
+
fs.renameSync(chunkPath, filePath);
|
|
35
|
+
} else {
|
|
36
|
+
fs.writeFileSync(filePath, buffer);
|
|
37
|
+
}
|
|
38
|
+
const fileSize = fs.statSync(filePath).size;
|
|
39
|
+
if (typeof maxFileSize === "number" && fileSize > maxFileSize) {
|
|
40
|
+
fs.unlinkSync(filePath);
|
|
41
|
+
return {
|
|
42
|
+
statusCode: ChunkUploadStatusCode.FileTooLarge
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
statusCode: ChunkUploadStatusCode.Success,
|
|
47
|
+
uploadCompleted: true
|
|
48
|
+
};
|
|
49
|
+
} else if (currentChunk === 1) {
|
|
50
|
+
fs.writeFileSync(chunkPath, buffer);
|
|
51
|
+
} else {
|
|
52
|
+
fs.appendFileSync(chunkPath, buffer);
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
statusCode: ChunkUploadStatusCode.Success,
|
|
56
|
+
currentChunk
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
__name(ChunkUpload, "ChunkUpload");
|
|
60
|
+
export {
|
|
61
|
+
ChunkUpload,
|
|
62
|
+
ChunkUploadStatusCode
|
|
63
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ChunkUpload.js';
|
package/dist/structures/Oweb.js
CHANGED
|
@@ -68,17 +68,11 @@ class Oweb extends _FastifyInstance {
|
|
|
68
68
|
setInternalErrorHandler(errorHandlerCallback) {
|
|
69
69
|
this._options.OWEB_INTERNAL_ERROR_HANDLER = errorHandlerCallback;
|
|
70
70
|
}
|
|
71
|
-
|
|
72
|
-
*
|
|
73
|
-
* Starts the server
|
|
74
|
-
*/
|
|
75
|
-
start(options = {
|
|
76
|
-
port: 3e3,
|
|
77
|
-
host: "127.0.0.1"
|
|
78
|
-
}) {
|
|
71
|
+
start({ port = 3e3, host = "127.0.0.1" }) {
|
|
79
72
|
return new Promise((resolve) => {
|
|
80
73
|
this.listen({
|
|
81
|
-
port
|
|
74
|
+
port,
|
|
75
|
+
host
|
|
82
76
|
}, (err, address) => resolve({
|
|
83
77
|
err,
|
|
84
78
|
address
|
package/package.json
CHANGED
|
@@ -1,37 +1,47 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "owebjs",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Flexible handler that built on top of Fastify",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
},
|
|
36
|
-
"
|
|
37
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "owebjs",
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "Flexible handler that built on top of Fastify",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"default": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
},
|
|
13
|
+
"./plugins": {
|
|
14
|
+
"import": "./dist/plugins/index.js",
|
|
15
|
+
"default": "./dist/plugins/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"start": "node .",
|
|
20
|
+
"build": "tsup",
|
|
21
|
+
"dev": "tsup && node .",
|
|
22
|
+
"test": "tsup && node scripts/copyBinaries && node test/index.js",
|
|
23
|
+
"format": "prettier --write . --ignore-path .gitignore"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/owebjs/oweb",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/owebjs/oweb"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [],
|
|
31
|
+
"author": "owebjs",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"fastify": "^4.23.2"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@fastify/multipart": "^8.1.0",
|
|
38
|
+
"@swc/core": "^1.3.85",
|
|
39
|
+
"@types/node": "^20.6.2",
|
|
40
|
+
"prettier": "^3.0.3",
|
|
41
|
+
"tslib": "^2.6.2",
|
|
42
|
+
"tsup": "^7.2.0",
|
|
43
|
+
"typescript": "^5.2.2",
|
|
44
|
+
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.10.0"
|
|
45
|
+
},
|
|
46
|
+
"type": "module"
|
|
47
|
+
}
|
package/dist/helpers/JwtAuth.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__name
|
|
3
|
-
} from "../chunk-NH24FRB3.js";
|
|
4
|
-
import jwt from "jsonwebtoken";
|
|
5
|
-
const JwtAuth = /* @__PURE__ */ __name(({ secret, onError }) => {
|
|
6
|
-
return function(Base) {
|
|
7
|
-
return class JWT extends Base {
|
|
8
|
-
static {
|
|
9
|
-
__name(this, "JWT");
|
|
10
|
-
}
|
|
11
|
-
constructor(req, res) {
|
|
12
|
-
super();
|
|
13
|
-
let token = req?.headers?.authorization;
|
|
14
|
-
if (token) {
|
|
15
|
-
token = token.trim();
|
|
16
|
-
token = token.slice(Math.max(token.lastIndexOf(" "), 0));
|
|
17
|
-
}
|
|
18
|
-
if (secret) {
|
|
19
|
-
try {
|
|
20
|
-
this.jwtResult = jwt.verify(token, secret);
|
|
21
|
-
} catch {
|
|
22
|
-
if (onError)
|
|
23
|
-
onError(req, res);
|
|
24
|
-
}
|
|
25
|
-
} else {
|
|
26
|
-
throw new Error("JWT Secret not provided!");
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
}, "JwtAuth");
|
|
32
|
-
export {
|
|
33
|
-
JwtAuth
|
|
34
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__name
|
|
3
|
-
} from "../chunk-NH24FRB3.js";
|
|
4
|
-
const creator = /* @__PURE__ */ __name((allPlugins, plugin) => plugin(allPlugins), "creator");
|
|
5
|
-
let BaseRequest = class BaseRequest2 {
|
|
6
|
-
static {
|
|
7
|
-
__name(this, "BaseRequest");
|
|
8
|
-
}
|
|
9
|
-
constructor() {
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
const register = /* @__PURE__ */ __name((...plugins) => plugins.reduce(creator, BaseRequest), "register");
|
|
13
|
-
export {
|
|
14
|
-
register
|
|
15
|
-
};
|