owebjs 1.2.0 → 1.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/dist/plugins/ChunkUpload.js +13 -13
- package/dist/plugins/index.d.ts +34 -0
- package/package.json +3 -2
|
@@ -3,24 +3,24 @@ import {
|
|
|
3
3
|
} from "../chunk-NH24FRB3.js";
|
|
4
4
|
import fs from "node:fs";
|
|
5
5
|
import nodePath from "node:path";
|
|
6
|
-
var
|
|
7
|
-
(function(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
})(
|
|
6
|
+
var ChunkUploadStatus;
|
|
7
|
+
(function(ChunkUploadStatus2) {
|
|
8
|
+
ChunkUploadStatus2["Success"] = "SUCCESS";
|
|
9
|
+
ChunkUploadStatus2["FileTooLarge"] = "FILE_TOO_LARGE";
|
|
10
|
+
ChunkUploadStatus2["ChunkTooLarge"] = "CHUNK_TOO_LARGE";
|
|
11
|
+
ChunkUploadStatus2["InvalidChunk"] = "INVALID_CHUNK";
|
|
12
|
+
})(ChunkUploadStatus || (ChunkUploadStatus = {}));
|
|
13
13
|
async function ChunkUpload(file, options) {
|
|
14
14
|
const { buffer, fileName, currentChunk, totalChunks } = file;
|
|
15
15
|
const { path, maxChunkSize, maxFileSize } = options;
|
|
16
16
|
if (typeof currentChunk !== "number" || typeof totalChunks !== "number" || currentChunk < 1 || totalChunks < 1 || currentChunk > totalChunks) {
|
|
17
17
|
return {
|
|
18
|
-
|
|
18
|
+
status: ChunkUploadStatus.InvalidChunk
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
if (buffer.length > maxChunkSize) {
|
|
22
22
|
return {
|
|
23
|
-
|
|
23
|
+
status: ChunkUploadStatus.ChunkTooLarge
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
const filePath = nodePath.join(path, fileName);
|
|
@@ -39,11 +39,11 @@ async function ChunkUpload(file, options) {
|
|
|
39
39
|
if (typeof maxFileSize === "number" && fileSize > maxFileSize) {
|
|
40
40
|
fs.unlinkSync(filePath);
|
|
41
41
|
return {
|
|
42
|
-
|
|
42
|
+
status: ChunkUploadStatus.FileTooLarge
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
return {
|
|
46
|
-
|
|
46
|
+
status: ChunkUploadStatus.Success,
|
|
47
47
|
uploadCompleted: true
|
|
48
48
|
};
|
|
49
49
|
} else if (currentChunk === 1) {
|
|
@@ -52,12 +52,12 @@ async function ChunkUpload(file, options) {
|
|
|
52
52
|
fs.appendFileSync(chunkPath, buffer);
|
|
53
53
|
}
|
|
54
54
|
return {
|
|
55
|
-
|
|
55
|
+
status: ChunkUploadStatus.Success,
|
|
56
56
|
currentChunk
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
__name(ChunkUpload, "ChunkUpload");
|
|
60
60
|
export {
|
|
61
61
|
ChunkUpload,
|
|
62
|
-
|
|
62
|
+
ChunkUploadStatus
|
|
63
63
|
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
interface FileData {
|
|
2
|
+
buffer: Buffer;
|
|
3
|
+
fileName: string;
|
|
4
|
+
currentChunk: number;
|
|
5
|
+
totalChunks: number;
|
|
6
|
+
}
|
|
7
|
+
interface ChunkUploadOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Path to save file
|
|
10
|
+
*/
|
|
11
|
+
path: string;
|
|
12
|
+
/**
|
|
13
|
+
* Max chunk size in bytes
|
|
14
|
+
*/
|
|
15
|
+
maxChunkSize: number;
|
|
16
|
+
/**
|
|
17
|
+
* Max file size in bytes
|
|
18
|
+
*/
|
|
19
|
+
maxFileSize?: number;
|
|
20
|
+
}
|
|
21
|
+
interface ChunkUploadResult {
|
|
22
|
+
status: ChunkUploadStatus;
|
|
23
|
+
uploadCompleted?: true;
|
|
24
|
+
currentChunk?: number;
|
|
25
|
+
}
|
|
26
|
+
declare enum ChunkUploadStatus {
|
|
27
|
+
Success = "SUCCESS",
|
|
28
|
+
FileTooLarge = "FILE_TOO_LARGE",
|
|
29
|
+
ChunkTooLarge = "CHUNK_TOO_LARGE",
|
|
30
|
+
InvalidChunk = "INVALID_CHUNK"
|
|
31
|
+
}
|
|
32
|
+
declare function ChunkUpload(file: FileData, options: ChunkUploadOptions): Promise<ChunkUploadResult>;
|
|
33
|
+
|
|
34
|
+
export { ChunkUpload, ChunkUploadOptions, ChunkUploadResult, ChunkUploadStatus, FileData };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "owebjs",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "Flexible handler that built on top of Fastify",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
},
|
|
13
13
|
"./plugins": {
|
|
14
14
|
"import": "./dist/plugins/index.js",
|
|
15
|
-
"default": "./dist/plugins/index.js"
|
|
15
|
+
"default": "./dist/plugins/index.js",
|
|
16
|
+
"types": "./dist/plugins/index.d.ts"
|
|
16
17
|
}
|
|
17
18
|
},
|
|
18
19
|
"scripts": {
|