@autonomys/auto-drive 1.4.0 → 1.4.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.
- package/.env +6 -0
- package/dist/api/calls/download.d.ts.map +1 -1
- package/dist/api/calls/index.d.ts.map +1 -1
- package/dist/api/calls/read.d.ts.map +1 -1
- package/dist/api/calls/upload.d.ts.map +1 -1
- package/dist/api/calls/write.d.ts.map +1 -1
- package/dist/api/connection.d.ts.map +1 -1
- package/dist/api/handler.d.ts.map +1 -1
- package/dist/api/models/folderTree.d.ts.map +1 -1
- package/dist/api/networks.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 +7 -1
- package/dist/api/types.d.ts.map +1 -1
- package/dist/api/wrappers.d.ts.map +1 -1
- package/dist/api/wrappers.js +9 -7
- package/dist/fs/utils.d.ts.map +1 -1
- package/dist/fs/wrappers.d.ts.map +1 -1
- package/dist/fs/wrappers.js +2 -2
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/misc.d.ts.map +1 -1
- package/package.json +11 -10
- package/src/api/types.ts +8 -1
- package/src/api/wrappers.ts +9 -1
- package/src/fs/wrappers.ts +1 -1
- package/src/utils/index.ts +0 -1
- 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/src/utils/async.ts +0 -42
package/.env
ADDED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../../src/api/calls/download.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAE9C,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../../src/api/calls/download.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAE9C,eAAO,MAAM,cAAc,GACzB,KAAK,mBAAmB,EACxB,OAAO,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,KAC7E,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAmBpC,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAI,KAAK,mBAAmB,EAAE,KAAK,MAAM,KAAG,MAEzE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/calls/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,QAAQ
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/calls/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,QAAQ;kBAMshB,qCAA2B,EAAC;;;MAAkE;0BAAkiC,qCAA2B,EAAC;;MAAgD;oBAAi7B,qCAA2B,EAAC;;MAAgD;oBAAs6B,qCAA2B,EAAC;;MAAgD;;;uBAA//F,qCAA2B,EAAC;gBAAkG,CAAC;;;MAA8E;yBAAyiC,qCAA2B,EAAC;;qBAA2G,CAAC;MAAsB;yCAA41C,qCAA2B,EAAC;;;gBAAkK,CAAC;;;MAAyE;sBAAg1C,qCAA2B,EAAC;;;;MAAuH;qBAA0qC,qCAA2B,EAAC;;MAA4D;eAA76L,qCAA2B,EAAC;;MAA8C;sBAA29B,qCAA2B,EAAC,+CAA4B;wBAAuX,qCAA2B,EAAC;;;MAAgE;iBAA67B,qCAA2B,EAAC,+CAA4B;gBAA28B,qCAA2B,EAAC;;MAAgD;uBAAi1B,qCAA2B,EAAC;;MAAgD;4BAA89B,qCAA2B,EAAC;;MAAgD;sBAAk+B,qCAA2B,EAAC;;MAAgD;wBAA6/B,qCAA2B,EAAC;;MAAgD;YAA4jB,qCAAwB;qBAR9sR,qCAEZ,EAAE;;6BAIX,CAAD;MAAY;wBAEwf,qCAAwB,EAAC,WAAY;CADziB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../../src/api/calls/read.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAC/F,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAE9C;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,
|
|
1
|
+
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../../src/api/calls/read.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAC/F,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE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U3C,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe,GAC1B,KAAK,mBAAmB,EACxB,OAAO,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,KAC5C,OAAO,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAUrC,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iBAAiB,GAC5B,KAAK,mBAAmB,EACxB,OAAO,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,KAC5C,OAAO,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAUvC,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,GAAU,KAAK,mBAAmB,KAAG,OAAO,CAAC,QAAQ,CAStE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../../src/api/calls/upload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,EACL,sBAAsB,EACtB,UAAU,EACV,iBAAiB,EACjB,YAAY,EACb,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAE9C;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../../src/api/calls/upload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,EACL,sBAAsB,EACtB,UAAU,EACV,iBAAiB,EACjB,YAAY,EACb,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAE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|
-
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/api/calls/write.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAE9C;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/api/calls/write.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAE9C;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,WAAW,GACtB,KAAK,mBAAmB,EACxB,OAAO,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,iBAkBhE,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,GAC9B,KAAK,mBAAmB,EACxB,OAAO,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,KAC5C,OAAO,CAAC,IAAI,CAQd,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,GACxB,KAAK,mBAAmB,EACxB,OAAO,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,KAC5C,OAAO,CAAC,IAAI,CAUd,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,GACxB,KAAK,mBAAmB,EACxB,OAAO,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,KAC5C,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAU5B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/api/connection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAGzD,eAAO,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/api/connection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAGzD,eAAO,MAAM,kBAAkB,GAAI,SAAS,iBAAiB,KAAG,YAG/D,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/api/handler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEhE,eAAO,MAAM,uBAAuB,
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/api/handler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEhE,eAAO,MAAM,uBAAuB,GAAI,qCAKrC,iBAAiB,KAAG,mBA2BtB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"folderTree.d.ts","sourceRoot":"","sources":["../../../src/api/models/folderTree.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,QAAQ,CAAA;IACd,QAAQ,EAAE,UAAU,EAAE,CAAA;IACtB,EAAE,EAAE,MAAM,CAAA;CACX,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,EAAE,MAAM,CAAA;CACX,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,gBAAgB,GAAG,cAAc,CAAA;AAE1D,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;EAKjC,CAAA;AAEF,eAAO,MAAM,oBAAoB;;;;;;;;;;;;EAI/B,CAAA;AAEF,eAAO,MAAM,gBAAgB,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,CAGjD,CAAA;AAEF,eAAO,MAAM,8BAA8B,
|
|
1
|
+
{"version":3,"file":"folderTree.d.ts","sourceRoot":"","sources":["../../../src/api/models/folderTree.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,QAAQ,CAAA;IACd,QAAQ,EAAE,UAAU,EAAE,CAAA;IACtB,EAAE,EAAE,MAAM,CAAA;CACX,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,EAAE,MAAM,CAAA;CACX,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,gBAAgB,GAAG,cAAc,CAAA;AAE1D,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;EAKjC,CAAA;AAEF,eAAO,MAAM,oBAAoB;;;;;;;;;;;;EAI/B,CAAA;AAEF,eAAO,MAAM,gBAAgB,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,CAGjD,CAAA;AAEF,eAAO,MAAM,8BAA8B,GAAI,SAAS,MAAM,EAAE,KAAG,UA0ClE,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,OAAO,IAAI,EAAE,KAAG,UASlD,CAAA;AAoBD,eAAO,MAAM,gCAAgC,GAC3C,MAAM,UAAU,EAChB,OAAO,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,kBAU5B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"networks.d.ts","sourceRoot":"","sources":["../../src/api/networks.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,gBAAgB,GAAG,MAAM,OAAO,QAAQ,CAAA;AAEpD,eAAO,MAAM,QAAQ;;;CAGyB,CAAA;AAE9C,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"networks.d.ts","sourceRoot":"","sources":["../../src/api/networks.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,gBAAgB,GAAG,MAAM,OAAO,QAAQ,CAAA;AAEpD,eAAO,MAAM,QAAQ;;;CAGyB,CAAA;AAE9C,eAAO,MAAM,aAAa,GAAI,WAAW,gBAAgB,WAMxD,CAAA"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { ObjectSummary } from './models';
|
|
2
|
+
import { PaginatedResult } from './models/common';
|
|
3
|
+
import { GenericFile, GenericFileWithinFolder } from './models/file';
|
|
4
|
+
import { SubscriptionInfo } from './models/user';
|
|
5
|
+
import { AutoDriveNetwork } from './networks';
|
|
6
|
+
export interface AutoDriveApi extends AutoDriveApiHandler {
|
|
7
|
+
/**
|
|
8
|
+
* Uploads a file to the server with optional encryption and compression.
|
|
9
|
+
*
|
|
10
|
+
* This function reads a file from the provided input, optionally encrypts it
|
|
11
|
+
* using the specified password, and compresses it using the specified algorithm if requested.
|
|
12
|
+
* It uploads the file in chunks to the server, creating an upload session and
|
|
13
|
+
* completing it once all chunks have been successfully uploaded.
|
|
14
|
+
*
|
|
15
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
16
|
+
* @param {File} file - The file to be uploaded.
|
|
17
|
+
* @param {UploadFileOptions} options - Options for the upload process.
|
|
18
|
+
* @param {string} [options.password] - The password for encryption (optional).
|
|
19
|
+
* @param {boolean} [options.compression=true] - Whether to compress the file (optional).
|
|
20
|
+
* @param {number} [uploadChunkSize] - The size of each chunk to upload (optional).
|
|
21
|
+
* @returns {PromisedObservable<UploadFileStatus>} - An observable that emits the upload status.
|
|
22
|
+
* @throws {Error} - Throws an error if the upload fails at any stage.
|
|
23
|
+
*/
|
|
24
|
+
uploadFileFromInput: (file: File, options: UploadFileOptions, uploadChunkSize?: number) => Promise<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Uploads a file to the server with optional encryption and compression.
|
|
27
|
+
*
|
|
28
|
+
* This function reads a file from the provided input, optionally encrypts it
|
|
29
|
+
* using the specified password, and compresses it using the specified algorithm if requested.
|
|
30
|
+
* It uploads the file in chunks to the server, creating an upload session and
|
|
31
|
+
* completing it once all chunks have been successfully uploaded.
|
|
32
|
+
*
|
|
33
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
34
|
+
* @param {File | GenericFile} file - The file to be uploaded, which can be a File or a GenericFile.
|
|
35
|
+
* @param {UploadFileOptions} options - Options for the upload process.
|
|
36
|
+
* @param {string} [options.password] - The password for encryption (optional).
|
|
37
|
+
* @param {boolean} [options.compression=true] - Whether to compress the file (optional).
|
|
38
|
+
* @param {number} [uploadChunkSize] - The size of each chunk to upload (optional).
|
|
39
|
+
* @returns {Promise<string>} - The CID of the uploaded file.
|
|
40
|
+
* @throws {Error} - Throws an error if the upload fails at any stage.
|
|
41
|
+
*/
|
|
42
|
+
uploadFile: (file: GenericFile, options: UploadFileOptions, uploadChunkSize?: number) => Promise<string>;
|
|
43
|
+
/**
|
|
44
|
+
* Uploads an object as a JSON file to the server.
|
|
45
|
+
*
|
|
46
|
+
* This function serializes the provided object to a JSON string,
|
|
47
|
+
* and then uploads the JSON string as a file to the server.
|
|
48
|
+
*
|
|
49
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
50
|
+
* @param {File | GenericFile} file - The file to be uploaded, which can be a File or a GenericFile.
|
|
51
|
+
* @param {UploadFileOptions} options - Options for the upload process.
|
|
52
|
+
* @param {string} [options.password] - The password for encryption (optional).
|
|
53
|
+
* @param {boolean} [options.compression=true] - Whether to compress the file (optional).
|
|
54
|
+
* @param {number} [uploadChunkSize] - The size of each chunk to upload (optional).
|
|
55
|
+
* @returns {Promise<string>} - The CID of the uploaded file.
|
|
56
|
+
* @throws {Error} - Throws an error if the upload fails at any stage.
|
|
57
|
+
*/
|
|
58
|
+
uploadObjectAsJSON: (object: unknown, name?: string | undefined, options?: UploadFileOptions, uploadChunkSize?: number) => Promise<string>;
|
|
59
|
+
/**
|
|
60
|
+
* Uploads an entire folder to the server.
|
|
61
|
+
*
|
|
62
|
+
* This function retrieves all files within the specified folder,
|
|
63
|
+
* constructs a file tree representation, and initiates the upload
|
|
64
|
+
* process. It also handles optional compression of the files during
|
|
65
|
+
* the upload. If a password is provided, the files will be zipped
|
|
66
|
+
* before uploading.
|
|
67
|
+
*
|
|
68
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
69
|
+
* @param {FileList | File[]} fileList - The list of files to be uploaded.
|
|
70
|
+
* @param {Object} options - Options for the upload process.
|
|
71
|
+
* @param {number} [options.uploadChunkSize] - The size of each chunk to upload (optional).
|
|
72
|
+
* @param {string} [options.password] - The password for encryption (optional).
|
|
73
|
+
* @returns {PromisedObservable<UploadFileStatus | UploadFolderStatus>} - An observable that emits the upload status.
|
|
74
|
+
* @throws {Error} - Throws an error if the upload fails at any stage.
|
|
75
|
+
*/
|
|
76
|
+
uploadFolderFromInput: (fileList: FileList | File[], options: {
|
|
77
|
+
uploadChunkSize?: number;
|
|
78
|
+
password?: string;
|
|
79
|
+
onProgress?: (progress: number) => void;
|
|
80
|
+
}) => Promise<string>;
|
|
81
|
+
/**
|
|
82
|
+
* Uploads a file within an existing folder upload session.
|
|
83
|
+
*
|
|
84
|
+
* @param {AutoDriveApi} api - The API instance to interact with the AutoDrive service.
|
|
85
|
+
* @param {string} uploadId - The ID of the folder upload session to which the file will be added.
|
|
86
|
+
* @param {string} filepath - The path of the file to be uploaded.
|
|
87
|
+
*
|
|
88
|
+
* @returns {Promise<void>} A promise that resolves when the file upload is complete.
|
|
89
|
+
*/
|
|
90
|
+
uploadFileWithinFolderUpload: (uploadId: string, file: GenericFileWithinFolder, uploadChunkSize?: number, options?: Pick<UploadFileOptions, 'onProgress'>) => Promise<string>;
|
|
91
|
+
/**
|
|
92
|
+
* Downloads a file from the AutoDrive service.
|
|
93
|
+
*
|
|
94
|
+
* @param {AutoDriveApi} api - The API instance to interact with the AutoDrive service.
|
|
95
|
+
* @param {string} cid - The CID of the file to be downloaded.
|
|
96
|
+
* @returns {Promise<ReadableStream<Uint8Array>>} A promise that resolves to a ReadableStream of the downloaded file.
|
|
97
|
+
*/
|
|
98
|
+
downloadFile: (cid: string, password?: string) => Promise<AsyncIterable<Buffer>>;
|
|
99
|
+
/**
|
|
100
|
+
* Gets the pending credits for the current user.
|
|
101
|
+
*
|
|
102
|
+
* @returns {Promise<{ upload: number; download: number }>} A promise that resolves to the pending credits.
|
|
103
|
+
*/
|
|
104
|
+
getPendingCredits: () => Promise<{
|
|
105
|
+
upload: number;
|
|
106
|
+
download: number;
|
|
107
|
+
}>;
|
|
108
|
+
/**
|
|
109
|
+
* Gets the subscription info for the current user.
|
|
110
|
+
*
|
|
111
|
+
* @returns {Promise<SubscriptionInfo>} A promise that resolves to the subscription info.
|
|
112
|
+
*/
|
|
113
|
+
getSubscriptionInfo: () => Promise<SubscriptionInfo>;
|
|
114
|
+
/**
|
|
115
|
+
* Publishes an object by sending a request to the server.
|
|
116
|
+
*
|
|
117
|
+
* If already published, it will return the same public download URL.
|
|
118
|
+
*
|
|
119
|
+
* @param cid {string} - The CID of the object to publish.
|
|
120
|
+
* @returns {Promise<string>} - The public download URL of the published object.
|
|
121
|
+
*/
|
|
122
|
+
publishObject: (cid: string) => Promise<string>;
|
|
123
|
+
/**
|
|
124
|
+
* Gets the files of the current user.
|
|
125
|
+
*
|
|
126
|
+
* @param page {number} - The page number to get.
|
|
127
|
+
* @param limit {number} - The number of files to get per page.
|
|
128
|
+
* @returns {Promise<PaginatedResult<ObjectSummary>>} - A promise that resolves to the paginated result of the files.
|
|
129
|
+
*/
|
|
130
|
+
getMyFiles: (page: number, limit: number) => Promise<PaginatedResult<ObjectSummary>>;
|
|
131
|
+
/**
|
|
132
|
+
* Searches for files by name or CID in the user's files.
|
|
133
|
+
*
|
|
134
|
+
* @param value {string} - The value to search for.
|
|
135
|
+
* @returns {Promise<ObjectSummary[]>} - A promise that resolves to the list of files matching the search criteria.
|
|
136
|
+
*/
|
|
137
|
+
searchByNameOrCIDInMyFiles: (value: string) => Promise<ObjectSummary[]>;
|
|
138
|
+
/**
|
|
139
|
+
* Searches for files by name or CID in the global files.
|
|
140
|
+
*
|
|
141
|
+
* @param value {string} - The value to search for.
|
|
142
|
+
* @returns {Promise<ObjectSummary[]>} - A promise that resolves to the list of files matching the search criteria.
|
|
143
|
+
*/
|
|
144
|
+
searchByNameOrCID: (value: string) => Promise<ObjectSummary[]>;
|
|
145
|
+
}
|
|
146
|
+
export interface AutoDriveApiHandler {
|
|
147
|
+
sendRequest: (relativeUrl: string, request: Partial<Request>, body?: BodyInit) => Promise<Response>;
|
|
148
|
+
baseUrl: string;
|
|
149
|
+
}
|
|
150
|
+
export type UploadFileOptions = {
|
|
151
|
+
password?: string;
|
|
152
|
+
compression?: boolean;
|
|
153
|
+
onProgress?: (progress: number) => void;
|
|
154
|
+
};
|
|
155
|
+
export declare enum OAuthProvider {
|
|
156
|
+
GOOGLE = "google",
|
|
157
|
+
DISCORD = "discord"
|
|
158
|
+
}
|
|
159
|
+
export type ApiKeyAuthProvider = 'apikey';
|
|
160
|
+
export type AuthProvider = ApiKeyAuthProvider | 'oauth';
|
|
161
|
+
export type ConnectionOptions = {
|
|
162
|
+
provider?: AuthProvider;
|
|
163
|
+
apiKey?: string;
|
|
164
|
+
url?: null;
|
|
165
|
+
network: AutoDriveNetwork;
|
|
166
|
+
} | {
|
|
167
|
+
provider?: AuthProvider;
|
|
168
|
+
apiKey?: string;
|
|
169
|
+
url: string;
|
|
170
|
+
network?: null;
|
|
171
|
+
};
|
|
172
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":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AE,MAAM,CAAA;IACjB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;CACxC,CAAA;AAED,oBAAY,aAAa;IACvB,MAAM,WAAW;IACjB,OAAO,YAAY;CACpB;AAED,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAA;AACzC,MAAM,MAAM,YAAY,GAAG,kBAAkB,GAAG,OAAO,CAAA;AAEvD,MAAM,MAAM,iBAAiB,GACzB;IACE,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,CAAC,EAAE,IAAI,CAAA;IACV,OAAO,EAAE,gBAAgB,CAAA;CAC1B,GACD;IACE,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,CAAC,EAAE,IAAI,CAAA;CACf,CAAA"}
|
package/dist/api/type.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OAuthProvider = void 0;
|
|
4
|
+
var OAuthProvider;
|
|
5
|
+
(function (OAuthProvider) {
|
|
6
|
+
OAuthProvider["GOOGLE"] = "google";
|
|
7
|
+
OAuthProvider["DISCORD"] = "discord";
|
|
8
|
+
})(OAuthProvider || (exports.OAuthProvider = OAuthProvider = {}));
|
package/dist/api/types.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { ObjectSummary } from './models';
|
|
2
2
|
import { PaginatedResult } from './models/common';
|
|
3
3
|
import { GenericFile, GenericFileWithinFolder } from './models/file';
|
|
4
|
-
import { SubscriptionInfo } from './models/user';
|
|
4
|
+
import { SubscriptionInfo, UserInfo } from './models/user';
|
|
5
5
|
import { AutoDriveNetwork } from './networks';
|
|
6
6
|
export interface AutoDriveApi extends AutoDriveApiHandler {
|
|
7
|
+
/**
|
|
8
|
+
* Gets the user info for the current user.
|
|
9
|
+
*
|
|
10
|
+
* @returns {Promise<UserInfo>} A promise that resolves to the user info.
|
|
11
|
+
*/
|
|
12
|
+
me: () => Promise<UserInfo>;
|
|
7
13
|
/**
|
|
8
14
|
* Uploads a file to the server with optional encryption and compression.
|
|
9
15
|
*
|
package/dist/api/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/api/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/api/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AACpE,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAE7C,MAAM,WAAW,YAAa,SAAQ,mBAAmB;IACvD;;;;OAIG;IACH,EAAE,EAAE,MAAM,OAAO,CAAC,QAAQ,CAAC,CAAA;IAE3B;;;;;;;;;;;;;;;;OAgBG;IACH,mBAAmB,EAAE,CACnB,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,iBAAiB,EAC1B,eAAe,CAAC,EAAE,MAAM,KACrB,OAAO,CAAC,MAAM,CAAC,CAAA;IACpB;;;;;;;;;;;;;;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AC,EAAE,MAAM,CAAA;IACf,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,CAAC,EAAE,IAAI,CAAA;CACf,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrappers.d.ts","sourceRoot":"","sources":["../../src/api/wrappers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wrappers.d.ts","sourceRoot":"","sources":["../../src/api/wrappers.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAqB,MAAM,SAAS,CAAA;AA6B9E,eAAO,MAAM,kBAAkB,GAAI,KAAK,mBAAmB,KAAG,YAgU7D,CAAA"}
|
package/dist/api/wrappers.js
CHANGED
|
@@ -20,8 +20,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
22
|
exports.createApiInterface = void 0;
|
|
23
|
+
const asynchronous_1 = require("@autonomys/asynchronous");
|
|
23
24
|
const mime_types_1 = __importDefault(require("mime-types"));
|
|
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");
|
|
@@ -35,7 +35,7 @@ const uploadFileChunks = (api, fileUploadId, asyncIterable, uploadChunkSize = UP
|
|
|
35
35
|
let index = 0;
|
|
36
36
|
let uploadBytes = 0;
|
|
37
37
|
try {
|
|
38
|
-
for (var _d = true, _e = __asyncValues((0,
|
|
38
|
+
for (var _d = true, _e = __asyncValues((0, asynchronous_1.asyncByChunk)(asyncIterable, uploadChunkSize)), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
|
|
39
39
|
_c = _f.value;
|
|
40
40
|
_d = false;
|
|
41
41
|
const chunk = _c;
|
|
@@ -64,7 +64,7 @@ const createApiInterface = (api) => {
|
|
|
64
64
|
const { password = undefined, compression = true } = options;
|
|
65
65
|
return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
66
|
const { compressFile, CompressionAlgorithm, encryptFile, EncryptionAlgorithm } = yield import('@autonomys/auto-dag-data');
|
|
67
|
-
let asyncIterable = (0,
|
|
67
|
+
let asyncIterable = (0, asynchronous_1.fileToIterable)(file);
|
|
68
68
|
if (compression) {
|
|
69
69
|
asyncIterable = compressFile(asyncIterable, {
|
|
70
70
|
level: 9,
|
|
@@ -146,7 +146,7 @@ const createApiInterface = (api) => {
|
|
|
146
146
|
try {
|
|
147
147
|
const json = Buffer.from(JSON.stringify(object));
|
|
148
148
|
return uploadFile({
|
|
149
|
-
read: () => (0,
|
|
149
|
+
read: () => (0, asynchronous_1.bufferToIterable)(json),
|
|
150
150
|
name: name || 'object.json',
|
|
151
151
|
mimeType: 'application/json',
|
|
152
152
|
size: json.length,
|
|
@@ -165,7 +165,7 @@ const createApiInterface = (api) => {
|
|
|
165
165
|
const zipBlob = yield (0, folderTree_1.constructZipBlobFromTreeAndPaths)(fileTree, filesMap);
|
|
166
166
|
const name = fileList[0].webkitRelativePath.split('/').filter(Boolean)[0];
|
|
167
167
|
return uploadFile({
|
|
168
|
-
read: () => (0,
|
|
168
|
+
read: () => (0, asynchronous_1.fileToIterable)(zipBlob),
|
|
169
169
|
name: `${name}.zip`,
|
|
170
170
|
mimeType: 'application/zip',
|
|
171
171
|
size: zipBlob.size,
|
|
@@ -183,7 +183,7 @@ const createApiInterface = (api) => {
|
|
|
183
183
|
const totalSize = files.reduce((acc, file) => acc + file.size, 0);
|
|
184
184
|
for (const file of files) {
|
|
185
185
|
yield uploadFileWithinFolderUpload(folderUpload.id, {
|
|
186
|
-
read: () => (0,
|
|
186
|
+
read: () => (0, asynchronous_1.fileToIterable)(file),
|
|
187
187
|
name: file.name,
|
|
188
188
|
mimeType: mime_types_1.default.lookup(file.name) || undefined,
|
|
189
189
|
size: file.size,
|
|
@@ -214,7 +214,7 @@ const createApiInterface = (api) => {
|
|
|
214
214
|
var _a, _b;
|
|
215
215
|
const { decompressFile, CompressionAlgorithm, EncryptionAlgorithm, decryptFile } = yield import('@autonomys/auto-dag-data');
|
|
216
216
|
const metadata = yield index_1.apiCalls.getObjectMetadata(api, { cid });
|
|
217
|
-
let iterable = (0,
|
|
217
|
+
let iterable = (0, asynchronous_1.asyncFromStream)(yield index_1.apiCalls.downloadObject(api, { cid }));
|
|
218
218
|
if ((_a = metadata.uploadOptions) === null || _a === void 0 ? void 0 : _a.encryption) {
|
|
219
219
|
if (!password) {
|
|
220
220
|
throw new Error('Password is required to decrypt the file');
|
|
@@ -263,7 +263,9 @@ const createApiInterface = (api) => {
|
|
|
263
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
264
|
return summaries;
|
|
265
265
|
});
|
|
266
|
+
const me = () => index_1.apiCalls.getMe(api);
|
|
266
267
|
return {
|
|
268
|
+
me,
|
|
267
269
|
uploadFileFromInput,
|
|
268
270
|
uploadFile,
|
|
269
271
|
uploadObjectAsJSON,
|
package/dist/fs/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/fs/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAoB,MAAM,IAAI,CAAA;AAIlD,OAAO,EAAE,UAAU,EAAoB,MAAM,0BAA0B,CAAA;AAEvE,eAAO,MAAM,QAAQ,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/fs/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAoB,MAAM,IAAI,CAAA;AAIlD,OAAO,EAAE,UAAU,EAAoB,MAAM,0BAA0B,CAAA;AAEvE,eAAO,MAAM,QAAQ,GAAU,YAAY,MAAM,KAAG,OAAO,CAAC,MAAM,EAAE,CAWnE,CAAA;AAED,eAAO,MAAM,wBAAwB,GACnC,iBAAiB,WAAW,KAC3B,cAAc,CAAC,UAAU,CAoB3B,CAAA;AAyBD,eAAO,MAAM,sCAAsC,GACjD,MAAM,UAAU,EAChB,OAAO,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,kBAU9B,CAAA"}
|
|
@@ -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":"AAOA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAI9D;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,sBAAsB,GACjC,KAAK,YAAY,EACjB,UAAU,MAAM,EAChB,UAAS,iBAAsB,EAC/B,kBAAkB,MAAM,KACvB,OAAO,CAAC,MAAM,CAkBhB,CAAA;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,0BAA0B,GACrC,KAAK,YAAY,EACjB,YAAY,MAAM,EAClB,6CAIG;IACD,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,CAAC,oBAAoB,EAAE,MAAM,KAAK,IAAI,CAAA;CAC/C,KACL,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAyDzB,CAAA"}
|
package/dist/fs/wrappers.js
CHANGED
|
@@ -13,12 +13,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.uploadFolderFromFolderPath = exports.uploadFileFromFilepath = void 0;
|
|
16
|
+
const asynchronous_1 = require("@autonomys/asynchronous");
|
|
16
17
|
const fs_1 = __importDefault(require("fs"));
|
|
17
18
|
const mime_types_1 = __importDefault(require("mime-types"));
|
|
18
19
|
const index_1 = require("../api/index");
|
|
19
20
|
const folderTree_1 = require("../api/models/folderTree");
|
|
20
21
|
const uploads_1 = require("../api/models/uploads");
|
|
21
|
-
const index_2 = require("../utils/index");
|
|
22
22
|
const misc_1 = require("../utils/misc");
|
|
23
23
|
const utils_1 = require("./utils");
|
|
24
24
|
/**
|
|
@@ -79,7 +79,7 @@ const uploadFolderFromFolderPath = (api_1, folderPath_1, ...args_1) => __awaiter
|
|
|
79
79
|
const zipBlob = yield (0, utils_1.constructZipFromTreeAndFileSystemPaths)(fileTree, filesMap);
|
|
80
80
|
const name = folderPath.split('/').pop();
|
|
81
81
|
return api.uploadFile({
|
|
82
|
-
read: () => (0,
|
|
82
|
+
read: () => (0, asynchronous_1.fileToIterable)(zipBlob),
|
|
83
83
|
name: `${name}.zip`,
|
|
84
84
|
mimeType: 'application/zip',
|
|
85
85
|
size: zipBlob.size,
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,SAAS,CAAA"}
|
package/dist/utils/index.js
CHANGED
|
@@ -14,6 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./async"), exports);
|
|
18
17
|
__exportStar(require("./misc"), exports);
|
|
19
18
|
__exportStar(require("./types"), exports);
|
package/dist/utils/misc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"misc.d.ts","sourceRoot":"","sources":["../../src/utils/misc.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,
|
|
1
|
+
{"version":3,"file":"misc.d.ts","sourceRoot":"","sources":["../../src/utils/misc.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,GAAI,SAAS,MAAM,EAAE,QAAQ,MAAM,WAA6B,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autonomys/auto-drive",
|
|
3
3
|
"packageManager": "yarn@4.7.0",
|
|
4
|
-
"version": "1.4.
|
|
4
|
+
"version": "1.4.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -31,24 +31,25 @@
|
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@prerenderer/rollup-plugin": "^0.3.12",
|
|
34
|
-
"@rollup/plugin-commonjs": "^28.0.
|
|
34
|
+
"@rollup/plugin-commonjs": "^28.0.3",
|
|
35
35
|
"@rollup/plugin-json": "^6.1.0",
|
|
36
|
-
"@rollup/plugin-node-resolve": "^
|
|
37
|
-
"@rollup/plugin-terser": "^0.4.
|
|
38
|
-
"@rollup/plugin-typescript": "^12.1.
|
|
39
|
-
"@types/mime-types": "^2",
|
|
36
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
37
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
38
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
39
|
+
"@types/mime-types": "^2.1.4",
|
|
40
40
|
"rollup-plugin-jscc": "^2.0.0",
|
|
41
41
|
"tslib": "^2.8.1",
|
|
42
42
|
"typescript": "^5.6.3"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@autonomys/
|
|
46
|
-
"@autonomys/auto-
|
|
45
|
+
"@autonomys/asynchronous": "1.4.1",
|
|
46
|
+
"@autonomys/auto-dag-data": "^1.4.1",
|
|
47
|
+
"@autonomys/auto-utils": "^1.4.1",
|
|
47
48
|
"jszip": "^3.10.1",
|
|
48
49
|
"mime-types": "^2.1.35",
|
|
49
50
|
"process": "^0.11.10",
|
|
50
51
|
"stream": "^0.0.3",
|
|
51
|
-
"zod": "^3.
|
|
52
|
+
"zod": "^3.24.2"
|
|
52
53
|
},
|
|
53
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "115cb6ba785c73fa7c536381d5b04d8b3fcd68b9"
|
|
54
55
|
}
|
package/src/api/types.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { ObjectSummary } from './models'
|
|
2
2
|
import { PaginatedResult } from './models/common'
|
|
3
3
|
import { GenericFile, GenericFileWithinFolder } from './models/file'
|
|
4
|
-
import { SubscriptionInfo } from './models/user'
|
|
4
|
+
import { SubscriptionInfo, UserInfo } from './models/user'
|
|
5
5
|
import { AutoDriveNetwork } from './networks'
|
|
6
6
|
|
|
7
7
|
export interface AutoDriveApi extends AutoDriveApiHandler {
|
|
8
|
+
/**
|
|
9
|
+
* Gets the user info for the current user.
|
|
10
|
+
*
|
|
11
|
+
* @returns {Promise<UserInfo>} A promise that resolves to the user info.
|
|
12
|
+
*/
|
|
13
|
+
me: () => Promise<UserInfo>
|
|
14
|
+
|
|
8
15
|
/**
|
|
9
16
|
* Uploads a file to the server with optional encryption and compression.
|
|
10
17
|
*
|
package/src/api/wrappers.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
asyncByChunk,
|
|
3
|
+
asyncFromStream,
|
|
4
|
+
bufferToIterable,
|
|
5
|
+
fileToIterable,
|
|
6
|
+
} from '@autonomys/asynchronous'
|
|
1
7
|
import mime from 'mime-types'
|
|
2
|
-
import { asyncByChunk, asyncFromStream, bufferToIterable, fileToIterable } from '../utils/async'
|
|
3
8
|
import { progressToPercentage } from '../utils/misc'
|
|
4
9
|
import { publicDownloadUrl } from './calls/download'
|
|
5
10
|
import { apiCalls } from './calls/index'
|
|
@@ -338,7 +343,10 @@ export const createApiInterface = (api: AutoDriveApiHandler): AutoDriveApi => {
|
|
|
338
343
|
return summaries
|
|
339
344
|
}
|
|
340
345
|
|
|
346
|
+
const me = () => apiCalls.getMe(api)
|
|
347
|
+
|
|
341
348
|
return {
|
|
349
|
+
me,
|
|
342
350
|
uploadFileFromInput,
|
|
343
351
|
uploadFile,
|
|
344
352
|
uploadObjectAsJSON,
|
package/src/fs/wrappers.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fileToIterable } from '@autonomys/asynchronous'
|
|
1
2
|
import fs from 'fs'
|
|
2
3
|
import mime from 'mime-types'
|
|
3
4
|
import { apiCalls } from '../api/index'
|
|
@@ -5,7 +6,6 @@ import { GenericFileWithinFolder } from '../api/models/file'
|
|
|
5
6
|
import { constructFromFileSystemEntries } from '../api/models/folderTree'
|
|
6
7
|
import { CompressionAlgorithm } from '../api/models/uploads'
|
|
7
8
|
import { AutoDriveApi, UploadFileOptions } from '../api/types'
|
|
8
|
-
import { fileToIterable } from '../utils/index'
|
|
9
9
|
import { progressToPercentage } from '../utils/misc'
|
|
10
10
|
import { constructZipFromTreeAndFileSystemPaths, getFiles } from './utils'
|
|
11
11
|
|
package/src/utils/index.ts
CHANGED
package/dist/index.d.ts
DELETED
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA"}
|
package/dist/index.js
DELETED
package/dist/utils/folder.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"folder.d.ts","sourceRoot":"","sources":["../../src/utils/folder.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,QAAQ,eAAsB,MAAM,KAAG,OAAO,CAAC,MAAM,EAAE,CAWnE,CAAA"}
|
package/dist/utils/folder.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import fs from 'fs/promises';
|
|
11
|
-
import path from 'path';
|
|
12
|
-
export const getFiles = (folderPath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
13
|
-
const stat = yield fs.stat(folderPath);
|
|
14
|
-
if (stat.isDirectory()) {
|
|
15
|
-
const files = yield fs.readdir(folderPath);
|
|
16
|
-
const promises = files.map((file) => getFiles(path.join(folderPath, file)));
|
|
17
|
-
const allFiles = yield Promise.all(promises);
|
|
18
|
-
return allFiles.flat();
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
return [folderPath];
|
|
22
|
-
}
|
|
23
|
-
});
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import * as rxjs from 'rxjs';
|
|
2
|
-
export declare class PromisedObservable<T> extends rxjs.Observable<T> {
|
|
3
|
-
constructor(subscribe?: (this: rxjs.Observable<T>, subscriber: rxjs.Subscriber<T>) => void);
|
|
4
|
-
get promise(): Promise<T>;
|
|
5
|
-
}
|
|
6
|
-
export declare const firstValueFrom: typeof rxjs.firstValueFrom, lastValueFrom: typeof rxjs.lastValueFrom;
|
|
7
|
-
//# sourceMappingURL=observable.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"observable.d.ts","sourceRoot":"","sources":["../../src/utils/observable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAQ5B,qBAAa,kBAAkB,CAAC,CAAC,CAAE,SAAQ,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;gBAC/C,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;IAI1F,IAAI,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,CAExB;CACF;AAED,eAAO,MAAQ,cAAc,8BAAE,aAAa,2BAAS,CAAA"}
|
package/dist/utils/observable.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import * as rxjs from 'rxjs';
|
|
2
|
-
const asyncCallback = (callback) => {
|
|
3
|
-
return (t) => {
|
|
4
|
-
callback(t);
|
|
5
|
-
};
|
|
6
|
-
};
|
|
7
|
-
export class PromisedObservable extends rxjs.Observable {
|
|
8
|
-
constructor(subscribe) {
|
|
9
|
-
super(subscribe && asyncCallback(subscribe));
|
|
10
|
-
}
|
|
11
|
-
get promise() {
|
|
12
|
-
return lastValueFrom(this);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export const { firstValueFrom, lastValueFrom } = rxjs;
|
package/dist/utils/stream.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/utils/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,IAAI,CAAA;AAEhC,eAAO,MAAM,wBAAwB,oBAClB,WAAW,KAC3B,cAAc,CAAC,UAAU,CAoB3B,CAAA"}
|
package/dist/utils/stream.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export const createWriteStreamAdapter = (nodeWriteStream) => {
|
|
2
|
-
return new WritableStream({
|
|
3
|
-
write(chunk) {
|
|
4
|
-
return new Promise((resolve, reject) => {
|
|
5
|
-
nodeWriteStream.write(chunk, (err) => {
|
|
6
|
-
if (err) {
|
|
7
|
-
reject(err);
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
resolve();
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
},
|
|
15
|
-
close() {
|
|
16
|
-
nodeWriteStream.end();
|
|
17
|
-
},
|
|
18
|
-
abort(err) {
|
|
19
|
-
nodeWriteStream.destroy(err);
|
|
20
|
-
},
|
|
21
|
-
});
|
|
22
|
-
};
|
package/src/utils/async.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { Buffer } from 'buffer'
|
|
2
|
-
|
|
3
|
-
export const asyncByChunk = async function* (
|
|
4
|
-
asyncIterable: AsyncIterable<Buffer>,
|
|
5
|
-
chunkSize: number,
|
|
6
|
-
) {
|
|
7
|
-
let buffer = Buffer.alloc(0)
|
|
8
|
-
|
|
9
|
-
for await (const chunk of asyncIterable) {
|
|
10
|
-
buffer = Buffer.concat([buffer, chunk])
|
|
11
|
-
while (buffer.length >= chunkSize) {
|
|
12
|
-
yield buffer.subarray(0, chunkSize)
|
|
13
|
-
buffer = buffer.subarray(chunkSize)
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (buffer.length > 0) {
|
|
18
|
-
yield buffer
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const asyncFromStream = async function* (
|
|
23
|
-
stream: ReadableStream<Uint8Array>,
|
|
24
|
-
): AsyncIterable<Buffer> {
|
|
25
|
-
const reader = stream.getReader()
|
|
26
|
-
let result = await reader.read()
|
|
27
|
-
while (!result.done) {
|
|
28
|
-
yield Buffer.from(result.value)
|
|
29
|
-
result = await reader.read()
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const fileToIterable = async function* (file: File | Blob): AsyncIterable<Buffer> {
|
|
34
|
-
const chunkSize = 1024 * 1024
|
|
35
|
-
for (let i = 0; i < file.size; i += chunkSize) {
|
|
36
|
-
yield Buffer.from(await file.slice(i, i + chunkSize).arrayBuffer())
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export const bufferToIterable = async function* (buffer: Buffer): AsyncIterable<Buffer> {
|
|
41
|
-
yield buffer
|
|
42
|
-
}
|