@autonomys/auto-drive 1.4.21 → 1.4.23
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/package.json +5 -5
- package/.env +0 -6
- package/cid.debug.ts +0 -11
- package/dist/api/type.d.ts +0 -172
- package/dist/api/type.d.ts.map +0 -1
- package/dist/api/type.js +0 -8
- package/dist/utils/async.d.ts +0 -6
- package/dist/utils/async.d.ts.map +0 -1
- package/dist/utils/async.js +0 -79
- package/morphology.debug.ts +0 -46
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.23",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"typescript": "^5.8.3"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@autonomys/asynchronous": "^1.4.
|
|
46
|
-
"@autonomys/auto-dag-data": "^1.4.
|
|
47
|
-
"@autonomys/auto-utils": "^1.4.
|
|
45
|
+
"@autonomys/asynchronous": "^1.4.23",
|
|
46
|
+
"@autonomys/auto-dag-data": "^1.4.23",
|
|
47
|
+
"@autonomys/auto-utils": "^1.4.23",
|
|
48
48
|
"blockstore-core": "^5.0.2",
|
|
49
49
|
"jszip": "^3.10.1",
|
|
50
50
|
"mime-types": "^3.0.1",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"stream": "^0.0.3",
|
|
53
53
|
"zod": "^3.24.2"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "5bd522e4d53624e4d3524a929406f979a56fbf42"
|
|
56
56
|
}
|
package/.env
DELETED
package/cid.debug.ts
DELETED
package/dist/api/type.d.ts
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
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
|
package/dist/api/type.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../src/api/type.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;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAE7C,MAAM,WAAW,YAAa,SAAQ,mBAAmB;IACvD;;;;;;;;;;;;;;;;OAgBG;IACH,mBAAmB,E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E,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
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
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/utils/async.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Buffer } from 'buffer';
|
|
2
|
-
export declare const asyncByChunk: (asyncIterable: AsyncIterable<Buffer>, chunkSize: number) => AsyncGenerator<Buffer<ArrayBuffer>, void, unknown>;
|
|
3
|
-
export declare const asyncFromStream: (stream: ReadableStream<Uint8Array>) => AsyncIterable<Buffer>;
|
|
4
|
-
export declare const fileToIterable: (file: File | Blob) => AsyncIterable<Buffer>;
|
|
5
|
-
export declare const bufferToIterable: (buffer: Buffer) => AsyncIterable<Buffer>;
|
|
6
|
-
//# sourceMappingURL=async.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async.d.ts","sourceRoot":"","sources":["../../src/utils/async.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,eAAO,MAAM,YAAY,kBACR,aAAa,CAAC,MAAM,CAAC,aACzB,MAAM,uDAelB,CAAA;AAED,eAAO,MAAM,eAAe,WAClB,cAAc,CAAC,UAAU,CAAC,KACjC,aAAa,CAAC,MAAM,CAOtB,CAAA;AAED,eAAO,MAAM,cAAc,SAA0B,IAAI,GAAG,IAAI,KAAG,aAAa,CAAC,MAAM,CAKtF,CAAA;AAED,eAAO,MAAM,gBAAgB,WAA4B,MAAM,KAAG,aAAa,CAAC,MAAM,CAErF,CAAA"}
|
package/dist/utils/async.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
3
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
4
|
-
var m = o[Symbol.asyncIterator], i;
|
|
5
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
6
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
7
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
8
|
-
};
|
|
9
|
-
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
10
|
-
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
11
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
12
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
13
|
-
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
14
|
-
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
15
|
-
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
16
|
-
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
17
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
18
|
-
function fulfill(value) { resume("next", value); }
|
|
19
|
-
function reject(value) { resume("throw", value); }
|
|
20
|
-
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
21
|
-
};
|
|
22
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.bufferToIterable = exports.fileToIterable = exports.asyncFromStream = exports.asyncByChunk = void 0;
|
|
24
|
-
const buffer_1 = require("buffer");
|
|
25
|
-
const asyncByChunk = function (asyncIterable, chunkSize) {
|
|
26
|
-
return __asyncGenerator(this, arguments, function* () {
|
|
27
|
-
var _a, e_1, _b, _c;
|
|
28
|
-
let buffer = buffer_1.Buffer.alloc(0);
|
|
29
|
-
try {
|
|
30
|
-
for (var _d = true, asyncIterable_1 = __asyncValues(asyncIterable), asyncIterable_1_1; asyncIterable_1_1 = yield __await(asyncIterable_1.next()), _a = asyncIterable_1_1.done, !_a; _d = true) {
|
|
31
|
-
_c = asyncIterable_1_1.value;
|
|
32
|
-
_d = false;
|
|
33
|
-
const chunk = _c;
|
|
34
|
-
buffer = buffer_1.Buffer.concat([buffer, chunk]);
|
|
35
|
-
while (buffer.length >= chunkSize) {
|
|
36
|
-
yield yield __await(buffer.subarray(0, chunkSize));
|
|
37
|
-
buffer = buffer.subarray(chunkSize);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
42
|
-
finally {
|
|
43
|
-
try {
|
|
44
|
-
if (!_d && !_a && (_b = asyncIterable_1.return)) yield __await(_b.call(asyncIterable_1));
|
|
45
|
-
}
|
|
46
|
-
finally { if (e_1) throw e_1.error; }
|
|
47
|
-
}
|
|
48
|
-
if (buffer.length > 0) {
|
|
49
|
-
yield yield __await(buffer);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
exports.asyncByChunk = asyncByChunk;
|
|
54
|
-
const asyncFromStream = function (stream) {
|
|
55
|
-
return __asyncGenerator(this, arguments, function* () {
|
|
56
|
-
const reader = stream.getReader();
|
|
57
|
-
let result = yield __await(reader.read());
|
|
58
|
-
while (!result.done) {
|
|
59
|
-
yield yield __await(buffer_1.Buffer.from(result.value));
|
|
60
|
-
result = yield __await(reader.read());
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
};
|
|
64
|
-
exports.asyncFromStream = asyncFromStream;
|
|
65
|
-
const fileToIterable = function (file) {
|
|
66
|
-
return __asyncGenerator(this, arguments, function* () {
|
|
67
|
-
const chunkSize = 1024 * 1024;
|
|
68
|
-
for (let i = 0; i < file.size; i += chunkSize) {
|
|
69
|
-
yield yield __await(buffer_1.Buffer.from(yield __await(file.slice(i, i + chunkSize).arrayBuffer())));
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
};
|
|
73
|
-
exports.fileToIterable = fileToIterable;
|
|
74
|
-
const bufferToIterable = function (buffer) {
|
|
75
|
-
return __asyncGenerator(this, arguments, function* () {
|
|
76
|
-
yield yield __await(buffer);
|
|
77
|
-
});
|
|
78
|
-
};
|
|
79
|
-
exports.bufferToIterable = bufferToIterable;
|
package/morphology.debug.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
import { ObjectInformation } from './src/api/index'
|
|
3
|
-
import { blake3Hash } from './src/node'
|
|
4
|
-
|
|
5
|
-
const cid = 'bafkr6idrzb7n6yq25lq4vrf3xybhnygukipp4ogk4m2646dlcsopbtufum'
|
|
6
|
-
|
|
7
|
-
interface ObjectMapping {
|
|
8
|
-
blockNumber: number
|
|
9
|
-
v0: {
|
|
10
|
-
objects: [string, number, number][]
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const getObjectMapping = async (hash: string) => {
|
|
15
|
-
const response = await fetch(`https://indexer.mainnet.autonomys.xyz/objects/${hash}`)
|
|
16
|
-
if (!response.ok) {
|
|
17
|
-
throw new Error('Failed to fetch object mapping')
|
|
18
|
-
}
|
|
19
|
-
return (await response.json()) as ObjectMapping
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const getMorphology = async (cid: string) => {
|
|
23
|
-
const response = await fetch(`https://public.auto-drive.autonomys.xyz/api/objects/${cid}`)
|
|
24
|
-
if (!response.ok) {
|
|
25
|
-
throw new Error('Failed to fetch object information')
|
|
26
|
-
}
|
|
27
|
-
const data: ObjectInformation = await response.json()
|
|
28
|
-
|
|
29
|
-
if (data.metadata.type === 'folder') {
|
|
30
|
-
throw new Error('Folder is not supported')
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const objectMappingHashes = await Promise.all(
|
|
34
|
-
data.metadata.chunks.map((chunk) => blake3Hash(chunk.cid).then((e) => e.toString('hex'))),
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
const objectMappings = []
|
|
38
|
-
for (const hash of objectMappingHashes) {
|
|
39
|
-
const objectMapping = await getObjectMapping(hash)
|
|
40
|
-
objectMappings.push(objectMapping)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
fs.writeFileSync('objectMappings.json', JSON.stringify(objectMappings, null, 2))
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
getMorphology(cid)
|