owebjs 1.2.1 → 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 +7 -7
- package/package.json +1 -1
|
@@ -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
|
};
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -19,16 +19,16 @@ interface ChunkUploadOptions {
|
|
|
19
19
|
maxFileSize?: number;
|
|
20
20
|
}
|
|
21
21
|
interface ChunkUploadResult {
|
|
22
|
-
|
|
22
|
+
status: ChunkUploadStatus;
|
|
23
23
|
uploadCompleted?: true;
|
|
24
24
|
currentChunk?: number;
|
|
25
25
|
}
|
|
26
|
-
declare enum
|
|
27
|
-
Success =
|
|
28
|
-
FileTooLarge =
|
|
29
|
-
ChunkTooLarge =
|
|
30
|
-
InvalidChunk =
|
|
26
|
+
declare enum ChunkUploadStatus {
|
|
27
|
+
Success = "SUCCESS",
|
|
28
|
+
FileTooLarge = "FILE_TOO_LARGE",
|
|
29
|
+
ChunkTooLarge = "CHUNK_TOO_LARGE",
|
|
30
|
+
InvalidChunk = "INVALID_CHUNK"
|
|
31
31
|
}
|
|
32
32
|
declare function ChunkUpload(file: FileData, options: ChunkUploadOptions): Promise<ChunkUploadResult>;
|
|
33
33
|
|
|
34
|
-
export { ChunkUpload, ChunkUploadOptions, ChunkUploadResult,
|
|
34
|
+
export { ChunkUpload, ChunkUploadOptions, ChunkUploadResult, ChunkUploadStatus, FileData };
|