@secrecy/lib 1.35.1 → 1.36.0-feat-upload-lite-file.1
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.
|
@@ -12,6 +12,7 @@ import { decrypt, encrypt } from '../worker/sodium.js';
|
|
|
12
12
|
import { apiDataToExternal } from './convert/data.js';
|
|
13
13
|
import { apiNodeFullToInternalFull, apiNodeToExternal, apiNodeToExternalNodeFull, internalNodeFullToNodeFull, } from './convert/node.js';
|
|
14
14
|
import { promiseAllLimit } from '../utils/promise.js';
|
|
15
|
+
import { kiloToBytes } from '../utils.js';
|
|
15
16
|
// import { md5 } from "../worker/index.js";
|
|
16
17
|
// import { firstValueFrom, of } from "rxjs";
|
|
17
18
|
export class SecrecyCloudClient {
|
|
@@ -46,6 +47,35 @@ export class SecrecyCloudClient {
|
|
|
46
47
|
}
|
|
47
48
|
return internalNodeFullToNodeFull(node);
|
|
48
49
|
}
|
|
50
|
+
async uploadLiteData({ data, encryptProgress, uploadProgress, signal, }) {
|
|
51
|
+
const dataBuffer = data instanceof File ? new Uint8Array(await data.arrayBuffer()) : data;
|
|
52
|
+
if (dataBuffer.byteLength > kiloToBytes(4500)) {
|
|
53
|
+
throw new Error('The data is too big for lite upload!');
|
|
54
|
+
}
|
|
55
|
+
const compressed = compress(dataBuffer);
|
|
56
|
+
const dataKey = secretStreamKeygen();
|
|
57
|
+
const { data: encryptedData, md5: md5Data, md5Encrypted, } = await encrypt(dataKey, compressed, encryptProgress, signal);
|
|
58
|
+
const encryptedDataKey = encryptCryptoBox(dataKey, this.#keys.publicKey, this.#keys.privateKey);
|
|
59
|
+
await uploadProgress?.({
|
|
60
|
+
total: encryptedData.byteLength,
|
|
61
|
+
current: 0,
|
|
62
|
+
percent: 0,
|
|
63
|
+
});
|
|
64
|
+
const uploadData = await this.#apiClient.cloud.uploadLiteData.mutate({
|
|
65
|
+
content: Buffer.from(encryptedData),
|
|
66
|
+
dataSize: BigInt(encryptedData.byteLength),
|
|
67
|
+
dataSizeBefore: BigInt(dataBuffer.byteLength),
|
|
68
|
+
dataKey: sodium.to_hex(encryptedDataKey),
|
|
69
|
+
md5Encrypted,
|
|
70
|
+
md5: md5Data,
|
|
71
|
+
}, { signal });
|
|
72
|
+
await uploadProgress?.({
|
|
73
|
+
total: encryptedData.byteLength,
|
|
74
|
+
current: encryptedData.byteLength,
|
|
75
|
+
percent: 1,
|
|
76
|
+
});
|
|
77
|
+
return uploadData.id;
|
|
78
|
+
}
|
|
49
79
|
async uploadData({ data, encryptProgress, uploadProgress, signal, }) {
|
|
50
80
|
const dataKey = secretStreamKeygen();
|
|
51
81
|
const dataBuffer = data instanceof File ? new Uint8Array(await data.arrayBuffer()) : data;
|
|
@@ -58,7 +88,7 @@ export class SecrecyCloudClient {
|
|
|
58
88
|
dataKey: sodium.to_hex(encryptedDataKey),
|
|
59
89
|
md5Encrypted,
|
|
60
90
|
md5: md5Data,
|
|
61
|
-
});
|
|
91
|
+
}, { signal });
|
|
62
92
|
await uploadProgress?.({
|
|
63
93
|
total: encryptedData.byteLength,
|
|
64
94
|
current: 0,
|
|
@@ -80,13 +110,13 @@ export class SecrecyCloudClient {
|
|
|
80
110
|
dataId: uploadData.id,
|
|
81
111
|
md5,
|
|
82
112
|
order,
|
|
83
|
-
});
|
|
113
|
+
}, { signal });
|
|
84
114
|
return isUploadPartEnded;
|
|
85
115
|
};
|
|
86
116
|
const uploadEnded = async () => {
|
|
87
117
|
const { isUploadEnded } = await this.#apiClient.cloud.uploadDataEnd.mutate({
|
|
88
118
|
dataId: uploadData.id,
|
|
89
|
-
});
|
|
119
|
+
}, { signal });
|
|
90
120
|
return isUploadEnded;
|
|
91
121
|
};
|
|
92
122
|
const chunkParts = new Array();
|
|
@@ -9,6 +9,12 @@ export declare class SecrecyCloudClient {
|
|
|
9
9
|
dataId: string;
|
|
10
10
|
nodeId: string;
|
|
11
11
|
}): Promise<NodeFull>;
|
|
12
|
+
uploadLiteData({ data, encryptProgress, uploadProgress, signal, }: {
|
|
13
|
+
data: globalThis.File | Uint8Array;
|
|
14
|
+
encryptProgress?: ProgressCallback;
|
|
15
|
+
uploadProgress?: ProgressCallback;
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
}): Promise<string>;
|
|
12
18
|
uploadData({ data, encryptProgress, uploadProgress, signal, }: {
|
|
13
19
|
data: globalThis.File | Uint8Array;
|
|
14
20
|
encryptProgress?: ProgressCallback;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@secrecy/lib",
|
|
3
3
|
"author": "Anonymize <anonymize@gmail.com>",
|
|
4
4
|
"description": "Anonymize Secrecy Library",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.36.0-feat-upload-lite-file.1",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/anonymize-org/lib.git"
|