securequ 1.1.19 → 1.1.21
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/client/Base.cjs +146 -146
- package/client/Base.cjs.map +1 -1
- package/client/Base.d.ts +18 -18
- package/client/Base.js +146 -146
- package/client/Base.js.map +1 -1
- package/client/index.cjs +155 -138
- package/client/index.cjs.map +1 -1
- package/client/index.d.ts +10 -10
- package/client/index.js +156 -139
- package/client/index.js.map +1 -1
- package/client/types.d.ts +39 -35
- package/include/compress.cjs +31 -31
- package/include/compress.cjs.map +1 -1
- package/include/compress.d.ts +9 -9
- package/include/compress.js +33 -33
- package/include/compress.js.map +1 -1
- package/include/crypto.cjs +132 -132
- package/include/crypto.cjs.map +1 -1
- package/include/crypto.d.ts +21 -21
- package/include/crypto.js +132 -132
- package/include/crypto.js.map +1 -1
- package/include/file-scaner.cjs +77 -95
- package/include/file-scaner.cjs.map +1 -1
- package/include/file-scaner.d.ts +11 -11
- package/include/file-scaner.js +74 -95
- package/include/file-scaner.js.map +1 -1
- package/include/file.cjs +78 -60
- package/include/file.cjs.map +1 -1
- package/include/file.js +78 -61
- package/include/file.js.map +1 -1
- package/index.cjs +1 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/readme.md +312 -312
- package/server/Base.cjs +105 -105
- package/server/Base.cjs.map +1 -1
- package/server/Base.d.ts +20 -20
- package/server/Base.js +105 -105
- package/server/Base.js.map +1 -1
- package/server/Router.cjs +29 -29
- package/server/Router.cjs.map +1 -1
- package/server/Router.d.ts +7 -7
- package/server/Router.js +29 -29
- package/server/Router.js.map +1 -1
- package/server/index.cjs +185 -187
- package/server/index.cjs.map +1 -1
- package/server/index.d.ts +5 -5
- package/server/index.js +186 -188
- package/server/index.js.map +1 -1
- package/server/types.d.ts +72 -72
package/include/file.cjs
CHANGED
|
@@ -1,70 +1,88 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var tslib = require('tslib');
|
|
4
|
-
var crypto = require('./crypto.cjs');
|
|
5
4
|
|
|
6
|
-
function getChunkSize(fileSize) {
|
|
7
|
-
// fileSize in bytes
|
|
8
|
-
const MB = 1024 * 1024;
|
|
9
|
-
if (fileSize <= 1 * MB) {
|
|
10
|
-
// Very small files (<1MB): single small chunk
|
|
11
|
-
return 64 * 1024; // 64 KB
|
|
12
|
-
}
|
|
13
|
-
else if (fileSize <= 10 * MB) {
|
|
14
|
-
// Small files (1–10MB): medium chunks
|
|
15
|
-
return 256 * 1024; // 256 KB
|
|
16
|
-
}
|
|
17
|
-
else if (fileSize <= 100 * MB) {
|
|
18
|
-
// Medium files (10–100MB): faster upload, moderate size
|
|
19
|
-
return 512 * 1024; // 512 KB
|
|
20
|
-
}
|
|
21
|
-
else if (fileSize <= 500 * MB) {
|
|
22
|
-
// Large files (100–500MB): larger chunks to reduce overhead
|
|
23
|
-
return 1 * MB; // 1 MB
|
|
24
|
-
}
|
|
25
|
-
else if (fileSize <= 2 * 1024 * MB) {
|
|
26
|
-
// Very large files (500MB–2GB): fewer but larger parts
|
|
27
|
-
return 2 * MB; // 2 MB
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
// Extremely large files (>2GB)
|
|
31
|
-
return 4 * MB; // 4 MB max chunk size
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
const totalChunks = (file, chunkSize) => Math.ceil(file.size / (chunkSize || getChunkSize(file.size)));
|
|
35
|
-
function chunkFile(file, chunkSize) {
|
|
36
|
-
return tslib.__asyncGenerator(this, arguments, function* chunkFile_1() {
|
|
37
|
-
const fileSize = file.size;
|
|
38
|
-
chunkSize = chunkSize || getChunkSize(fileSize);
|
|
39
|
-
let offset = 0;
|
|
40
|
-
while (offset < fileSize) {
|
|
41
|
-
const chunk = file.slice(offset, offset + chunkSize);
|
|
42
|
-
const buffer = new Uint8Array(yield tslib.__await(chunk.arrayBuffer()));
|
|
43
|
-
yield yield tslib.__await({ chunk: buffer, chunkIndex: Math.floor(offset / chunkSize) });
|
|
44
|
-
offset += chunkSize;
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
let
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return
|
|
5
|
+
function getChunkSize(fileSize) {
|
|
6
|
+
// fileSize in bytes
|
|
7
|
+
const MB = 1024 * 1024;
|
|
8
|
+
if (fileSize <= 1 * MB) {
|
|
9
|
+
// Very small files (<1MB): single small chunk
|
|
10
|
+
return 64 * 1024; // 64 KB
|
|
11
|
+
}
|
|
12
|
+
else if (fileSize <= 10 * MB) {
|
|
13
|
+
// Small files (1–10MB): medium chunks
|
|
14
|
+
return 256 * 1024; // 256 KB
|
|
15
|
+
}
|
|
16
|
+
else if (fileSize <= 100 * MB) {
|
|
17
|
+
// Medium files (10–100MB): faster upload, moderate size
|
|
18
|
+
return 512 * 1024; // 512 KB
|
|
19
|
+
}
|
|
20
|
+
else if (fileSize <= 500 * MB) {
|
|
21
|
+
// Large files (100–500MB): larger chunks to reduce overhead
|
|
22
|
+
return 1 * MB; // 1 MB
|
|
23
|
+
}
|
|
24
|
+
else if (fileSize <= 2 * 1024 * MB) {
|
|
25
|
+
// Very large files (500MB–2GB): fewer but larger parts
|
|
26
|
+
return 2 * MB; // 2 MB
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
// Extremely large files (>2GB)
|
|
30
|
+
return 4 * MB; // 4 MB max chunk size
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const totalChunks = (file, chunkSize) => Math.ceil(file.size / (chunkSize || getChunkSize(file.size)));
|
|
34
|
+
function chunkFile(file, chunkSize) {
|
|
35
|
+
return tslib.__asyncGenerator(this, arguments, function* chunkFile_1() {
|
|
36
|
+
const fileSize = file.size;
|
|
37
|
+
chunkSize = chunkSize || getChunkSize(fileSize);
|
|
38
|
+
let offset = 0;
|
|
39
|
+
while (offset < fileSize) {
|
|
40
|
+
const chunk = file.slice(offset, offset + chunkSize);
|
|
41
|
+
const buffer = new Uint8Array(yield tslib.__await(chunk.arrayBuffer()));
|
|
42
|
+
yield yield tslib.__await({ chunk: buffer, chunkIndex: Math.floor(offset / chunkSize) });
|
|
43
|
+
offset += chunkSize;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function generateFileId(str) {
|
|
48
|
+
let h1 = 0xdeadbeef ^ str.length;
|
|
49
|
+
let h2 = 0x41c6ce57 ^ str.length;
|
|
50
|
+
for (let i = 0; i < str.length; i++) {
|
|
51
|
+
const ch = str.charCodeAt(i);
|
|
52
|
+
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
53
|
+
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
54
|
+
}
|
|
55
|
+
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507);
|
|
56
|
+
h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);
|
|
57
|
+
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507);
|
|
58
|
+
h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);
|
|
59
|
+
const hex = (h1 >>> 0).toString(16).padStart(8, "0") +
|
|
60
|
+
(h2 >>> 0).toString(16).padStart(8, "0") +
|
|
61
|
+
((h1 ^ h2) >>> 0).toString(16).padStart(8, "0") +
|
|
62
|
+
((h1 + h2) >>> 0).toString(16).padStart(8, "0");
|
|
63
|
+
return hex.slice(0, 32);
|
|
64
|
+
}
|
|
65
|
+
async function getFileId(file) {
|
|
66
|
+
let data = [];
|
|
67
|
+
if (typeof window !== 'undefined') {
|
|
68
|
+
data = [
|
|
69
|
+
navigator.userAgent,
|
|
70
|
+
navigator.language,
|
|
71
|
+
screen.width,
|
|
72
|
+
screen.height,
|
|
73
|
+
screen.colorDepth,
|
|
74
|
+
new Date().getTimezoneOffset(),
|
|
75
|
+
Intl.DateTimeFormat().resolvedOptions().timeZone || ""
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
const meta = `${file.name}||${file.size}||${file.lastModified}||${data.join("||")}`;
|
|
79
|
+
const ext = file.name.split('.').pop() || '';
|
|
80
|
+
const id = generateFileId(meta);
|
|
81
|
+
return `${id}.${ext}`;
|
|
65
82
|
}
|
|
66
83
|
|
|
67
84
|
exports.chunkFile = chunkFile;
|
|
85
|
+
exports.generateFileId = generateFileId;
|
|
68
86
|
exports.getChunkSize = getChunkSize;
|
|
69
87
|
exports.getFileId = getFileId;
|
|
70
88
|
exports.totalChunks = totalChunks;
|
package/include/file.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.cjs","sources":["../../src/include/file.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"file.cjs","sources":["../../src/include/file.ts"],"sourcesContent":["export function getChunkSize(fileSize: number): number {\n // fileSize in bytes\n const MB = 1024 * 1024;\n\n if (fileSize <= 1 * MB) {\n // Very small files (<1MB): single small chunk\n return 64 * 1024; // 64 KB\n } else if (fileSize <= 10 * MB) {\n // Small files (1–10MB): medium chunks\n return 256 * 1024; // 256 KB\n } else if (fileSize <= 100 * MB) {\n // Medium files (10–100MB): faster upload, moderate size\n return 512 * 1024; // 512 KB\n } else if (fileSize <= 500 * MB) {\n // Large files (100–500MB): larger chunks to reduce overhead\n return 1 * MB; // 1 MB\n } else if (fileSize <= 2 * 1024 * MB) {\n // Very large files (500MB–2GB): fewer but larger parts\n return 2 * MB; // 2 MB\n } else {\n // Extremely large files (>2GB)\n return 4 * MB; // 4 MB max chunk size\n }\n}\n\nexport const totalChunks = (file: File, chunkSize?: number) => Math.ceil(file.size / (chunkSize || getChunkSize(file.size)));\n\nexport async function* chunkFile(file: File, chunkSize?: number) {\n const fileSize = file.size;\n chunkSize = chunkSize || getChunkSize(fileSize);\n let offset = 0;\n\n while (offset < fileSize) {\n const chunk = file.slice(offset, offset + chunkSize);\n const buffer = new Uint8Array(await chunk.arrayBuffer());\n yield { chunk: buffer, chunkIndex: Math.floor(offset / chunkSize) };\n offset += chunkSize;\n }\n}\n\nexport function generateFileId(str: string) {\n let h1 = 0xdeadbeef ^ str.length\n let h2 = 0x41c6ce57 ^ str.length\n\n for (let i = 0; i < str.length; i++) {\n const ch = str.charCodeAt(i)\n h1 = Math.imul(h1 ^ ch, 2654435761)\n h2 = Math.imul(h2 ^ ch, 1597334677)\n }\n\n h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507)\n h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909)\n\n h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507)\n h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909)\n\n const hex =\n (h1 >>> 0).toString(16).padStart(8, \"0\") +\n (h2 >>> 0).toString(16).padStart(8, \"0\") +\n ((h1 ^ h2) >>> 0).toString(16).padStart(8, \"0\") +\n ((h1 + h2) >>> 0).toString(16).padStart(8, \"0\")\n\n return hex.slice(0, 32)\n}\n\nexport async function getFileId(file: File): Promise<string> {\n let data: any[] = [];\n if (typeof window !== 'undefined') {\n data = [\n navigator.userAgent,\n navigator.language,\n screen.width,\n screen.height,\n screen.colorDepth,\n new Date().getTimezoneOffset(),\n Intl.DateTimeFormat().resolvedOptions().timeZone || \"\"\n ]\n }\n\n const meta = `${file.name}||${file.size}||${file.lastModified}||${data.join(\"||\")}`\n const ext = file.name.split('.').pop() || ''\n const id = generateFileId(meta);\n return `${id}.${ext}`;\n}"],"names":["__await"],"mappings":";;;;AAAM,SAAU,YAAY,CAAC,QAAgB,EAAA;;AAE1C,IAAA,MAAM,EAAE,GAAG,IAAI,GAAG,IAAI;AAEtB,IAAA,IAAI,QAAQ,IAAI,CAAC,GAAG,EAAE,EAAE;;AAErB,QAAA,OAAO,EAAE,GAAG,IAAI,CAAC;AAC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
import { __asyncGenerator, __await } from 'tslib';
|
|
2
|
-
import crypto from './crypto.js';
|
|
3
2
|
|
|
4
|
-
function getChunkSize(fileSize) {
|
|
5
|
-
// fileSize in bytes
|
|
6
|
-
const MB = 1024 * 1024;
|
|
7
|
-
if (fileSize <= 1 * MB) {
|
|
8
|
-
// Very small files (<1MB): single small chunk
|
|
9
|
-
return 64 * 1024; // 64 KB
|
|
10
|
-
}
|
|
11
|
-
else if (fileSize <= 10 * MB) {
|
|
12
|
-
// Small files (1–10MB): medium chunks
|
|
13
|
-
return 256 * 1024; // 256 KB
|
|
14
|
-
}
|
|
15
|
-
else if (fileSize <= 100 * MB) {
|
|
16
|
-
// Medium files (10–100MB): faster upload, moderate size
|
|
17
|
-
return 512 * 1024; // 512 KB
|
|
18
|
-
}
|
|
19
|
-
else if (fileSize <= 500 * MB) {
|
|
20
|
-
// Large files (100–500MB): larger chunks to reduce overhead
|
|
21
|
-
return 1 * MB; // 1 MB
|
|
22
|
-
}
|
|
23
|
-
else if (fileSize <= 2 * 1024 * MB) {
|
|
24
|
-
// Very large files (500MB–2GB): fewer but larger parts
|
|
25
|
-
return 2 * MB; // 2 MB
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
// Extremely large files (>2GB)
|
|
29
|
-
return 4 * MB; // 4 MB max chunk size
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
const totalChunks = (file, chunkSize) => Math.ceil(file.size / (chunkSize || getChunkSize(file.size)));
|
|
33
|
-
function chunkFile(file, chunkSize) {
|
|
34
|
-
return __asyncGenerator(this, arguments, function* chunkFile_1() {
|
|
35
|
-
const fileSize = file.size;
|
|
36
|
-
chunkSize = chunkSize || getChunkSize(fileSize);
|
|
37
|
-
let offset = 0;
|
|
38
|
-
while (offset < fileSize) {
|
|
39
|
-
const chunk = file.slice(offset, offset + chunkSize);
|
|
40
|
-
const buffer = new Uint8Array(yield __await(chunk.arrayBuffer()));
|
|
41
|
-
yield yield __await({ chunk: buffer, chunkIndex: Math.floor(offset / chunkSize) });
|
|
42
|
-
offset += chunkSize;
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
let
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return
|
|
3
|
+
function getChunkSize(fileSize) {
|
|
4
|
+
// fileSize in bytes
|
|
5
|
+
const MB = 1024 * 1024;
|
|
6
|
+
if (fileSize <= 1 * MB) {
|
|
7
|
+
// Very small files (<1MB): single small chunk
|
|
8
|
+
return 64 * 1024; // 64 KB
|
|
9
|
+
}
|
|
10
|
+
else if (fileSize <= 10 * MB) {
|
|
11
|
+
// Small files (1–10MB): medium chunks
|
|
12
|
+
return 256 * 1024; // 256 KB
|
|
13
|
+
}
|
|
14
|
+
else if (fileSize <= 100 * MB) {
|
|
15
|
+
// Medium files (10–100MB): faster upload, moderate size
|
|
16
|
+
return 512 * 1024; // 512 KB
|
|
17
|
+
}
|
|
18
|
+
else if (fileSize <= 500 * MB) {
|
|
19
|
+
// Large files (100–500MB): larger chunks to reduce overhead
|
|
20
|
+
return 1 * MB; // 1 MB
|
|
21
|
+
}
|
|
22
|
+
else if (fileSize <= 2 * 1024 * MB) {
|
|
23
|
+
// Very large files (500MB–2GB): fewer but larger parts
|
|
24
|
+
return 2 * MB; // 2 MB
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
// Extremely large files (>2GB)
|
|
28
|
+
return 4 * MB; // 4 MB max chunk size
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const totalChunks = (file, chunkSize) => Math.ceil(file.size / (chunkSize || getChunkSize(file.size)));
|
|
32
|
+
function chunkFile(file, chunkSize) {
|
|
33
|
+
return __asyncGenerator(this, arguments, function* chunkFile_1() {
|
|
34
|
+
const fileSize = file.size;
|
|
35
|
+
chunkSize = chunkSize || getChunkSize(fileSize);
|
|
36
|
+
let offset = 0;
|
|
37
|
+
while (offset < fileSize) {
|
|
38
|
+
const chunk = file.slice(offset, offset + chunkSize);
|
|
39
|
+
const buffer = new Uint8Array(yield __await(chunk.arrayBuffer()));
|
|
40
|
+
yield yield __await({ chunk: buffer, chunkIndex: Math.floor(offset / chunkSize) });
|
|
41
|
+
offset += chunkSize;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function generateFileId(str) {
|
|
46
|
+
let h1 = 0xdeadbeef ^ str.length;
|
|
47
|
+
let h2 = 0x41c6ce57 ^ str.length;
|
|
48
|
+
for (let i = 0; i < str.length; i++) {
|
|
49
|
+
const ch = str.charCodeAt(i);
|
|
50
|
+
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
51
|
+
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
52
|
+
}
|
|
53
|
+
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507);
|
|
54
|
+
h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);
|
|
55
|
+
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507);
|
|
56
|
+
h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);
|
|
57
|
+
const hex = (h1 >>> 0).toString(16).padStart(8, "0") +
|
|
58
|
+
(h2 >>> 0).toString(16).padStart(8, "0") +
|
|
59
|
+
((h1 ^ h2) >>> 0).toString(16).padStart(8, "0") +
|
|
60
|
+
((h1 + h2) >>> 0).toString(16).padStart(8, "0");
|
|
61
|
+
return hex.slice(0, 32);
|
|
62
|
+
}
|
|
63
|
+
async function getFileId(file) {
|
|
64
|
+
let data = [];
|
|
65
|
+
if (typeof window !== 'undefined') {
|
|
66
|
+
data = [
|
|
67
|
+
navigator.userAgent,
|
|
68
|
+
navigator.language,
|
|
69
|
+
screen.width,
|
|
70
|
+
screen.height,
|
|
71
|
+
screen.colorDepth,
|
|
72
|
+
new Date().getTimezoneOffset(),
|
|
73
|
+
Intl.DateTimeFormat().resolvedOptions().timeZone || ""
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
const meta = `${file.name}||${file.size}||${file.lastModified}||${data.join("||")}`;
|
|
77
|
+
const ext = file.name.split('.').pop() || '';
|
|
78
|
+
const id = generateFileId(meta);
|
|
79
|
+
return `${id}.${ext}`;
|
|
63
80
|
}
|
|
64
81
|
|
|
65
|
-
export { chunkFile, getChunkSize, getFileId, totalChunks };
|
|
82
|
+
export { chunkFile, generateFileId, getChunkSize, getFileId, totalChunks };
|
|
66
83
|
//# sourceMappingURL=file.js.map
|
package/include/file.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.js","sources":["../../src/include/file.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"file.js","sources":["../../src/include/file.ts"],"sourcesContent":["export function getChunkSize(fileSize: number): number {\n // fileSize in bytes\n const MB = 1024 * 1024;\n\n if (fileSize <= 1 * MB) {\n // Very small files (<1MB): single small chunk\n return 64 * 1024; // 64 KB\n } else if (fileSize <= 10 * MB) {\n // Small files (1–10MB): medium chunks\n return 256 * 1024; // 256 KB\n } else if (fileSize <= 100 * MB) {\n // Medium files (10–100MB): faster upload, moderate size\n return 512 * 1024; // 512 KB\n } else if (fileSize <= 500 * MB) {\n // Large files (100–500MB): larger chunks to reduce overhead\n return 1 * MB; // 1 MB\n } else if (fileSize <= 2 * 1024 * MB) {\n // Very large files (500MB–2GB): fewer but larger parts\n return 2 * MB; // 2 MB\n } else {\n // Extremely large files (>2GB)\n return 4 * MB; // 4 MB max chunk size\n }\n}\n\nexport const totalChunks = (file: File, chunkSize?: number) => Math.ceil(file.size / (chunkSize || getChunkSize(file.size)));\n\nexport async function* chunkFile(file: File, chunkSize?: number) {\n const fileSize = file.size;\n chunkSize = chunkSize || getChunkSize(fileSize);\n let offset = 0;\n\n while (offset < fileSize) {\n const chunk = file.slice(offset, offset + chunkSize);\n const buffer = new Uint8Array(await chunk.arrayBuffer());\n yield { chunk: buffer, chunkIndex: Math.floor(offset / chunkSize) };\n offset += chunkSize;\n }\n}\n\nexport function generateFileId(str: string) {\n let h1 = 0xdeadbeef ^ str.length\n let h2 = 0x41c6ce57 ^ str.length\n\n for (let i = 0; i < str.length; i++) {\n const ch = str.charCodeAt(i)\n h1 = Math.imul(h1 ^ ch, 2654435761)\n h2 = Math.imul(h2 ^ ch, 1597334677)\n }\n\n h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507)\n h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909)\n\n h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507)\n h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909)\n\n const hex =\n (h1 >>> 0).toString(16).padStart(8, \"0\") +\n (h2 >>> 0).toString(16).padStart(8, \"0\") +\n ((h1 ^ h2) >>> 0).toString(16).padStart(8, \"0\") +\n ((h1 + h2) >>> 0).toString(16).padStart(8, \"0\")\n\n return hex.slice(0, 32)\n}\n\nexport async function getFileId(file: File): Promise<string> {\n let data: any[] = [];\n if (typeof window !== 'undefined') {\n data = [\n navigator.userAgent,\n navigator.language,\n screen.width,\n screen.height,\n screen.colorDepth,\n new Date().getTimezoneOffset(),\n Intl.DateTimeFormat().resolvedOptions().timeZone || \"\"\n ]\n }\n\n const meta = `${file.name}||${file.size}||${file.lastModified}||${data.join(\"||\")}`\n const ext = file.name.split('.').pop() || ''\n const id = generateFileId(meta);\n return `${id}.${ext}`;\n}"],"names":[],"mappings":";;AAAM,SAAU,YAAY,CAAC,QAAgB,EAAA;;AAE1C,IAAA,MAAM,EAAE,GAAG,IAAI,GAAG,IAAI;AAEtB,IAAA,IAAI,QAAQ,IAAI,CAAC,GAAG,EAAE,EAAE;;AAErB,QAAA,OAAO,EAAE,GAAG,IAAI,CAAC;AACnB,IAAA;AAAM,SAAA,IAAI,QAAQ,IAAI,EAAE,GAAG,EAAE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AAE,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC;QAC/C,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC;IAElD,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;AAC1B;AAEO,eAAe,SAAS,CAAC,IAAU,EAAA;IACvC,IAAI,IAAI,GAAU,EAAE;AACpB,IAAA,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;AAChC,QAAA,IAAI,GAAG;AACJ,YAAA,SAAS,CAAC,SAAS;AACnB,YAAA,SAAS,CAAC,QAAQ;AAClB,YAAA,MAAM,CAAC,KAAK;AACZ,YAAA,MAAM,CAAC,MAAM;AACb,YAAA,MAAM,CAAC,UAAU;AACjB,YAAA,IAAI,IAAI,EAAE,CAAC,iBAAiB,EAAE;YAC9B,IAAI,CAAC,cAAc,EAAE,CAAC,eAAe,EAAE,CAAC,QAAQ,IAAI;SACtD;AACH,IAAA;IAED,MAAM,IAAI,GAAG,CAAA,EAAG,IAAI,CAAC,IAAI,CAAA,EAAA,EAAK,IAAI,CAAC,IAAI,CAAA,EAAA,EAAK,IAAI,CAAC,YAAY,KAAK,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA,CAAE;AACnF,IAAA,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE;AAC5C,IAAA,MAAM,EAAE,GAAG,cAAc,CAAC,IAAI,CAAC;AAC/B,IAAA,OAAO,CAAA,EAAG,EAAE,CAAA,CAAA,EAAI,GAAG,EAAE;AACxB;;;;"}
|
package/index.cjs
CHANGED
package/index.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ export { default as SecurequServer } from './server/index.js';
|
|
|
3
3
|
export { default as crypto } from './include/crypto.js';
|
|
4
4
|
export { default as compresor } from './include/compress.js';
|
|
5
5
|
export { default as fileScaner } from './include/file-scaner.js';
|
|
6
|
-
export { HTTPMethods, HandshakeInfo, HttpRequestInit, SecurequClientConfig, SecurequClientResponse } from './client/types.js';
|
|
6
|
+
export { FileUploadArgs, HTTPMethods, HandshakeInfo, HttpRequestInit, SecurequClientConfig, SecurequClientResponse } from './client/types.js';
|
|
7
7
|
export { HandlerFunction, HandlerInfo, ListenerInfo, Metadata, RouteFactory, SecurequServerConfig, ServerClient, ServerClientInfo, ServerClientOrigin, ServerClientSecret, ServerResponse, UploadFileMeta, UploadFilePath } from './server/types.js';
|
package/index.js
CHANGED
|
@@ -2,5 +2,5 @@ export { default as SecurequClient } from './client/index.js';
|
|
|
2
2
|
export { default as SecurequServer } from './server/index.js';
|
|
3
3
|
export { default as crypto } from './include/crypto.js';
|
|
4
4
|
export { default as compresor } from './include/compress.js';
|
|
5
|
-
export {
|
|
5
|
+
export { fileScaner } from './include/file-scaner.js';
|
|
6
6
|
//# sourceMappingURL=index.js.map
|