@autonomys/auto-drive 1.2.4 → 1.2.6
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 +21 -0
- package/dist/api/calls/download.d.ts +1 -0
- package/dist/api/calls/download.d.ts.map +1 -1
- package/dist/api/calls/download.js +5 -1
- package/dist/api/calls/index.d.ts +6 -0
- package/dist/api/calls/index.d.ts.map +1 -1
- package/dist/api/calls/write.d.ts +17 -0
- package/dist/api/calls/write.d.ts.map +1 -1
- package/dist/api/calls/write.js +23 -1
- package/dist/api/connection.d.ts +1 -0
- package/dist/api/connection.d.ts.map +1 -1
- package/dist/api/connection.js +4 -0
- package/dist/api/wrappers.d.ts +10 -0
- package/dist/api/wrappers.d.ts.map +1 -1
- package/dist/api/wrappers.js +16 -1
- package/package.json +3 -3
- package/src/api/calls/download.ts +4 -0
- package/src/api/calls/write.ts +29 -2
- package/src/api/connection.ts +5 -0
- package/src/api/wrappers.ts +16 -0
- 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/.env
ADDED
package/README.md
CHANGED
|
@@ -166,6 +166,27 @@ try {
|
|
|
166
166
|
}
|
|
167
167
|
```
|
|
168
168
|
|
|
169
|
+
### Create shareable download link
|
|
170
|
+
|
|
171
|
+
Here is an example of how to use the `publishObject` method to publish an object and get its public download URL:
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
import { createAutoDriveApi, publishObject } from '@autonomys/auto-drive'
|
|
175
|
+
import { NetworkId } from '@autonomys/auto-utils'
|
|
176
|
+
|
|
177
|
+
const api = createAutoDriveApi({ apiKey: 'your-api-key', network: NetworkId.TAURUS }) // Initialize your API instance with API key
|
|
178
|
+
|
|
179
|
+
try {
|
|
180
|
+
const cid = 'your-file-cid'
|
|
181
|
+
const publicUrl = await publishObject(api, cid)
|
|
182
|
+
console.log('Public download URL:', publicUrl)
|
|
183
|
+
} catch (error) {
|
|
184
|
+
console.error('Error publishing object:', error)
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
**Note: For retrieving the link of an already published object just call again `publishObject` method**
|
|
189
|
+
|
|
169
190
|
### Example Usage of getRoots
|
|
170
191
|
|
|
171
192
|
Here is an example of how to use the `getRoots` method to retrieve the root directories:
|
|
@@ -3,4 +3,5 @@ import { AutoDriveApi } from '../connection';
|
|
|
3
3
|
export declare const downloadObject: (api: AutoDriveApi, query: ArgsWithoutPagination<{
|
|
4
4
|
cid: string;
|
|
5
5
|
}>) => Promise<ReadableStream<Uint8Array>>;
|
|
6
|
+
export declare const publicDownloadUrl: (api: AutoDriveApi, cid: string) => string;
|
|
6
7
|
//# sourceMappingURL=download.d.ts.map
|
|
@@ -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,YAAY,EAAE,MAAM,eAAe,CAAA;AAE5C,eAAO,MAAM,cAAc,QACpB,YAAY,SACV,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,KAC5C,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAcpC,CAAA"}
|
|
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,YAAY,EAAE,MAAM,eAAe,CAAA;AAE5C,eAAO,MAAM,cAAc,QACpB,YAAY,SACV,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,KAC5C,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAcpC,CAAA;AAED,eAAO,MAAM,iBAAiB,QAAS,YAAY,OAAO,MAAM,KAAG,MAElE,CAAA"}
|
|
@@ -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.downloadObject = void 0;
|
|
12
|
+
exports.publicDownloadUrl = exports.downloadObject = void 0;
|
|
13
13
|
const downloadObject = (api, query) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
14
|
const response = yield api.sendRequest(`/objects/${query.cid}/download`, {
|
|
15
15
|
method: 'GET',
|
|
@@ -23,3 +23,7 @@ const downloadObject = (api, query) => __awaiter(void 0, void 0, void 0, functio
|
|
|
23
23
|
return response.body;
|
|
24
24
|
});
|
|
25
25
|
exports.downloadObject = downloadObject;
|
|
26
|
+
const publicDownloadUrl = (api, cid) => {
|
|
27
|
+
return `${api.baseUrl}/objects/${cid}/public`;
|
|
28
|
+
};
|
|
29
|
+
exports.publicDownloadUrl = publicDownloadUrl;
|
|
@@ -9,6 +9,11 @@ export declare const apiCalls: {
|
|
|
9
9
|
restoreObject: (api: import("..").AutoDriveApi, query: import("../../utils").ArgsWithoutPagination<{
|
|
10
10
|
cid: string;
|
|
11
11
|
}>) => Promise<void>;
|
|
12
|
+
publishObject: (api: import("..").AutoDriveApi, query: import("../../utils").ArgsWithoutPagination<{
|
|
13
|
+
cid: string;
|
|
14
|
+
}>) => Promise<{
|
|
15
|
+
result: string;
|
|
16
|
+
}>;
|
|
12
17
|
createFileUpload: (api: import("..").AutoDriveApi, { mimeType, filename, uploadOptions, }: import("../../utils").ArgsWithoutPagination<{
|
|
13
18
|
mimeType?: string;
|
|
14
19
|
filename: string;
|
|
@@ -54,5 +59,6 @@ export declare const apiCalls: {
|
|
|
54
59
|
downloadObject: (api: import("..").AutoDriveApi, query: import("../../utils").ArgsWithoutPagination<{
|
|
55
60
|
cid: string;
|
|
56
61
|
}>) => Promise<ReadableStream<Uint8Array>>;
|
|
62
|
+
publicDownloadUrl: (api: import("..").AutoDriveApi, cid: string) => string;
|
|
57
63
|
};
|
|
58
64
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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;;;;;;;;;;;;;;;;;gBAMg0B,CAAC;;;;;;qBAAgvC,CAAC;;;;;gBAAkiD,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CADzmH,CAAA"}
|
|
@@ -46,4 +46,21 @@ export declare const markObjectAsDeleted: (api: AutoDriveApi, query: ArgsWithout
|
|
|
46
46
|
export declare const restoreObject: (api: AutoDriveApi, query: ArgsWithoutPagination<{
|
|
47
47
|
cid: string;
|
|
48
48
|
}>) => Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Publishes an object by sending a request to the server.
|
|
51
|
+
*
|
|
52
|
+
* This function sends a request to the server to publish an object identified
|
|
53
|
+
* by its CID. The publication process may depend on the server's implementation
|
|
54
|
+
* and the object's current state.
|
|
55
|
+
*
|
|
56
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
57
|
+
* @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object to publish.
|
|
58
|
+
* @returns {Promise<void>} - A promise that resolves when the object has been successfully published.
|
|
59
|
+
* @throws {Error} - Throws an error if the publication process fails.
|
|
60
|
+
*/
|
|
61
|
+
export declare const publishObject: (api: AutoDriveApi, query: ArgsWithoutPagination<{
|
|
62
|
+
cid: string;
|
|
63
|
+
}>) => Promise<{
|
|
64
|
+
result: string;
|
|
65
|
+
}>;
|
|
49
66
|
//# sourceMappingURL=write.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/api/calls/write.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/api/calls/write.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,WAAW,QACjB,YAAY,SACV,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,iBAkBhE,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,QACzB,YAAY,SACV,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,KAC5C,OAAO,CAAC,IAAI,CAQd,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,QACnB,YAAY,SACV,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,KAC5C,OAAO,CAAC,IAAI,CAUd,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,QACnB,YAAY,SACV,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,KAC5C,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAU5B,CAAA"}
|
package/dist/api/calls/write.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.restoreObject = exports.markObjectAsDeleted = exports.shareObject = void 0;
|
|
12
|
+
exports.publishObject = exports.restoreObject = exports.markObjectAsDeleted = exports.shareObject = void 0;
|
|
13
13
|
/**
|
|
14
14
|
* Shares an object with a specified public ID.
|
|
15
15
|
*
|
|
@@ -78,3 +78,25 @@ const restoreObject = (api, query) => __awaiter(void 0, void 0, void 0, function
|
|
|
78
78
|
return response.json();
|
|
79
79
|
});
|
|
80
80
|
exports.restoreObject = restoreObject;
|
|
81
|
+
/**
|
|
82
|
+
* Publishes an object by sending a request to the server.
|
|
83
|
+
*
|
|
84
|
+
* This function sends a request to the server to publish an object identified
|
|
85
|
+
* by its CID. The publication process may depend on the server's implementation
|
|
86
|
+
* and the object's current state.
|
|
87
|
+
*
|
|
88
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
89
|
+
* @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object to publish.
|
|
90
|
+
* @returns {Promise<void>} - A promise that resolves when the object has been successfully published.
|
|
91
|
+
* @throws {Error} - Throws an error if the publication process fails.
|
|
92
|
+
*/
|
|
93
|
+
const publishObject = (api, query) => __awaiter(void 0, void 0, void 0, function* () {
|
|
94
|
+
const response = yield api.sendRequest(`/objects/${query.cid}/publish`, {
|
|
95
|
+
method: 'POST',
|
|
96
|
+
});
|
|
97
|
+
if (!response.ok) {
|
|
98
|
+
throw new Error(`Failed to publish object: ${response.statusText}`);
|
|
99
|
+
}
|
|
100
|
+
return response.json();
|
|
101
|
+
});
|
|
102
|
+
exports.publishObject = publishObject;
|
package/dist/api/connection.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/api/connection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAA2B,MAAM,YAAY,CAAA;AAEtE,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE,CACX,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,EACzB,IAAI,CAAC,EAAE,QAAQ,KACZ,OAAO,CAAC,QAAQ,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/api/connection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAA2B,MAAM,YAAY,CAAA;AAEtE,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE,CACX,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,EACzB,IAAI,CAAC,EAAE,QAAQ,KACZ,OAAO,CAAC,QAAQ,CAAC,CAAA;IACtB,OAAO,EAAE,MAAM,CAAA;CAChB;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,KAAK,iBAAiB,GAClB;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;AAEL,eAAO,MAAM,kBAAkB,wCAK5B,iBAAiB,KAAG,YAuBtB,CAAA"}
|
package/dist/api/connection.js
CHANGED
|
@@ -18,6 +18,9 @@ var OAuthProvider;
|
|
|
18
18
|
})(OAuthProvider || (exports.OAuthProvider = OAuthProvider = {}));
|
|
19
19
|
const createAutoDriveApi = ({ provider = 'apikey', apiKey, url = null, network, }) => {
|
|
20
20
|
const baseUrl = !network ? url : (0, networks_1.getNetworkUrl)(network);
|
|
21
|
+
if (!baseUrl) {
|
|
22
|
+
throw new Error('No base URL provided');
|
|
23
|
+
}
|
|
21
24
|
return {
|
|
22
25
|
sendRequest: (relativeUrl, request, body) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
26
|
var _a;
|
|
@@ -25,6 +28,7 @@ const createAutoDriveApi = ({ provider = 'apikey', apiKey, url = null, network,
|
|
|
25
28
|
const fullRequest = Object.assign(Object.assign({}, request), { headers: new Headers(headers), body });
|
|
26
29
|
return fetch(`${baseUrl}${relativeUrl}`, fullRequest);
|
|
27
30
|
}),
|
|
31
|
+
baseUrl,
|
|
28
32
|
};
|
|
29
33
|
};
|
|
30
34
|
exports.createAutoDriveApi = createAutoDriveApi;
|
package/dist/api/wrappers.d.ts
CHANGED
|
@@ -103,4 +103,14 @@ export declare const getPendingCredits: (api: AutoDriveApi) => Promise<{
|
|
|
103
103
|
download: number;
|
|
104
104
|
}>;
|
|
105
105
|
export declare const getSubscriptionInfo: (api: AutoDriveApi) => Promise<SubscriptionInfo>;
|
|
106
|
+
/**
|
|
107
|
+
* Publishes an object by sending a request to the server.
|
|
108
|
+
*
|
|
109
|
+
* If already published, it will return the same public download URL.
|
|
110
|
+
*
|
|
111
|
+
* @param api {AutoDriveApi} - The API instance used to send requests.
|
|
112
|
+
* @param cid {string} - The CID of the object to publish.
|
|
113
|
+
* @returns {Promise<string>} - The public download URL of the published object.
|
|
114
|
+
*/
|
|
115
|
+
export declare const publishObject: (api: AutoDriveApi, cid: string) => Promise<string>;
|
|
106
116
|
//# 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":"AAKA,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;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,QAAe,YAAY,OAAO,MAAM,KAAG,OAAO,CAAC,MAAM,CAIlF,CAAA"}
|
package/dist/api/wrappers.js
CHANGED
|
@@ -19,10 +19,11 @@ 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.getSubscriptionInfo = exports.getPendingCredits = exports.downloadFile = exports.uploadFileWithinFolderUpload = exports.uploadFolderFromInput = exports.uploadObjectAsJSON = exports.uploadFile = exports.uploadFileFromInput = void 0;
|
|
22
|
+
exports.publishObject = exports.getSubscriptionInfo = exports.getPendingCredits = exports.downloadFile = exports.uploadFileWithinFolderUpload = exports.uploadFolderFromInput = exports.uploadObjectAsJSON = exports.uploadFile = exports.uploadFileFromInput = 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
|
+
const download_1 = require("./calls/download");
|
|
26
27
|
const index_1 = require("./calls/index");
|
|
27
28
|
const folderTree_1 = require("./models/folderTree");
|
|
28
29
|
const UPLOAD_FILE_CHUNK_SIZE = 1024 * 1024;
|
|
@@ -328,3 +329,17 @@ const getSubscriptionInfo = (api) => __awaiter(void 0, void 0, void 0, function*
|
|
|
328
329
|
return me.subscription;
|
|
329
330
|
});
|
|
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;
|
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.2.
|
|
4
|
+
"version": "1.2.6",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"typescript": "^5.6.3"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@autonomys/auto-dag-data": "^1.2.
|
|
45
|
+
"@autonomys/auto-dag-data": "^1.2.6",
|
|
46
46
|
"jszip": "^3.10.1",
|
|
47
47
|
"mime-types": "^2.1.35",
|
|
48
48
|
"process": "^0.11.10",
|
|
49
49
|
"stream": "^0.0.3",
|
|
50
50
|
"zod": "^3.23.8"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "17765b54234458fc359868f323c2dd6ca6ae324b"
|
|
53
53
|
}
|
package/src/api/calls/write.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ArgsWithoutPagination } from '../../utils/types'
|
|
2
|
-
import { AutoDriveApi } from '../connection'
|
|
1
|
+
import { ArgsWithoutPagination } from '../../utils/types';
|
|
2
|
+
import { AutoDriveApi } from '../connection';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Shares an object with a specified public ID.
|
|
@@ -86,3 +86,30 @@ export const restoreObject = async (
|
|
|
86
86
|
|
|
87
87
|
return response.json()
|
|
88
88
|
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Publishes an object by sending a request to the server.
|
|
92
|
+
*
|
|
93
|
+
* This function sends a request to the server to publish an object identified
|
|
94
|
+
* by its CID. The publication process may depend on the server's implementation
|
|
95
|
+
* and the object's current state.
|
|
96
|
+
*
|
|
97
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
98
|
+
* @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object to publish.
|
|
99
|
+
* @returns {Promise<void>} - A promise that resolves when the object has been successfully published.
|
|
100
|
+
* @throws {Error} - Throws an error if the publication process fails.
|
|
101
|
+
*/
|
|
102
|
+
export const publishObject = async (
|
|
103
|
+
api: AutoDriveApi,
|
|
104
|
+
query: ArgsWithoutPagination<{ cid: string }>,
|
|
105
|
+
): Promise<{ result: string }> => {
|
|
106
|
+
const response = await api.sendRequest(`/objects/${query.cid}/publish`, {
|
|
107
|
+
method: 'POST',
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
if (!response.ok) {
|
|
111
|
+
throw new Error(`Failed to publish object: ${response.statusText}`)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return response.json()
|
|
115
|
+
}
|
package/src/api/connection.ts
CHANGED
|
@@ -7,6 +7,7 @@ export interface AutoDriveApi {
|
|
|
7
7
|
request: Partial<Request>,
|
|
8
8
|
body?: BodyInit,
|
|
9
9
|
) => Promise<Response>
|
|
10
|
+
baseUrl: string
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export enum OAuthProvider {
|
|
@@ -38,6 +39,9 @@ export const createAutoDriveApi = ({
|
|
|
38
39
|
network,
|
|
39
40
|
}: ConnectionOptions): AutoDriveApi => {
|
|
40
41
|
const baseUrl = !network ? url : getNetworkUrl(network)
|
|
42
|
+
if (!baseUrl) {
|
|
43
|
+
throw new Error('No base URL provided')
|
|
44
|
+
}
|
|
41
45
|
|
|
42
46
|
return {
|
|
43
47
|
sendRequest: async (relativeUrl: string, request: Partial<Request>, body?: BodyInit) => {
|
|
@@ -54,5 +58,6 @@ export const createAutoDriveApi = ({
|
|
|
54
58
|
|
|
55
59
|
return fetch(`${baseUrl}${relativeUrl}`, fullRequest)
|
|
56
60
|
},
|
|
61
|
+
baseUrl,
|
|
57
62
|
}
|
|
58
63
|
}
|
package/src/api/wrappers.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import mime from 'mime-types'
|
|
2
2
|
import { asyncByChunk, asyncFromStream, bufferToIterable, fileToIterable } from '../utils/async'
|
|
3
3
|
import { progressToPercentage } from '../utils/misc'
|
|
4
|
+
import { publicDownloadUrl } from './calls/download'
|
|
4
5
|
import { apiCalls } from './calls/index'
|
|
5
6
|
import { AutoDriveApi } from './connection'
|
|
6
7
|
import { GenericFile, GenericFileWithinFolder } from './models/file'
|
|
@@ -392,3 +393,18 @@ export const getSubscriptionInfo = async (api: AutoDriveApi): Promise<Subscripti
|
|
|
392
393
|
|
|
393
394
|
return me.subscription
|
|
394
395
|
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Publishes an object by sending a request to the server.
|
|
399
|
+
*
|
|
400
|
+
* If already published, it will return the same public download URL.
|
|
401
|
+
*
|
|
402
|
+
* @param api {AutoDriveApi} - The API instance used to send requests.
|
|
403
|
+
* @param cid {string} - The CID of the object to publish.
|
|
404
|
+
* @returns {Promise<string>} - The public download URL of the published object.
|
|
405
|
+
*/
|
|
406
|
+
export const publishObject = async (api: AutoDriveApi, cid: string): Promise<string> => {
|
|
407
|
+
const result = await apiCalls.publishObject(api, { cid })
|
|
408
|
+
|
|
409
|
+
return publicDownloadUrl(api, result.result)
|
|
410
|
+
}
|
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
|
-
};
|