@autonomys/auto-drive 1.1.4 → 1.2.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/README.md +42 -84
- package/dist/api/calls/index.d.ts +1 -0
- package/dist/api/calls/index.d.ts.map +1 -1
- package/dist/api/calls/read.d.ts +9 -0
- package/dist/api/calls/read.d.ts.map +1 -1
- package/dist/api/calls/read.js +18 -1
- package/dist/api/models/user.d.ts +28 -0
- package/dist/api/models/user.d.ts.map +1 -0
- package/dist/api/models/user.js +8 -0
- package/dist/api/wrappers.d.ts +30 -8
- package/dist/api/wrappers.d.ts.map +1 -1
- package/dist/api/wrappers.js +148 -137
- package/dist/fs/wrappers.d.ts +4 -5
- package/dist/fs/wrappers.d.ts.map +1 -1
- package/dist/fs/wrappers.js +33 -65
- package/dist/utils/async.d.ts +1 -0
- package/dist/utils/async.d.ts.map +1 -1
- package/dist/utils/async.js +7 -1
- package/dist/utils/autohash.d.ts +17 -0
- package/dist/utils/autohash.d.ts.map +1 -0
- package/dist/utils/autohash.js +73 -0
- 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/observable.d.ts +1 -6
- package/dist/utils/observable.d.ts.map +1 -1
- package/dist/utils/observable.js +0 -50
- package/package.json +3 -4
- package/src/api/calls/read.ts +19 -0
- package/src/api/models/user.ts +31 -0
- package/src/api/wrappers.ts +172 -114
- package/src/fs/wrappers.ts +44 -39
- package/src/utils/async.ts +4 -0
- package/src/utils/index.ts +0 -1
- package/tsconfig.json +3 -1
- package/src/utils/observable.ts +0 -19
package/README.md
CHANGED
|
@@ -25,43 +25,40 @@ yarn add @autonomys/auto-drive
|
|
|
25
25
|
Here is an example of how to use the `uploadFileFromFilepath` method to upload a file with optional encryption and compression:
|
|
26
26
|
|
|
27
27
|
```typescript
|
|
28
|
-
import { uploadFileFromFilepath } from '@autonomys/auto-drive'
|
|
28
|
+
import { uploadFileFromFilepath,createAutoDriveApi } from '@autonomys/auto-drive'
|
|
29
29
|
|
|
30
30
|
const api = createAutoDriveApi({ apiKey: 'your-api-key' }) // Initialize your API instance with API key
|
|
31
31
|
const filePath = 'path/to/your/file.txt' // Specify the path to your file
|
|
32
32
|
const options = {
|
|
33
33
|
password: 'your-encryption-password', // Optional: specify a password for encryption
|
|
34
34
|
compression: true,
|
|
35
|
+
// an optional callback useful for large file uploads
|
|
36
|
+
onProgress?: (progress: number) => {
|
|
37
|
+
console.log(`The upload is completed is ${progress}% completed`)
|
|
38
|
+
}
|
|
35
39
|
}
|
|
36
40
|
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
})
|
|
41
|
-
.catch((error) => {
|
|
42
|
-
console.error('Error uploading file:', error)
|
|
43
|
-
})
|
|
41
|
+
const cid = await uploadFileFromFilepath(api, filePath, options)
|
|
42
|
+
|
|
43
|
+
console.log(`The file is uploaded and its cid is ${cid}`)
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
### How to upload [File](https://developer.mozilla.org/en-US/docs/Web/API/File) interface
|
|
47
47
|
|
|
48
48
|
```typescript
|
|
49
|
-
import {
|
|
49
|
+
import { uploadFileFromInput, createAutoDriveApi } from '@autonomys/auto-drive'
|
|
50
50
|
|
|
51
51
|
const api = createAutoDriveApi({ apiKey: 'your-api-key' }) // Initialize your API instance with API key
|
|
52
|
-
|
|
52
|
+
|
|
53
|
+
// e.g Get File from object from HTML event
|
|
54
|
+
const file: File = e.target.value // Substitute with your file
|
|
53
55
|
const options = {
|
|
54
56
|
password: 'your-encryption-password', // Optional: specify a password for encryption
|
|
55
57
|
compression: true,
|
|
56
58
|
}
|
|
59
|
+
const cid = await uploadFileFromInput(api, file, options)
|
|
57
60
|
|
|
58
|
-
|
|
59
|
-
.then(() => {
|
|
60
|
-
console.log('File uploaded successfully!')
|
|
61
|
-
})
|
|
62
|
-
.catch((error) => {
|
|
63
|
-
console.error('Error uploading file:', error)
|
|
64
|
-
})
|
|
61
|
+
console.log(`The file is uploaded and its cid is ${cid}`)
|
|
65
62
|
```
|
|
66
63
|
|
|
67
64
|
### How to upload a file from a custom interface?
|
|
@@ -83,7 +80,7 @@ For more info about asynn generator visit [this website](https://developer.mozil
|
|
|
83
80
|
You could upload any file that could be represented in that way. For example, uploading a file as a `Buffer`
|
|
84
81
|
|
|
85
82
|
```typescript
|
|
86
|
-
import { uploadFile } from '@autonomys/auto-drive'
|
|
83
|
+
import { createAutoDriveApi, uploadFile } from '@autonomys/auto-drive'
|
|
87
84
|
|
|
88
85
|
const api = createAutoDriveApi({ apiKey: 'your-api-key' }) // Initialize your API instance with API key
|
|
89
86
|
const buffer = Buffer.from(...);
|
|
@@ -100,21 +97,21 @@ const genericFile = {
|
|
|
100
97
|
const options = {
|
|
101
98
|
password: 'your-encryption-password', // Optional: specify a password for encryption
|
|
102
99
|
compression: true,
|
|
100
|
+
// an optional callback useful for large file uploads
|
|
101
|
+
onProgress?: (progress: number) => {
|
|
102
|
+
console.log(`The upload is completed is ${progress}% completed`)
|
|
103
|
+
}
|
|
103
104
|
}
|
|
104
105
|
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
})
|
|
109
|
-
.catch((error) => {
|
|
110
|
-
console.error('Error uploading file:', error)
|
|
111
|
-
})
|
|
106
|
+
const cid = uploadFile(api, genericFile, options)
|
|
107
|
+
|
|
108
|
+
console.log(`The file is uploaded and its cid is ${cid}`)
|
|
112
109
|
```
|
|
113
110
|
|
|
114
111
|
### How to upload a folder from folder? (Not available in browser)
|
|
115
112
|
|
|
116
113
|
```ts
|
|
117
|
-
import { uploadFolderFromFolderPath } from '@autonomys/auto-drive'
|
|
114
|
+
import { createAutoDriveApi, uploadFolderFromFolderPath } from '@autonomys/auto-drive'
|
|
118
115
|
|
|
119
116
|
const api = createAutoDriveApi({ apiKey: 'your-api-key' }) // Initialize your API instance with API key
|
|
120
117
|
const folderPath = 'path/to/your/folder' // Specify the path to your folder
|
|
@@ -122,74 +119,31 @@ const folderPath = 'path/to/your/folder' // Specify the path to your folder
|
|
|
122
119
|
const options = {
|
|
123
120
|
uploadChunkSize: 1024 * 1024, // Optional: specify the chunk size for uploads
|
|
124
121
|
password: 'your-encryption-password', // Optional: If folder is encrypted
|
|
122
|
+
// an optional callback useful for large file uploads
|
|
123
|
+
onProgress: (progress: number) => {
|
|
124
|
+
console.log(`The upload is completed is ${progress}% completed`)
|
|
125
|
+
},
|
|
125
126
|
}
|
|
126
127
|
|
|
127
|
-
const
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
**Note: If a folder is tried to be encrypted a zip file would be generated and that file would be encrypted and uploaded.**
|
|
131
|
-
|
|
132
|
-
### Handle observables
|
|
133
|
-
|
|
134
|
-
Since uploads may take some time, specially in big-sized files. Uploads do implement `rxjs` observables so you could have feedback about the process or even show your users the progress of the upload.
|
|
135
|
-
|
|
136
|
-
For that reason when file upload functions return `PromisedObservable<UploadFileStatus>`:
|
|
137
|
-
|
|
138
|
-
```typescript
|
|
139
|
-
export type UploadFileStatus = {
|
|
140
|
-
type: 'file'
|
|
141
|
-
progress: number
|
|
142
|
-
cid?: CID
|
|
143
|
-
}
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
Being the cid only returned (and thus optional) when the upload is completed.
|
|
147
|
-
|
|
148
|
-
Similarly, for folder uploads the functions return `PromisedObservable<UploadFolderStatus>`
|
|
149
|
-
|
|
150
|
-
```ts
|
|
151
|
-
export type UploadFolderStatus = {
|
|
152
|
-
type: 'folder'
|
|
153
|
-
progress: number
|
|
154
|
-
cid?: CID
|
|
155
|
-
}
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
**e.g Show upload progress in React**
|
|
159
|
-
|
|
160
|
-
```typescript
|
|
161
|
-
const [progress, setProgress] = useState<number>(0)
|
|
128
|
+
const folderCID = await uploadFolderFromFolderPath(api, folderPath, options)
|
|
162
129
|
|
|
163
|
-
|
|
164
|
-
const finalStatus = await uploadFileFromInput(api, genericFile, options).forEach((status) => {
|
|
165
|
-
setProgress(status.progress)
|
|
166
|
-
})
|
|
167
|
-
})
|
|
130
|
+
console.log(`The folder is uploaded and its cid is ${folderCID}`)
|
|
168
131
|
```
|
|
169
132
|
|
|
170
|
-
**
|
|
171
|
-
|
|
172
|
-
Other users may want to not use the progress observability. For having a promise instead the field `promise` is a Promise that resolves into `UploadFileStatus` and `UploadFolderStatus` for files and folders respectively.
|
|
173
|
-
|
|
174
|
-
e.g
|
|
175
|
-
|
|
176
|
-
```ts
|
|
177
|
-
const status = await uploadFileFromInput(api, genericFile, options).promise
|
|
178
|
-
const cid = status.cid
|
|
179
|
-
```
|
|
133
|
+
**Note: If a folder is tried to be encrypted a zip file would be generated and that file would be encrypted and uploaded.**
|
|
180
134
|
|
|
181
135
|
### Example Usage of Download
|
|
182
136
|
|
|
183
137
|
Here is an example of how to use the `downloadFile` method to download a file from the server:
|
|
184
138
|
|
|
185
139
|
```typescript
|
|
186
|
-
import {
|
|
140
|
+
import { createAutoDriveApi, downloadFile } from '@autonomys/auto-drive'
|
|
187
141
|
|
|
188
142
|
const api = createAutoDriveApi({ apiKey: 'your-api-key' }) // Initialize your API instance with API key
|
|
189
143
|
|
|
190
144
|
try {
|
|
191
145
|
const cid = '..'
|
|
192
|
-
const stream = await
|
|
146
|
+
const stream = await downloadFile(api, cid)
|
|
193
147
|
let file = Buffer.alloc(0)
|
|
194
148
|
for await (const chunk of stream) {
|
|
195
149
|
file = Buffer.concat([file, chunk])
|
|
@@ -205,16 +159,20 @@ try {
|
|
|
205
159
|
Here is an example of how to use the `getRoots` method to retrieve the root directories:
|
|
206
160
|
|
|
207
161
|
```typescript
|
|
208
|
-
import { createAutoDriveApi,
|
|
209
|
-
import fs from 'fs'
|
|
162
|
+
import { createAutoDriveApi, apiCalls, Scope } from '@autonomys/auto-drive'
|
|
210
163
|
|
|
211
164
|
const api = createAutoDriveApi({ apiKey: 'your-api-key' }) // Initialize your API instance with API key
|
|
212
165
|
|
|
213
166
|
try {
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
167
|
+
const myFiles = await apiCalls.getRoots(api, {
|
|
168
|
+
scope: Scope.User,
|
|
169
|
+
limit: 100,
|
|
170
|
+
offset: 0,
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
console.log(`Retrieved ${myFiles.rows.length} files of ${myFiles.totalCount} total`)
|
|
174
|
+
for (const file of myFiles.rows) {
|
|
175
|
+
console.log(`${file.name} - ${file.headCid}: ${file.size}`)
|
|
218
176
|
}
|
|
219
177
|
} catch (error) {
|
|
220
178
|
console.error('Error downloading file:', error)
|
|
@@ -50,6 +50,7 @@ export declare const apiCalls: {
|
|
|
50
50
|
getObjectMetadata: (api: import("..").AutoDriveApi, query: import("../../utils").ArgsWithoutPagination<{
|
|
51
51
|
cid: string;
|
|
52
52
|
}>) => Promise<import("..").ObjectInformation["metadata"]>;
|
|
53
|
+
getMe: (api: import("..").AutoDriveApi) => Promise<import("../models/user").UserInfo>;
|
|
53
54
|
downloadObject: (api: import("..").AutoDriveApi, query: import("../../utils").ArgsWithoutPagination<{
|
|
54
55
|
cid: string;
|
|
55
56
|
}>) => Promise<ReadableStream<Uint8Array>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/calls/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,QAAQ;;;;;;;;;;;;gBAMg0B,CAAC;;;;;;qBAAgvC,CAAC;;;;;gBAAkiD,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/calls/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,QAAQ;;;;;;;;;;;;gBAMg0B,CAAC;;;;;;qBAAgvC,CAAC;;;;;gBAAkiD,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CADzmH,CAAA"}
|
package/dist/api/calls/read.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { ArgsWithoutPagination, ArgsWithPagination } from '../../utils/types';
|
|
|
2
2
|
import { AutoDriveApi } from '../connection';
|
|
3
3
|
import { PaginatedResult } from '../models/common';
|
|
4
4
|
import { ObjectInformation, ObjectSummary, Scope } from '../models/objects';
|
|
5
|
+
import { UserInfo } from '../models/user';
|
|
5
6
|
/**
|
|
6
7
|
* Retrieves the root objects based on the specified scope.
|
|
7
8
|
*
|
|
@@ -96,4 +97,12 @@ export declare const getObjectOwners: (api: AutoDriveApi, query: ArgsWithoutPagi
|
|
|
96
97
|
export declare const getObjectMetadata: (api: AutoDriveApi, query: ArgsWithoutPagination<{
|
|
97
98
|
cid: string;
|
|
98
99
|
}>) => Promise<ObjectInformation["metadata"]>;
|
|
100
|
+
/**
|
|
101
|
+
* Get upload and download limits of the user
|
|
102
|
+
*
|
|
103
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
104
|
+
* @returns {Promise<UserInfo>} - A promise that resolves to the user info.
|
|
105
|
+
* @throws {Error} - Throws an error if the request fails.
|
|
106
|
+
*/
|
|
107
|
+
export declare const getMe: (api: AutoDriveApi) => Promise<UserInfo>;
|
|
99
108
|
//# sourceMappingURL=read.d.ts.map
|
|
@@ -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,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;
|
|
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,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAC3E,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEzC;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,QACd,YAAY,SACV,kBAAkB,CAAC;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC,KAC1C,OAAO,CAAC,eAAe,CAAC,aAAa,CAAC,CAaxC,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,QACrB,YAAY,SACV,kBAAkB,KACxB,OAAO,CAAC,eAAe,CAAC,aAAa,CAAC,CAaxC,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,QAChB,YAAY,SACV,kBAAkB,KACxB,OAAO,CAAC,eAAe,CAAC,aAAa,CAAC,CAaxC,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,QACf,YAAY,SACV,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,KAC5C,OAAO,CAAC,iBAAiB,CAU3B,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,qBAAqB,QAC3B,YAAY,SACV,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,KAC5C,OAAO,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAU3C,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe,QACrB,YAAY,SACV,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,KAC5C,OAAO,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAUrC,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iBAAiB,QACvB,YAAY,SACV,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,KAC5C,OAAO,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAUvC,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,QAAe,YAAY,KAAG,OAAO,CAAC,QAAQ,CAS/D,CAAA"}
|
package/dist/api/calls/read.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getObjectMetadata = exports.getObjectOwners = exports.getObjectUploadStatus = exports.getObject = exports.getDeleted = exports.getSharedWithMe = exports.getRoots = void 0;
|
|
12
|
+
exports.getMe = exports.getObjectMetadata = exports.getObjectOwners = exports.getObjectUploadStatus = exports.getObject = exports.getDeleted = exports.getSharedWithMe = exports.getRoots = void 0;
|
|
13
13
|
/**
|
|
14
14
|
* Retrieves the root objects based on the specified scope.
|
|
15
15
|
*
|
|
@@ -157,3 +157,20 @@ const getObjectMetadata = (api, query) => __awaiter(void 0, void 0, void 0, func
|
|
|
157
157
|
return response.json();
|
|
158
158
|
});
|
|
159
159
|
exports.getObjectMetadata = getObjectMetadata;
|
|
160
|
+
/**
|
|
161
|
+
* Get upload and download limits of the user
|
|
162
|
+
*
|
|
163
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
164
|
+
* @returns {Promise<UserInfo>} - A promise that resolves to the user info.
|
|
165
|
+
* @throws {Error} - Throws an error if the request fails.
|
|
166
|
+
*/
|
|
167
|
+
const getMe = (api) => __awaiter(void 0, void 0, void 0, function* () {
|
|
168
|
+
const response = yield api.sendRequest('@me', {
|
|
169
|
+
method: 'GET',
|
|
170
|
+
});
|
|
171
|
+
if (!response.ok) {
|
|
172
|
+
throw new Error(`Failed to get limits: ${response.statusText}`);
|
|
173
|
+
}
|
|
174
|
+
return response.json();
|
|
175
|
+
});
|
|
176
|
+
exports.getMe = getMe;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type SubscriptionGranularity = 'monthly';
|
|
2
|
+
export type SubscriptionInfo = {
|
|
3
|
+
id: string;
|
|
4
|
+
organizationId: string;
|
|
5
|
+
uploadLimit: number;
|
|
6
|
+
downloadLimit: number;
|
|
7
|
+
granularity: SubscriptionGranularity;
|
|
8
|
+
pendingUploadCredits: number;
|
|
9
|
+
pendingDownloadCredits: number;
|
|
10
|
+
};
|
|
11
|
+
export declare enum UserRole {
|
|
12
|
+
User = "User",
|
|
13
|
+
Admin = "Admin"
|
|
14
|
+
}
|
|
15
|
+
export type User = {
|
|
16
|
+
oauthProvider: string;
|
|
17
|
+
oauthUserId: string;
|
|
18
|
+
role: UserRole;
|
|
19
|
+
downloadCredits: number;
|
|
20
|
+
uploadCredits: number;
|
|
21
|
+
publicId: string;
|
|
22
|
+
onboarded: true;
|
|
23
|
+
};
|
|
24
|
+
export type UserInfo = {
|
|
25
|
+
user: User;
|
|
26
|
+
subscription: SubscriptionInfo;
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=user.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../../src/api/models/user.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,uBAAuB,GAAG,SAAS,CAAA;AAE/C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,EAAE,EAAE,MAAM,CAAA;IACV,cAAc,EAAE,MAAM,CAAA;IACtB,WAAW,EAAE,MAAM,CAAA;IACnB,aAAa,EAAE,MAAM,CAAA;IACrB,WAAW,EAAE,uBAAuB,CAAA;IACpC,oBAAoB,EAAE,MAAM,CAAA;IAC5B,sBAAsB,EAAE,MAAM,CAAA;CAC/B,CAAA;AAED,oBAAY,QAAQ;IAClB,IAAI,SAAS;IACb,KAAK,UAAU;CAChB;AAED,MAAM,MAAM,IAAI,GAAG;IACjB,aAAa,EAAE,MAAM,CAAA;IACrB,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,QAAQ,CAAA;IACd,eAAe,EAAE,MAAM,CAAA;IACvB,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,IAAI,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,IAAI,CAAA;IACV,YAAY,EAAE,gBAAgB,CAAA;CAC/B,CAAA"}
|
package/dist/api/wrappers.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { PromisedObservable } from '../utils/observable';
|
|
2
1
|
import { AutoDriveApi } from './connection';
|
|
3
2
|
import { GenericFile, GenericFileWithinFolder } from './models/file';
|
|
4
|
-
import {
|
|
3
|
+
import { SubscriptionInfo } from './models/user';
|
|
5
4
|
export type UploadFileOptions = {
|
|
6
5
|
password?: string;
|
|
7
6
|
compression?: boolean;
|
|
7
|
+
onProgress?: (progress: number) => void;
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
10
10
|
* Uploads a file to the server with optional encryption and compression.
|
|
@@ -23,7 +23,7 @@ export type UploadFileOptions = {
|
|
|
23
23
|
* @returns {PromisedObservable<UploadFileStatus>} - An observable that emits the upload status.
|
|
24
24
|
* @throws {Error} - Throws an error if the upload fails at any stage.
|
|
25
25
|
*/
|
|
26
|
-
export declare const uploadFileFromInput: (api: AutoDriveApi, file: File, options?: UploadFileOptions, uploadChunkSize?: number) =>
|
|
26
|
+
export declare const uploadFileFromInput: (api: AutoDriveApi, file: File, options?: UploadFileOptions, uploadChunkSize?: number) => Promise<string>;
|
|
27
27
|
/**
|
|
28
28
|
* Uploads a file to the server with optional encryption and compression.
|
|
29
29
|
*
|
|
@@ -38,10 +38,26 @@ export declare const uploadFileFromInput: (api: AutoDriveApi, file: File, option
|
|
|
38
38
|
* @param {string} [options.password] - The password for encryption (optional).
|
|
39
39
|
* @param {boolean} [options.compression=true] - Whether to compress the file (optional).
|
|
40
40
|
* @param {number} [uploadChunkSize] - The size of each chunk to upload (optional).
|
|
41
|
-
* @returns {
|
|
41
|
+
* @returns {Promise<string>} - The CID of the uploaded file.
|
|
42
|
+
* @throws {Error} - Throws an error if the upload fails at any stage.
|
|
43
|
+
*/
|
|
44
|
+
export declare const uploadFile: (api: AutoDriveApi, file: GenericFile, options?: UploadFileOptions, uploadChunkSize?: number) => Promise<string>;
|
|
45
|
+
/**
|
|
46
|
+
* Uploads an object as a JSON file to the server.
|
|
47
|
+
*
|
|
48
|
+
* This function serializes the provided object to a JSON string,
|
|
49
|
+
* and then uploads the JSON string as a file to the server.
|
|
50
|
+
*
|
|
51
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
52
|
+
* @param {File | GenericFile} file - The file to be uploaded, which can be a File or a GenericFile.
|
|
53
|
+
* @param {UploadFileOptions} options - Options for the upload process.
|
|
54
|
+
* @param {string} [options.password] - The password for encryption (optional).
|
|
55
|
+
* @param {boolean} [options.compression=true] - Whether to compress the file (optional).
|
|
56
|
+
* @param {number} [uploadChunkSize] - The size of each chunk to upload (optional).
|
|
57
|
+
* @returns {Promise<string>} - The CID of the uploaded file.
|
|
42
58
|
* @throws {Error} - Throws an error if the upload fails at any stage.
|
|
43
59
|
*/
|
|
44
|
-
export declare const
|
|
60
|
+
export declare const uploadObjectAsJSON: (api: AutoDriveApi, object: unknown, name?: string | undefined, options?: UploadFileOptions, uploadChunkSize?: number) => Promise<string>;
|
|
45
61
|
/**
|
|
46
62
|
* Uploads an entire folder to the server.
|
|
47
63
|
*
|
|
@@ -59,10 +75,11 @@ export declare const uploadFile: (api: AutoDriveApi, file: GenericFile, options?
|
|
|
59
75
|
* @returns {PromisedObservable<UploadFileStatus | UploadFolderStatus>} - An observable that emits the upload status.
|
|
60
76
|
* @throws {Error} - Throws an error if the upload fails at any stage.
|
|
61
77
|
*/
|
|
62
|
-
export declare const uploadFolderFromInput: (api: AutoDriveApi, fileList: FileList | File[], { uploadChunkSize, password }?: {
|
|
78
|
+
export declare const uploadFolderFromInput: (api: AutoDriveApi, fileList: FileList | File[], { uploadChunkSize, password, onProgress, }?: {
|
|
63
79
|
uploadChunkSize?: number;
|
|
64
80
|
password?: string;
|
|
65
|
-
|
|
81
|
+
onProgress?: (progress: number) => void;
|
|
82
|
+
}) => Promise<string>;
|
|
66
83
|
/**
|
|
67
84
|
* Uploads a file within an existing folder upload session.
|
|
68
85
|
*
|
|
@@ -72,7 +89,7 @@ export declare const uploadFolderFromInput: (api: AutoDriveApi, fileList: FileLi
|
|
|
72
89
|
*
|
|
73
90
|
* @returns {Promise<void>} A promise that resolves when the file upload is complete.
|
|
74
91
|
*/
|
|
75
|
-
export declare const uploadFileWithinFolderUpload: (api: AutoDriveApi, uploadId: string, file: GenericFileWithinFolder, uploadChunkSize?: number) =>
|
|
92
|
+
export declare const uploadFileWithinFolderUpload: (api: AutoDriveApi, uploadId: string, file: GenericFileWithinFolder, uploadChunkSize?: number, options?: Pick<UploadFileOptions, "onProgress">) => Promise<string>;
|
|
76
93
|
/**
|
|
77
94
|
* Downloads a file from the AutoDrive service.
|
|
78
95
|
*
|
|
@@ -81,4 +98,9 @@ export declare const uploadFileWithinFolderUpload: (api: AutoDriveApi, uploadId:
|
|
|
81
98
|
* @returns {Promise<ReadableStream<Uint8Array>>} A promise that resolves to a ReadableStream of the downloaded file.
|
|
82
99
|
*/
|
|
83
100
|
export declare const downloadFile: (api: AutoDriveApi, cid: string, password?: string) => Promise<AsyncIterable<Buffer>>;
|
|
101
|
+
export declare const getPendingCredits: (api: AutoDriveApi) => Promise<{
|
|
102
|
+
upload: number;
|
|
103
|
+
download: number;
|
|
104
|
+
}>;
|
|
105
|
+
export declare const getSubscriptionInfo: (api: AutoDriveApi) => Promise<SubscriptionInfo>;
|
|
84
106
|
//# sourceMappingURL=wrappers.d.ts.map
|
|
@@ -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":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AAEpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAEhD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;CACxC,CAAA;AA6BD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,mBAAmB,QACzB,YAAY,QACX,IAAI,YACD,iBAAiB,oBACR,MAAM,KACvB,OAAO,CAAC,MAAM,CAgDhB,CAAA;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,UAAU,QAChB,YAAY,QACX,WAAW,YACR,iBAAiB,oBACR,MAAM,KACvB,OAAO,CAAC,MAAM,CA+ChB,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,kBAAkB,QACxB,YAAY,UACT,OAAO,SACR,MAAM,GAAG,SAAS,YAChB,iBAAiB,oBACR,MAAM,KACvB,OAAO,CAAC,MAAM,CAiBhB,CAAA;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,qBAAqB,QAC3B,YAAY,YACP,QAAQ,GAAG,IAAI,EAAE,+CAKxB;IAAE,eAAe,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,KAC1F,OAAO,CAAC,MAAM,CA2DhB,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,4BAA4B,QAClC,YAAY,YACP,MAAM,QACV,uBAAuB,oBACX,MAAM,YACf,IAAI,CAAC,iBAAiB,EAAE,YAAY,CAAC,KAC7C,OAAO,CAAC,MAAM,CAchB,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,QAClB,YAAY,OACZ,MAAM,aACA,MAAM,KAChB,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAwB/B,CAAA;AAED,eAAO,MAAM,iBAAiB,QACvB,YAAY,KAChB,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAM9C,CAAA;AAED,eAAO,MAAM,mBAAmB,QAAe,YAAY,KAAG,OAAO,CAAC,gBAAgB,CAIrF,CAAA"}
|