@autonomys/auto-drive 1.2.8 → 1.3.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/.env +6 -0
- package/README.md +22 -25
- package/dist/api/calls/download.d.ts +3 -3
- package/dist/api/calls/download.d.ts.map +1 -1
- package/dist/api/calls/index.d.ts +26 -19
- package/dist/api/calls/index.d.ts.map +1 -1
- package/dist/api/calls/read.d.ts +35 -18
- package/dist/api/calls/read.d.ts.map +1 -1
- package/dist/api/calls/read.js +39 -9
- package/dist/api/calls/upload.d.ts +11 -11
- package/dist/api/calls/upload.d.ts.map +1 -1
- package/dist/api/calls/upload.js +5 -5
- package/dist/api/calls/write.d.ts +9 -9
- package/dist/api/calls/write.d.ts.map +1 -1
- package/dist/api/calls/write.js +4 -4
- package/dist/api/connection.d.ts +2 -24
- package/dist/api/connection.d.ts.map +1 -1
- package/dist/api/connection.js +6 -30
- package/dist/api/handler.d.ts +3 -0
- package/dist/api/handler.d.ts.map +1 -0
- package/dist/api/handler.js +30 -0
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +2 -0
- package/dist/api/models/objects.d.ts +4 -0
- package/dist/api/models/objects.d.ts.map +1 -1
- package/dist/api/type.d.ts +172 -0
- package/dist/api/type.d.ts.map +1 -0
- package/dist/api/type.js +8 -0
- package/dist/api/types.d.ts +172 -0
- package/dist/api/types.d.ts.map +1 -0
- package/dist/api/types.js +8 -0
- package/dist/api/wrappers.d.ts +2 -115
- package/dist/api/wrappers.d.ts.map +1 -1
- package/dist/api/wrappers.js +178 -240
- package/dist/fs/wrappers.d.ts +1 -2
- package/dist/fs/wrappers.d.ts.map +1 -1
- package/dist/fs/wrappers.js +18 -19
- package/dist/node.d.ts +2 -2
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +25 -2
- package/package.json +4 -4
- package/src/api/calls/download.ts +3 -3
- package/src/api/calls/read.ts +61 -18
- package/src/api/calls/upload.ts +11 -11
- package/src/api/calls/write.ts +10 -10
- package/src/api/connection.ts +6 -61
- package/src/api/handler.ts +34 -0
- package/src/api/index.ts +2 -0
- package/src/api/models/objects.ts +5 -0
- package/src/api/types.ts +201 -0
- package/src/api/wrappers.ts +247 -300
- package/src/fs/wrappers.ts +11 -14
- package/src/node.ts +2 -2
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -2
- package/dist/utils/folder.d.ts +0 -2
- package/dist/utils/folder.d.ts.map +0 -1
- package/dist/utils/folder.js +0 -23
- package/dist/utils/observable.d.ts +0 -7
- package/dist/utils/observable.d.ts.map +0 -1
- package/dist/utils/observable.js +0 -15
- package/dist/utils/stream.d.ts +0 -3
- package/dist/utils/stream.d.ts.map +0 -1
- package/dist/utils/stream.js +0 -22
package/dist/api/wrappers.js
CHANGED
|
@@ -19,12 +19,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
19
19
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.
|
|
22
|
+
exports.createApiInterface = void 0;
|
|
23
23
|
const mime_types_1 = __importDefault(require("mime-types"));
|
|
24
24
|
const async_1 = require("../utils/async");
|
|
25
25
|
const misc_1 = require("../utils/misc");
|
|
26
26
|
const download_1 = require("./calls/download");
|
|
27
27
|
const index_1 = require("./calls/index");
|
|
28
|
+
const models_1 = require("./models");
|
|
28
29
|
const folderTree_1 = require("./models/folderTree");
|
|
29
30
|
const UPLOAD_FILE_CHUNK_SIZE = 1024 * 1024;
|
|
30
31
|
const uploadFileChunks = (api, fileUploadId, asyncIterable, uploadChunkSize = UPLOAD_FILE_CHUNK_SIZE, onProgress) => {
|
|
@@ -58,28 +59,53 @@ const uploadFileChunks = (api, fileUploadId, asyncIterable, uploadChunkSize = UP
|
|
|
58
59
|
}
|
|
59
60
|
}));
|
|
60
61
|
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
62
|
+
const createApiInterface = (api) => {
|
|
63
|
+
const uploadFileFromInput = (file, options = {}, uploadChunkSize) => {
|
|
64
|
+
const { password = undefined, compression = true } = options;
|
|
65
|
+
return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
+
const { compressFile, CompressionAlgorithm, encryptFile, EncryptionAlgorithm } = yield import('@autonomys/auto-dag-data');
|
|
67
|
+
let asyncIterable = (0, async_1.fileToIterable)(file);
|
|
68
|
+
if (compression) {
|
|
69
|
+
asyncIterable = compressFile(asyncIterable, {
|
|
70
|
+
level: 9,
|
|
71
|
+
algorithm: CompressionAlgorithm.ZLIB,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (password) {
|
|
75
|
+
asyncIterable = encryptFile(asyncIterable, password, {
|
|
76
|
+
algorithm: EncryptionAlgorithm.AES_256_GCM,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
const uploadOptions = {
|
|
80
|
+
compression: compression
|
|
81
|
+
? {
|
|
82
|
+
level: 9,
|
|
83
|
+
algorithm: CompressionAlgorithm.ZLIB,
|
|
84
|
+
}
|
|
85
|
+
: undefined,
|
|
86
|
+
encryption: password
|
|
87
|
+
? {
|
|
88
|
+
algorithm: EncryptionAlgorithm.AES_256_GCM,
|
|
89
|
+
}
|
|
90
|
+
: undefined,
|
|
91
|
+
};
|
|
92
|
+
const fileUpload = yield index_1.apiCalls.createFileUpload(api, {
|
|
93
|
+
mimeType: mime_types_1.default.lookup(file.name) || undefined,
|
|
94
|
+
filename: file.name,
|
|
95
|
+
uploadOptions,
|
|
96
|
+
});
|
|
97
|
+
yield uploadFileChunks(api, fileUpload.id, asyncIterable, uploadChunkSize, (bytes) => {
|
|
98
|
+
var _a;
|
|
99
|
+
(_a = options.onProgress) === null || _a === void 0 ? void 0 : _a.call(options, (0, misc_1.progressToPercentage)(bytes, file.size));
|
|
100
|
+
});
|
|
101
|
+
const result = yield index_1.apiCalls.completeUpload(api, { uploadId: fileUpload.id });
|
|
102
|
+
resolve(result.cid);
|
|
103
|
+
}));
|
|
104
|
+
};
|
|
105
|
+
const uploadFile = (file_1, ...args_1) => __awaiter(void 0, [file_1, ...args_1], void 0, function* (file, options = {}, uploadChunkSize) {
|
|
106
|
+
const { password = undefined, compression = true } = options;
|
|
81
107
|
const { compressFile, CompressionAlgorithm, encryptFile, EncryptionAlgorithm } = yield import('@autonomys/auto-dag-data');
|
|
82
|
-
let asyncIterable =
|
|
108
|
+
let asyncIterable = file.read();
|
|
83
109
|
if (compression) {
|
|
84
110
|
asyncIterable = compressFile(asyncIterable, {
|
|
85
111
|
level: 9,
|
|
@@ -114,232 +140,144 @@ const uploadFileFromInput = (api, file, options = {}, uploadChunkSize) => {
|
|
|
114
140
|
(_a = options.onProgress) === null || _a === void 0 ? void 0 : _a.call(options, (0, misc_1.progressToPercentage)(bytes, file.size));
|
|
115
141
|
});
|
|
116
142
|
const result = yield index_1.apiCalls.completeUpload(api, { uploadId: fileUpload.id });
|
|
117
|
-
|
|
118
|
-
}));
|
|
119
|
-
};
|
|
120
|
-
exports.uploadFileFromInput = uploadFileFromInput;
|
|
121
|
-
/**
|
|
122
|
-
* Uploads a file to the server with optional encryption and compression.
|
|
123
|
-
*
|
|
124
|
-
* This function reads a file from the provided input, optionally encrypts it
|
|
125
|
-
* using the specified password, and compresses it using the specified algorithm if requested.
|
|
126
|
-
* It uploads the file in chunks to the server, creating an upload session and
|
|
127
|
-
* completing it once all chunks have been successfully uploaded.
|
|
128
|
-
*
|
|
129
|
-
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
130
|
-
* @param {File | GenericFile} file - The file to be uploaded, which can be a File or a GenericFile.
|
|
131
|
-
* @param {UploadFileOptions} options - Options for the upload process.
|
|
132
|
-
* @param {string} [options.password] - The password for encryption (optional).
|
|
133
|
-
* @param {boolean} [options.compression=true] - Whether to compress the file (optional).
|
|
134
|
-
* @param {number} [uploadChunkSize] - The size of each chunk to upload (optional).
|
|
135
|
-
* @returns {Promise<string>} - The CID of the uploaded file.
|
|
136
|
-
* @throws {Error} - Throws an error if the upload fails at any stage.
|
|
137
|
-
*/
|
|
138
|
-
const uploadFile = (api_1, file_1, ...args_1) => __awaiter(void 0, [api_1, file_1, ...args_1], void 0, function* (api, file, options = {}, uploadChunkSize) {
|
|
139
|
-
const { password = undefined, compression = true } = options;
|
|
140
|
-
const { compressFile, CompressionAlgorithm, encryptFile, EncryptionAlgorithm } = yield import('@autonomys/auto-dag-data');
|
|
141
|
-
let asyncIterable = file.read();
|
|
142
|
-
if (compression) {
|
|
143
|
-
asyncIterable = compressFile(asyncIterable, {
|
|
144
|
-
level: 9,
|
|
145
|
-
algorithm: CompressionAlgorithm.ZLIB,
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
if (password) {
|
|
149
|
-
asyncIterable = encryptFile(asyncIterable, password, {
|
|
150
|
-
algorithm: EncryptionAlgorithm.AES_256_GCM,
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
const uploadOptions = {
|
|
154
|
-
compression: compression
|
|
155
|
-
? {
|
|
156
|
-
level: 9,
|
|
157
|
-
algorithm: CompressionAlgorithm.ZLIB,
|
|
158
|
-
}
|
|
159
|
-
: undefined,
|
|
160
|
-
encryption: password
|
|
161
|
-
? {
|
|
162
|
-
algorithm: EncryptionAlgorithm.AES_256_GCM,
|
|
163
|
-
}
|
|
164
|
-
: undefined,
|
|
165
|
-
};
|
|
166
|
-
const fileUpload = yield index_1.apiCalls.createFileUpload(api, {
|
|
167
|
-
mimeType: mime_types_1.default.lookup(file.name) || undefined,
|
|
168
|
-
filename: file.name,
|
|
169
|
-
uploadOptions,
|
|
143
|
+
return result.cid;
|
|
170
144
|
});
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
145
|
+
const uploadObjectAsJSON = (object_1, name_1, ...args_1) => __awaiter(void 0, [object_1, name_1, ...args_1], void 0, function* (object, name, options = {}, uploadChunkSize) {
|
|
146
|
+
try {
|
|
147
|
+
const json = Buffer.from(JSON.stringify(object));
|
|
148
|
+
return uploadFile({
|
|
149
|
+
read: () => (0, async_1.bufferToIterable)(json),
|
|
150
|
+
name: name || 'object.json',
|
|
151
|
+
mimeType: 'application/json',
|
|
152
|
+
size: json.length,
|
|
153
|
+
}, options, uploadChunkSize);
|
|
154
|
+
}
|
|
155
|
+
catch (e) {
|
|
156
|
+
throw new Error('Failed to serialize object to JSON');
|
|
157
|
+
}
|
|
174
158
|
});
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
return (0, exports.uploadFile)(api, {
|
|
198
|
-
read: () => (0, async_1.bufferToIterable)(json),
|
|
199
|
-
name: name || 'object.json',
|
|
200
|
-
mimeType: 'application/json',
|
|
201
|
-
size: json.length,
|
|
202
|
-
}, options, uploadChunkSize);
|
|
203
|
-
}
|
|
204
|
-
catch (e) {
|
|
205
|
-
throw new Error('Failed to serialize object to JSON');
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
exports.uploadObjectAsJSON = uploadObjectAsJSON;
|
|
209
|
-
/**
|
|
210
|
-
* Uploads an entire folder to the server.
|
|
211
|
-
*
|
|
212
|
-
* This function retrieves all files within the specified folder,
|
|
213
|
-
* constructs a file tree representation, and initiates the upload
|
|
214
|
-
* process. It also handles optional compression of the files during
|
|
215
|
-
* the upload. If a password is provided, the files will be zipped
|
|
216
|
-
* before uploading.
|
|
217
|
-
*
|
|
218
|
-
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
219
|
-
* @param {FileList | File[]} fileList - The list of files to be uploaded.
|
|
220
|
-
* @param {Object} options - Options for the upload process.
|
|
221
|
-
* @param {number} [options.uploadChunkSize] - The size of each chunk to upload (optional).
|
|
222
|
-
* @param {string} [options.password] - The password for encryption (optional).
|
|
223
|
-
* @returns {PromisedObservable<UploadFileStatus | UploadFolderStatus>} - An observable that emits the upload status.
|
|
224
|
-
* @throws {Error} - Throws an error if the upload fails at any stage.
|
|
225
|
-
*/
|
|
226
|
-
const uploadFolderFromInput = (api_1, fileList_1, ...args_1) => __awaiter(void 0, [api_1, fileList_1, ...args_1], void 0, function* (api, fileList, { uploadChunkSize, password, onProgress, } = {}) {
|
|
227
|
-
const files = fileList instanceof FileList ? Array.from(fileList) : fileList;
|
|
228
|
-
const fileTree = (0, folderTree_1.constructFromInput)(files);
|
|
229
|
-
// If password is provided, we zip the files and upload the zip file
|
|
230
|
-
if (password) {
|
|
231
|
-
const filesMap = Object.fromEntries(files.map((file) => [file.webkitRelativePath, file]));
|
|
232
|
-
const zipBlob = yield (0, folderTree_1.constructZipBlobFromTreeAndPaths)(fileTree, filesMap);
|
|
233
|
-
const name = fileList[0].webkitRelativePath.split('/').filter(Boolean)[0];
|
|
234
|
-
return (0, exports.uploadFile)(api, {
|
|
235
|
-
read: () => (0, async_1.fileToIterable)(zipBlob),
|
|
236
|
-
name: `${name}.zip`,
|
|
237
|
-
mimeType: 'application/zip',
|
|
238
|
-
size: zipBlob.size,
|
|
239
|
-
}, {
|
|
240
|
-
password,
|
|
241
|
-
compression: true,
|
|
242
|
-
onProgress,
|
|
159
|
+
const uploadFolderFromInput = (fileList_1, ...args_1) => __awaiter(void 0, [fileList_1, ...args_1], void 0, function* (fileList, { uploadChunkSize, password, onProgress, } = {}) {
|
|
160
|
+
const files = fileList instanceof FileList ? Array.from(fileList) : fileList;
|
|
161
|
+
const fileTree = (0, folderTree_1.constructFromInput)(files);
|
|
162
|
+
// If password is provided, we zip the files and upload the zip file
|
|
163
|
+
if (password) {
|
|
164
|
+
const filesMap = Object.fromEntries(files.map((file) => [file.webkitRelativePath, file]));
|
|
165
|
+
const zipBlob = yield (0, folderTree_1.constructZipBlobFromTreeAndPaths)(fileTree, filesMap);
|
|
166
|
+
const name = fileList[0].webkitRelativePath.split('/').filter(Boolean)[0];
|
|
167
|
+
return uploadFile({
|
|
168
|
+
read: () => (0, async_1.fileToIterable)(zipBlob),
|
|
169
|
+
name: `${name}.zip`,
|
|
170
|
+
mimeType: 'application/zip',
|
|
171
|
+
size: zipBlob.size,
|
|
172
|
+
}, {
|
|
173
|
+
password,
|
|
174
|
+
compression: true,
|
|
175
|
+
onProgress,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
// Otherwise, we upload the files as a folder w/o compression or encryption
|
|
179
|
+
const folderUpload = yield index_1.apiCalls.createFolderUpload(api, {
|
|
180
|
+
fileTree,
|
|
243
181
|
});
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
182
|
+
let currentBytesUploaded = 0;
|
|
183
|
+
const totalSize = files.reduce((acc, file) => acc + file.size, 0);
|
|
184
|
+
for (const file of files) {
|
|
185
|
+
yield uploadFileWithinFolderUpload(folderUpload.id, {
|
|
186
|
+
read: () => (0, async_1.fileToIterable)(file),
|
|
187
|
+
name: file.name,
|
|
188
|
+
mimeType: mime_types_1.default.lookup(file.name) || undefined,
|
|
189
|
+
size: file.size,
|
|
190
|
+
path: file.webkitRelativePath,
|
|
191
|
+
}, uploadChunkSize, {
|
|
192
|
+
onProgress: (progress) => {
|
|
193
|
+
onProgress === null || onProgress === void 0 ? void 0 : onProgress((0, misc_1.progressToPercentage)(currentBytesUploaded + progress, totalSize));
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
currentBytesUploaded += file.size;
|
|
197
|
+
}
|
|
198
|
+
const result = yield index_1.apiCalls.completeUpload(api, { uploadId: folderUpload.id });
|
|
199
|
+
return result.cid;
|
|
248
200
|
});
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
yield (0, exports.uploadFileWithinFolderUpload)(api, folderUpload.id, {
|
|
253
|
-
read: () => (0, async_1.fileToIterable)(file),
|
|
201
|
+
const uploadFileWithinFolderUpload = (uploadId_1, file_1, uploadChunkSize_1, ...args_1) => __awaiter(void 0, [uploadId_1, file_1, uploadChunkSize_1, ...args_1], void 0, function* (uploadId, file, uploadChunkSize, options = {}) {
|
|
202
|
+
const fileUpload = yield index_1.apiCalls.createFileUploadWithinFolderUpload(api, {
|
|
203
|
+
uploadId,
|
|
254
204
|
name: file.name,
|
|
255
|
-
mimeType:
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}, uploadChunkSize, {
|
|
259
|
-
onProgress: (progress) => {
|
|
260
|
-
onProgress === null || onProgress === void 0 ? void 0 : onProgress((0, misc_1.progressToPercentage)(currentBytesUploaded + progress, totalSize));
|
|
261
|
-
},
|
|
205
|
+
mimeType: file.mimeType,
|
|
206
|
+
relativeId: file.path,
|
|
207
|
+
uploadOptions: {},
|
|
262
208
|
});
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
return result.cid;
|
|
267
|
-
});
|
|
268
|
-
exports.uploadFolderFromInput = uploadFolderFromInput;
|
|
269
|
-
/**
|
|
270
|
-
* Uploads a file within an existing folder upload session.
|
|
271
|
-
*
|
|
272
|
-
* @param {AutoDriveApi} api - The API instance to interact with the AutoDrive service.
|
|
273
|
-
* @param {string} uploadId - The ID of the folder upload session to which the file will be added.
|
|
274
|
-
* @param {string} filepath - The path of the file to be uploaded.
|
|
275
|
-
*
|
|
276
|
-
* @returns {Promise<void>} A promise that resolves when the file upload is complete.
|
|
277
|
-
*/
|
|
278
|
-
const uploadFileWithinFolderUpload = (api_1, uploadId_1, file_1, uploadChunkSize_1, ...args_1) => __awaiter(void 0, [api_1, uploadId_1, file_1, uploadChunkSize_1, ...args_1], void 0, function* (api, uploadId, file, uploadChunkSize, options = {}) {
|
|
279
|
-
const fileUpload = yield index_1.apiCalls.createFileUploadWithinFolderUpload(api, {
|
|
280
|
-
uploadId,
|
|
281
|
-
name: file.name,
|
|
282
|
-
mimeType: file.mimeType,
|
|
283
|
-
relativeId: file.path,
|
|
284
|
-
uploadOptions: {},
|
|
209
|
+
yield uploadFileChunks(api, fileUpload.id, file.read(), uploadChunkSize, options.onProgress);
|
|
210
|
+
const result = yield index_1.apiCalls.completeUpload(api, { uploadId: fileUpload.id });
|
|
211
|
+
return result.cid;
|
|
285
212
|
});
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
const downloadFile = (api, cid, password) => __awaiter(void 0, void 0, void 0, function* () {
|
|
299
|
-
var _a, _b;
|
|
300
|
-
const { decompressFile, CompressionAlgorithm, EncryptionAlgorithm, decryptFile } = yield import('@autonomys/auto-dag-data');
|
|
301
|
-
const metadata = yield index_1.apiCalls.getObjectMetadata(api, { cid });
|
|
302
|
-
let iterable = (0, async_1.asyncFromStream)(yield index_1.apiCalls.downloadObject(api, { cid }));
|
|
303
|
-
if ((_a = metadata.uploadOptions) === null || _a === void 0 ? void 0 : _a.encryption) {
|
|
304
|
-
if (!password) {
|
|
305
|
-
throw new Error('Password is required to decrypt the file');
|
|
213
|
+
const downloadFile = (cid, password) => __awaiter(void 0, void 0, void 0, function* () {
|
|
214
|
+
var _a, _b;
|
|
215
|
+
const { decompressFile, CompressionAlgorithm, EncryptionAlgorithm, decryptFile } = yield import('@autonomys/auto-dag-data');
|
|
216
|
+
const metadata = yield index_1.apiCalls.getObjectMetadata(api, { cid });
|
|
217
|
+
let iterable = (0, async_1.asyncFromStream)(yield index_1.apiCalls.downloadObject(api, { cid }));
|
|
218
|
+
if ((_a = metadata.uploadOptions) === null || _a === void 0 ? void 0 : _a.encryption) {
|
|
219
|
+
if (!password) {
|
|
220
|
+
throw new Error('Password is required to decrypt the file');
|
|
221
|
+
}
|
|
222
|
+
iterable = decryptFile(iterable, password, {
|
|
223
|
+
algorithm: EncryptionAlgorithm.AES_256_GCM,
|
|
224
|
+
});
|
|
306
225
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
226
|
+
if ((_b = metadata.uploadOptions) === null || _b === void 0 ? void 0 : _b.compression) {
|
|
227
|
+
iterable = decompressFile(iterable, {
|
|
228
|
+
algorithm: CompressionAlgorithm.ZLIB,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
return iterable;
|
|
232
|
+
});
|
|
233
|
+
const getPendingCredits = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
234
|
+
const me = yield index_1.apiCalls.getMe(api);
|
|
235
|
+
return {
|
|
236
|
+
upload: me.subscription.pendingUploadCredits,
|
|
237
|
+
download: me.subscription.pendingDownloadCredits,
|
|
238
|
+
};
|
|
239
|
+
});
|
|
240
|
+
const getSubscriptionInfo = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
241
|
+
const me = yield index_1.apiCalls.getMe(api);
|
|
242
|
+
return me.subscription;
|
|
243
|
+
});
|
|
244
|
+
const publishObject = (cid) => __awaiter(void 0, void 0, void 0, function* () {
|
|
245
|
+
const result = yield index_1.apiCalls.publishObject(api, { cid });
|
|
246
|
+
return (0, download_1.publicDownloadUrl)(api, result.result);
|
|
247
|
+
});
|
|
248
|
+
const getMyFiles = (page_1, ...args_1) => __awaiter(void 0, [page_1, ...args_1], void 0, function* (page, limit = 100) {
|
|
249
|
+
const result = yield index_1.apiCalls.getRoots(api, {
|
|
250
|
+
scope: models_1.Scope.User,
|
|
251
|
+
limit,
|
|
252
|
+
offset: page * limit,
|
|
314
253
|
});
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
const
|
|
320
|
-
|
|
254
|
+
return result;
|
|
255
|
+
});
|
|
256
|
+
const searchByNameOrCIDInMyFiles = (value) => __awaiter(void 0, void 0, void 0, function* () {
|
|
257
|
+
const results = yield index_1.apiCalls.searchByNameOrCID(api, { value, scope: models_1.Scope.User });
|
|
258
|
+
const summaries = yield Promise.all(results.map((e) => __awaiter(void 0, void 0, void 0, function* () { return index_1.apiCalls.getObjectSummary(api, { cid: e.cid }); })));
|
|
259
|
+
return summaries;
|
|
260
|
+
});
|
|
261
|
+
const searchByNameOrCID = (value) => __awaiter(void 0, void 0, void 0, function* () {
|
|
262
|
+
const results = yield index_1.apiCalls.searchByNameOrCID(api, { value, scope: models_1.Scope.Global });
|
|
263
|
+
const summaries = yield Promise.all(results.map((e) => __awaiter(void 0, void 0, void 0, function* () { return index_1.apiCalls.getObjectSummary(api, { cid: e.cid }); })));
|
|
264
|
+
return summaries;
|
|
265
|
+
});
|
|
321
266
|
return {
|
|
322
|
-
|
|
323
|
-
|
|
267
|
+
uploadFileFromInput,
|
|
268
|
+
uploadFile,
|
|
269
|
+
uploadObjectAsJSON,
|
|
270
|
+
uploadFolderFromInput,
|
|
271
|
+
uploadFileWithinFolderUpload,
|
|
272
|
+
downloadFile,
|
|
273
|
+
getPendingCredits,
|
|
274
|
+
getSubscriptionInfo,
|
|
275
|
+
publishObject,
|
|
276
|
+
getMyFiles,
|
|
277
|
+
searchByNameOrCIDInMyFiles,
|
|
278
|
+
searchByNameOrCID,
|
|
279
|
+
sendRequest: api.sendRequest,
|
|
280
|
+
baseUrl: api.baseUrl,
|
|
324
281
|
};
|
|
325
|
-
}
|
|
326
|
-
exports.
|
|
327
|
-
const getSubscriptionInfo = (api) => __awaiter(void 0, void 0, void 0, function* () {
|
|
328
|
-
const me = yield index_1.apiCalls.getMe(api);
|
|
329
|
-
return me.subscription;
|
|
330
|
-
});
|
|
331
|
-
exports.getSubscriptionInfo = getSubscriptionInfo;
|
|
332
|
-
/**
|
|
333
|
-
* Publishes an object by sending a request to the server.
|
|
334
|
-
*
|
|
335
|
-
* If already published, it will return the same public download URL.
|
|
336
|
-
*
|
|
337
|
-
* @param api {AutoDriveApi} - The API instance used to send requests.
|
|
338
|
-
* @param cid {string} - The CID of the object to publish.
|
|
339
|
-
* @returns {Promise<string>} - The public download URL of the published object.
|
|
340
|
-
*/
|
|
341
|
-
const publishObject = (api, cid) => __awaiter(void 0, void 0, void 0, function* () {
|
|
342
|
-
const result = yield index_1.apiCalls.publishObject(api, { cid });
|
|
343
|
-
return (0, download_1.publicDownloadUrl)(api, result.result);
|
|
344
|
-
});
|
|
345
|
-
exports.publishObject = publishObject;
|
|
282
|
+
};
|
|
283
|
+
exports.createApiInterface = createApiInterface;
|
package/dist/fs/wrappers.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrappers.d.ts","sourceRoot":"","sources":["../../src/fs/wrappers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wrappers.d.ts","sourceRoot":"","sources":["../../src/fs/wrappers.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAK9D;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,sBAAsB,QAC5B,YAAY,YACP,MAAM,YACP,iBAAiB,oBACR,MAAM,KACvB,OAAO,CAAC,MAAM,CAkBhB,CAAA;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,0BAA0B,QAChC,YAAY,cACL,MAAM,+CAKf;IACD,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,CAAC,oBAAoB,EAAE,MAAM,KAAK,IAAI,CAAA;CACpD,KACA,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAyDzB,CAAA"}
|
package/dist/fs/wrappers.js
CHANGED
|
@@ -15,13 +15,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.uploadFolderFromFolderPath = exports.uploadFileFromFilepath = void 0;
|
|
16
16
|
const fs_1 = __importDefault(require("fs"));
|
|
17
17
|
const mime_types_1 = __importDefault(require("mime-types"));
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const utils_js_1 = require("./utils.js");
|
|
18
|
+
const index_1 = require("../api/index");
|
|
19
|
+
const folderTree_1 = require("../api/models/folderTree");
|
|
20
|
+
const uploads_1 = require("../api/models/uploads");
|
|
21
|
+
const index_2 = require("../utils/index");
|
|
22
|
+
const misc_1 = require("../utils/misc");
|
|
23
|
+
const utils_1 = require("./utils");
|
|
25
24
|
/**
|
|
26
25
|
* Uploads a file to the server with optional encryption and compression.
|
|
27
26
|
*
|
|
@@ -42,7 +41,7 @@ const utils_js_1 = require("./utils.js");
|
|
|
42
41
|
const uploadFileFromFilepath = (api, filePath, options = {}, uploadChunkSize) => {
|
|
43
42
|
const { password = undefined, compression = true, onProgress } = options;
|
|
44
43
|
const name = filePath.split('/').pop();
|
|
45
|
-
return
|
|
44
|
+
return api.uploadFile({
|
|
46
45
|
read: () => fs_1.default.createReadStream(filePath),
|
|
47
46
|
name,
|
|
48
47
|
mimeType: mime_types_1.default.lookup(name) || undefined,
|
|
@@ -73,14 +72,14 @@ exports.uploadFileFromFilepath = uploadFileFromFilepath;
|
|
|
73
72
|
* @throws {Error} - Throws an error if the upload fails at any stage.
|
|
74
73
|
*/
|
|
75
74
|
const uploadFolderFromFolderPath = (api_1, folderPath_1, ...args_1) => __awaiter(void 0, [api_1, folderPath_1, ...args_1], void 0, function* (api, folderPath, { uploadChunkSize, password, onProgress, } = {}) {
|
|
76
|
-
const files = yield (0,
|
|
77
|
-
const fileTree = (0,
|
|
75
|
+
const files = yield (0, utils_1.getFiles)(folderPath);
|
|
76
|
+
const fileTree = (0, folderTree_1.constructFromFileSystemEntries)(files);
|
|
78
77
|
if (password) {
|
|
79
78
|
const filesMap = Object.fromEntries(files.map((file) => [file, file]));
|
|
80
|
-
const zipBlob = yield (0,
|
|
79
|
+
const zipBlob = yield (0, utils_1.constructZipFromTreeAndFileSystemPaths)(fileTree, filesMap);
|
|
81
80
|
const name = folderPath.split('/').pop();
|
|
82
|
-
return
|
|
83
|
-
read: () => (0,
|
|
81
|
+
return api.uploadFile({
|
|
82
|
+
read: () => (0, index_2.fileToIterable)(zipBlob),
|
|
84
83
|
name: `${name}.zip`,
|
|
85
84
|
mimeType: 'application/zip',
|
|
86
85
|
size: zipBlob.size,
|
|
@@ -88,15 +87,15 @@ const uploadFolderFromFolderPath = (api_1, folderPath_1, ...args_1) => __awaiter
|
|
|
88
87
|
password,
|
|
89
88
|
compression: true,
|
|
90
89
|
onProgress: (progressInPercentage) => {
|
|
91
|
-
onProgress === null || onProgress === void 0 ? void 0 : onProgress((0,
|
|
90
|
+
onProgress === null || onProgress === void 0 ? void 0 : onProgress((0, misc_1.progressToPercentage)(progressInPercentage, zipBlob.size));
|
|
92
91
|
},
|
|
93
92
|
});
|
|
94
93
|
}
|
|
95
|
-
const folderUpload = yield
|
|
94
|
+
const folderUpload = yield index_1.apiCalls.createFolderUpload(api, {
|
|
96
95
|
fileTree,
|
|
97
96
|
uploadOptions: {
|
|
98
97
|
compression: {
|
|
99
|
-
algorithm:
|
|
98
|
+
algorithm: uploads_1.CompressionAlgorithm.ZLIB,
|
|
100
99
|
level: 9,
|
|
101
100
|
},
|
|
102
101
|
},
|
|
@@ -111,14 +110,14 @@ const uploadFolderFromFolderPath = (api_1, folderPath_1, ...args_1) => __awaiter
|
|
|
111
110
|
const totalSize = genericFiles.reduce((acc, file) => acc + file.size, 0);
|
|
112
111
|
let progress = 0;
|
|
113
112
|
for (const file of genericFiles) {
|
|
114
|
-
yield
|
|
113
|
+
yield api.uploadFileWithinFolderUpload(folderUpload.id, file, uploadChunkSize, {
|
|
115
114
|
onProgress: (uploadedBytes) => {
|
|
116
|
-
onProgress === null || onProgress === void 0 ? void 0 : onProgress((0,
|
|
115
|
+
onProgress === null || onProgress === void 0 ? void 0 : onProgress((0, misc_1.progressToPercentage)(progress + uploadedBytes, totalSize));
|
|
117
116
|
},
|
|
118
117
|
});
|
|
119
118
|
progress += file.size;
|
|
120
119
|
}
|
|
121
|
-
const result = yield
|
|
120
|
+
const result = yield index_1.apiCalls.completeUpload(api, { uploadId: folderUpload.id });
|
|
122
121
|
return result.cid;
|
|
123
122
|
});
|
|
124
123
|
exports.uploadFolderFromFolderPath = uploadFolderFromFolderPath;
|
package/dist/node.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './browser
|
|
2
|
-
export * from './fs/index
|
|
1
|
+
export * from './browser';
|
|
2
|
+
export * as fs from './fs/index';
|
|
3
3
|
//# sourceMappingURL=node.d.ts.map
|
package/dist/node.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,OAAO,KAAK,EAAE,MAAM,YAAY,CAAA"}
|
package/dist/node.js
CHANGED
|
@@ -10,9 +10,32 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
13
18
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
19
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
20
|
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
16
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
__exportStar(require("./
|
|
39
|
+
exports.fs = void 0;
|
|
40
|
+
__exportStar(require("./browser"), exports);
|
|
41
|
+
exports.fs = __importStar(require("./fs/index"));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autonomys/auto-drive",
|
|
3
3
|
"packageManager": "yarn@4.2.2",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -42,13 +42,13 @@
|
|
|
42
42
|
"typescript": "^5.6.3"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@autonomys/auto-dag-data": "^1.
|
|
46
|
-
"@autonomys/auto-utils": "^1.
|
|
45
|
+
"@autonomys/auto-dag-data": "^1.3.0",
|
|
46
|
+
"@autonomys/auto-utils": "^1.3.0",
|
|
47
47
|
"jszip": "^3.10.1",
|
|
48
48
|
"mime-types": "^2.1.35",
|
|
49
49
|
"process": "^0.11.10",
|
|
50
50
|
"stream": "^0.0.3",
|
|
51
51
|
"zod": "^3.23.8"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "c3194075c27e38d074dbff97abdcd6607dca75ae"
|
|
54
54
|
}
|