@autonomys/auto-drive 1.0.2 → 1.0.3
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/dist/cjs/api/calls/download.d.ts +5 -0
- package/dist/cjs/api/calls/index.d.ts +4 -0
- package/dist/cjs/api/calls/read.d.ts +97 -0
- package/dist/cjs/api/calls/upload.d.ts +93 -0
- package/dist/cjs/api/calls/write.d.ts +48 -0
- package/dist/cjs/api/connection.d.ts +7 -0
- package/dist/cjs/api/index.d.ts +4 -0
- package/dist/cjs/api/models/folderTree.d.ts +29 -0
- package/dist/cjs/api/models/index.d.ts +2 -0
- package/dist/cjs/api/models/objects.d.ts +40 -0
- package/dist/cjs/api/models/uploads.d.ts +113 -0
- package/dist/cjs/api/wrappers.d.ts +66 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +28810 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/utils/async.d.ts +2 -0
- package/dist/cjs/utils/folder.d.ts +1 -0
- package/dist/cjs/utils/index.d.ts +4 -0
- package/dist/cjs/utils/stream.d.ts +2 -0
- package/dist/cjs/utils/types.d.ts +5 -0
- package/dist/esm/api/calls/download.d.ts +5 -0
- package/dist/esm/api/calls/index.d.ts +4 -0
- package/dist/esm/api/calls/read.d.ts +97 -0
- package/dist/esm/api/calls/upload.d.ts +93 -0
- package/dist/esm/api/calls/write.d.ts +48 -0
- package/dist/esm/api/connection.d.ts +7 -0
- package/dist/esm/api/index.d.ts +4 -0
- package/dist/esm/api/models/folderTree.d.ts +29 -0
- package/dist/esm/api/models/index.d.ts +2 -0
- package/dist/esm/api/models/objects.d.ts +40 -0
- package/dist/esm/api/models/uploads.d.ts +113 -0
- package/dist/esm/api/wrappers.d.ts +66 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +28762 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/utils/async.d.ts +2 -0
- package/dist/esm/utils/folder.d.ts +1 -0
- package/dist/esm/utils/index.d.ts +4 -0
- package/dist/esm/utils/stream.d.ts +2 -0
- package/dist/esm/utils/types.d.ts +5 -0
- package/package.json +3 -3
- package/src/api/calls/download.ts +2 -2
- package/src/api/calls/index.ts +4 -4
- package/src/api/calls/read.ts +3 -3
- package/src/api/calls/upload.ts +7 -7
- package/src/api/calls/write.ts +2 -2
- package/src/api/connection.ts +11 -1
- package/src/api/index.ts +4 -4
- package/src/api/models/index.ts +2 -2
- package/src/api/models/uploads.ts +5 -1
- package/src/api/wrappers.ts +19 -11
- package/src/index.ts +2 -2
- package/src/utils/index.ts +4 -4
- package/tsconfig.json +1 -3
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { ArgsWithoutPagination, ArgsWithPagination } from '../../utils/types.js';
|
|
2
|
+
import { AutoDriveApi } from '../connection.js';
|
|
3
|
+
import { ObjectInformation, ObjectSummary, Scope } from '../models/objects.js';
|
|
4
|
+
/**
|
|
5
|
+
* Retrieves the root objects based on the specified scope.
|
|
6
|
+
*
|
|
7
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
8
|
+
* @param {ArgsWithPagination<{ scope: Scope }>} query - The query parameters including scope, limit, and offset.
|
|
9
|
+
* @returns {Promise<ObjectSummary[]>} - A promise that resolves to an array of ObjectSummary representing the root objects.
|
|
10
|
+
* @throws {Error} - Throws an error if the request fails.
|
|
11
|
+
*/
|
|
12
|
+
export declare const getRoots: (api: AutoDriveApi, query: ArgsWithPagination<{
|
|
13
|
+
scope: Scope;
|
|
14
|
+
}>) => Promise<ObjectSummary[]>;
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves the objects that have been shared with the authenticated user.
|
|
17
|
+
*
|
|
18
|
+
* This method sends a request to the server to fetch a list of objects
|
|
19
|
+
* that are shared with the user, based on the specified pagination parameters.
|
|
20
|
+
*
|
|
21
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
22
|
+
* @param {ArgsWithPagination} query - The query parameters including limit and offset for pagination.
|
|
23
|
+
* @returns {Promise<ObjectSummary[]>} - A promise that resolves to an array of ObjectSummary representing the shared objects.
|
|
24
|
+
* @throws {Error} - Throws an error if the request fails.
|
|
25
|
+
*/
|
|
26
|
+
export declare const getSharedWithMe: (api: AutoDriveApi, query: ArgsWithPagination) => Promise<ObjectSummary[]>;
|
|
27
|
+
/**
|
|
28
|
+
* Retrieves the objects that have been marked as deleted.
|
|
29
|
+
*
|
|
30
|
+
* This method sends a request to the server to fetch a list of objects
|
|
31
|
+
* that have been deleted, based on the specified pagination parameters.
|
|
32
|
+
*
|
|
33
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
34
|
+
* @param {ArgsWithPagination} query - The query parameters including limit and offset for pagination.
|
|
35
|
+
* @returns {Promise<ObjectSummary[]>} - A promise that resolves to an array of ObjectSummary representing the deleted objects.
|
|
36
|
+
* @throws {Error} - Throws an error if the request fails.
|
|
37
|
+
*/
|
|
38
|
+
export declare const getDeleted: (api: AutoDriveApi, query: ArgsWithPagination) => Promise<ObjectSummary[]>;
|
|
39
|
+
/**
|
|
40
|
+
* Retrieves the aggregated information of a specific object identified by its CID.
|
|
41
|
+
*
|
|
42
|
+
* This method sends a request to the server to fetch details about the
|
|
43
|
+
* object, including its metadata and other relevant information.
|
|
44
|
+
*
|
|
45
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
46
|
+
* @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object to retrieve.
|
|
47
|
+
* @returns {Promise<ObjectInformation>} - A promise that resolves to the information of the requested object.
|
|
48
|
+
* @throws {Error} - Throws an error if the request fails.
|
|
49
|
+
*/
|
|
50
|
+
export declare const getObject: (api: AutoDriveApi, query: ArgsWithoutPagination<{
|
|
51
|
+
cid: string;
|
|
52
|
+
}>) => Promise<ObjectInformation>;
|
|
53
|
+
/**
|
|
54
|
+
* Retrieves the upload status of a specific object identified by its CID.
|
|
55
|
+
*
|
|
56
|
+
* This method sends a request to the server to fetch the current upload status
|
|
57
|
+
* of the object, which can indicate whether the upload is pending, completed,
|
|
58
|
+
* or failed.
|
|
59
|
+
*
|
|
60
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
61
|
+
* @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object whose upload status is to be retrieved.
|
|
62
|
+
* @returns {Promise<ObjectInformation['uploadStatus']>} - A promise that resolves to the upload status of the requested object.
|
|
63
|
+
* @throws {Error} - Throws an error if the request fails.
|
|
64
|
+
*/
|
|
65
|
+
export declare const getObjectUploadStatus: (api: AutoDriveApi, query: ArgsWithoutPagination<{
|
|
66
|
+
cid: string;
|
|
67
|
+
}>) => Promise<ObjectInformation["uploadStatus"]>;
|
|
68
|
+
/**
|
|
69
|
+
* Retrieves the owners of a specific object identified by its CID.
|
|
70
|
+
*
|
|
71
|
+
* This method sends a request to the server to fetch the list of owners
|
|
72
|
+
* associated with the object. The owners can provide insights into who
|
|
73
|
+
* has access to or control over the object.
|
|
74
|
+
*
|
|
75
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
76
|
+
* @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object whose owners are to be retrieved.
|
|
77
|
+
* @returns {Promise<ObjectInformation['owners']>} - A promise that resolves to the list of owners of the requested object.
|
|
78
|
+
* @throws {Error} - Throws an error if the request fails.
|
|
79
|
+
*/
|
|
80
|
+
export declare const getObjectOwners: (api: AutoDriveApi, query: ArgsWithoutPagination<{
|
|
81
|
+
cid: string;
|
|
82
|
+
}>) => Promise<ObjectInformation["owners"]>;
|
|
83
|
+
/**
|
|
84
|
+
* Retrieves the metadata of a specific object identified by its CID.
|
|
85
|
+
*
|
|
86
|
+
* This method sends a request to the server to fetch the metadata associated
|
|
87
|
+
* with the object. The metadata can include various details about the object,
|
|
88
|
+
* such as its name, type, size, and other relevant information.
|
|
89
|
+
*
|
|
90
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
91
|
+
* @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object whose metadata is to be retrieved.
|
|
92
|
+
* @returns {Promise<ObjectInformation['metadata']>} - A promise that resolves to the metadata of the requested object.
|
|
93
|
+
* @throws {Error} - Throws an error if the request fails.
|
|
94
|
+
*/
|
|
95
|
+
export declare const getObjectMetadata: (api: AutoDriveApi, query: ArgsWithoutPagination<{
|
|
96
|
+
cid: string;
|
|
97
|
+
}>) => Promise<ObjectInformation["metadata"]>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { FileUploadOptions } from '@autonomys/auto-dag-data';
|
|
2
|
+
import { ArgsWithoutPagination } from '../../utils/types.js';
|
|
3
|
+
import { AutoDriveApi } from '../connection.js';
|
|
4
|
+
import { FolderTree } from '../models/folderTree.js';
|
|
5
|
+
import { FileUpload, FolderUpload } from '../models/uploads.js';
|
|
6
|
+
/**
|
|
7
|
+
* Initiates a file upload to the server.
|
|
8
|
+
*
|
|
9
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
10
|
+
* @param {ArgsWithoutPagination<{ mimeType?: string; filename: string; uploadOptions: FileUploadOptions | null }>} args - The arguments for the file upload.
|
|
11
|
+
* @param {string} args.mimeType - The MIME type of the file (optional).
|
|
12
|
+
* @param {string} args.filename - The name of the file to be uploaded.
|
|
13
|
+
* @param {FileUploadOptions | null} args.uploadOptions - Additional options for the file upload (optional).
|
|
14
|
+
* @returns {Promise<FileUpload>} - A promise that resolves to the file upload information.
|
|
15
|
+
* @throws {Error} - Throws an error if the upload fails.
|
|
16
|
+
*/
|
|
17
|
+
export declare const createFileUpload: (api: AutoDriveApi, { mimeType, filename, uploadOptions, }: ArgsWithoutPagination<{
|
|
18
|
+
mimeType?: string;
|
|
19
|
+
filename: string;
|
|
20
|
+
uploadOptions: FileUploadOptions | null;
|
|
21
|
+
}>) => Promise<FileUpload>;
|
|
22
|
+
/**
|
|
23
|
+
* Initiates a folder upload to the server.
|
|
24
|
+
*
|
|
25
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
26
|
+
* @param {ArgsWithoutPagination<{ fileTree: FolderTree; uploadOptions: FileUploadOptions }>} args - The arguments for the folder upload.
|
|
27
|
+
* @param {FolderTree} args.fileTree - The structure of the folder and its contents to be uploaded.
|
|
28
|
+
* @param {FileUploadOptions} args.uploadOptions - Additional options for the folder upload.
|
|
29
|
+
* @returns {Promise<FolderUpload>} - A promise that resolves to the folder upload information.
|
|
30
|
+
* @throws {Error} - Throws an error if the upload fails.
|
|
31
|
+
*/
|
|
32
|
+
export declare const createFolderUpload: (api: AutoDriveApi, { fileTree, uploadOptions, }: ArgsWithoutPagination<{
|
|
33
|
+
fileTree: FolderTree;
|
|
34
|
+
uploadOptions: FileUploadOptions;
|
|
35
|
+
}>) => Promise<FolderUpload>;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a file upload within an existing folder upload.
|
|
38
|
+
*
|
|
39
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
40
|
+
* @param {ArgsWithoutPagination<{ uploadId: string; name: string; mimeType: string; relativeId: string; uploadOptions: FileUploadOptions }>} args - The arguments for the file upload.
|
|
41
|
+
* @param {string} args.uploadId - The ID of the folder upload to which the file will be added.
|
|
42
|
+
* @param {string} args.name - The name of the file to be uploaded.
|
|
43
|
+
* @param {string} args.mimeType - The MIME type of the file being uploaded.
|
|
44
|
+
* @param {string} args.relativeId - The relative ID of the file within the folder structure.
|
|
45
|
+
* @param {FileUploadOptions} [args.uploadOptions={}] - Additional options for the file upload.
|
|
46
|
+
* @returns {Promise<FileUpload>} - A promise that resolves to the file upload information.
|
|
47
|
+
* @throws {Error} - Throws an error if the upload fails.
|
|
48
|
+
*/
|
|
49
|
+
export declare const createFileUploadWithinFolderUpload: (api: AutoDriveApi, { uploadId, name, mimeType, relativeId, uploadOptions, }: ArgsWithoutPagination<{
|
|
50
|
+
uploadId: string;
|
|
51
|
+
name: string;
|
|
52
|
+
mimeType?: string;
|
|
53
|
+
relativeId: string;
|
|
54
|
+
uploadOptions: FileUploadOptions;
|
|
55
|
+
}>) => Promise<FileUpload>;
|
|
56
|
+
/**
|
|
57
|
+
* Uploads a chunk of a file to the server.
|
|
58
|
+
*
|
|
59
|
+
* This function allows for the uploading of a specific chunk of a file
|
|
60
|
+
* during a multi-part upload process. It sends the chunk along with its
|
|
61
|
+
* index to the server, which can be used to reconstruct the file on the
|
|
62
|
+
* server side.
|
|
63
|
+
*
|
|
64
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
65
|
+
* @param {ArgsWithoutPagination<{ uploadId: string; chunk: Buffer; index: number }>} args - The arguments for the file chunk upload.
|
|
66
|
+
* @param {string} args.uploadId - The ID of the upload session.
|
|
67
|
+
* @param {Buffer} args.chunk - The chunk of the file to be uploaded.
|
|
68
|
+
* @param {number} args.index - The index of the chunk in the overall file.
|
|
69
|
+
* @returns {Promise<void>} - A promise that resolves when the chunk is uploaded successfully.
|
|
70
|
+
* @throws {Error} - Throws an error if the upload fails.
|
|
71
|
+
*/
|
|
72
|
+
export declare const uploadFileChunk: (api: AutoDriveApi, { uploadId, chunk, index, }: ArgsWithoutPagination<{
|
|
73
|
+
uploadId: string;
|
|
74
|
+
chunk: Buffer;
|
|
75
|
+
index: number;
|
|
76
|
+
}>) => Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Completes a file or folder upload session on the server.
|
|
79
|
+
*
|
|
80
|
+
* This function sends a request to the server to finalize the upload
|
|
81
|
+
* process for a given upload session identified by the upload ID. It is
|
|
82
|
+
* typically called after all file chunks have been uploaded. This method
|
|
83
|
+
* can be used to complete both file and folder uploads.
|
|
84
|
+
*
|
|
85
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
86
|
+
* @param {ArgsWithoutPagination<{ uploadId: string }>} args - The arguments for completing the upload.
|
|
87
|
+
* @param {string} args.uploadId - The ID of the upload session to complete.
|
|
88
|
+
* @returns {Promise<any>} - A promise that resolves to the response from the server.
|
|
89
|
+
* @throws {Error} - Throws an error if the completion of the upload fails.
|
|
90
|
+
*/
|
|
91
|
+
export declare const completeUpload: (api: AutoDriveApi, { uploadId }: ArgsWithoutPagination<{
|
|
92
|
+
uploadId: string;
|
|
93
|
+
}>) => Promise<any>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ArgsWithoutPagination } from '../../utils/types.js';
|
|
2
|
+
import { AutoDriveApi } from '../connection.js';
|
|
3
|
+
/**
|
|
4
|
+
* Shares an object with a specified public ID.
|
|
5
|
+
*
|
|
6
|
+
* This function sends a request to the server to share an object identified
|
|
7
|
+
* by its CID. The object will be shared with the provided public ID, allowing
|
|
8
|
+
* access to the object for users with that ID.
|
|
9
|
+
*
|
|
10
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
11
|
+
* @param {ArgsWithoutPagination<{ cid: string; publicId: string }>} query - The query parameters containing the CID of the object to share and the public ID to share it with.
|
|
12
|
+
* @returns {Promise<any>} - A promise that resolves to the response from the server.
|
|
13
|
+
* @throws {Error} - Throws an error if the sharing process fails.
|
|
14
|
+
*/
|
|
15
|
+
export declare const shareObject: (api: AutoDriveApi, query: ArgsWithoutPagination<{
|
|
16
|
+
cid: string;
|
|
17
|
+
publicId: string;
|
|
18
|
+
}>) => Promise<any>;
|
|
19
|
+
/**
|
|
20
|
+
* Marks an object as deleted by sending a request to the server.
|
|
21
|
+
*
|
|
22
|
+
* This function sends a request to the server to mark an object identified
|
|
23
|
+
* by its CID as deleted. This action is typically irreversible and should
|
|
24
|
+
* be used with caution.
|
|
25
|
+
*
|
|
26
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
27
|
+
* @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object to mark as deleted.
|
|
28
|
+
* @returns {Promise<void>} - A promise that resolves when the object has been marked as deleted.
|
|
29
|
+
* @throws {Error} - Throws an error if the marking process fails.
|
|
30
|
+
*/
|
|
31
|
+
export declare const markObjectAsDeleted: (api: AutoDriveApi, query: ArgsWithoutPagination<{
|
|
32
|
+
cid: string;
|
|
33
|
+
}>) => Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Restores an object that has been marked as deleted by sending a request to the server.
|
|
36
|
+
*
|
|
37
|
+
* This function sends a request to the server to restore an object identified
|
|
38
|
+
* by its CID. The restoration process may depend on the server's implementation
|
|
39
|
+
* and the object's current state.
|
|
40
|
+
*
|
|
41
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
42
|
+
* @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object to restore.
|
|
43
|
+
* @returns {Promise<void>} - A promise that resolves when the object has been successfully restored.
|
|
44
|
+
* @throws {Error} - Throws an error if the restoration process fails.
|
|
45
|
+
*/
|
|
46
|
+
export declare const restoreObject: (api: AutoDriveApi, query: ArgsWithoutPagination<{
|
|
47
|
+
cid: string;
|
|
48
|
+
}>) => Promise<void>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export type FolderTreeFolder = {
|
|
3
|
+
name: string;
|
|
4
|
+
type: 'folder';
|
|
5
|
+
children: FolderTree[];
|
|
6
|
+
id: string;
|
|
7
|
+
};
|
|
8
|
+
export type FolderTreeFile = {
|
|
9
|
+
name: string;
|
|
10
|
+
type: 'file';
|
|
11
|
+
id: string;
|
|
12
|
+
};
|
|
13
|
+
export type FolderTree = FolderTreeFolder | FolderTreeFile;
|
|
14
|
+
export declare const FolderTreeFolderSchema: any;
|
|
15
|
+
export declare const FolderTreeFileSchema: z.ZodObject<{
|
|
16
|
+
name: z.ZodString;
|
|
17
|
+
type: z.ZodLiteral<"file">;
|
|
18
|
+
id: z.ZodString;
|
|
19
|
+
}, "strip", z.ZodTypeAny, {
|
|
20
|
+
name?: string;
|
|
21
|
+
type?: "file";
|
|
22
|
+
id?: string;
|
|
23
|
+
}, {
|
|
24
|
+
name?: string;
|
|
25
|
+
type?: "file";
|
|
26
|
+
id?: string;
|
|
27
|
+
}>;
|
|
28
|
+
export declare const FolderTreeSchema: any;
|
|
29
|
+
export declare const constructFromFileSystemEntries: (entries: string[]) => FolderTree;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { OffchainMetadata } from '@autonomys/auto-dag-data';
|
|
2
|
+
export declare enum Scope {
|
|
3
|
+
Global = "global",
|
|
4
|
+
User = "user"
|
|
5
|
+
}
|
|
6
|
+
export interface Owner {
|
|
7
|
+
publicId: string;
|
|
8
|
+
role: OwnerRole;
|
|
9
|
+
}
|
|
10
|
+
export declare enum OwnerRole {
|
|
11
|
+
ADMIN = "admin",
|
|
12
|
+
VIEWER = "viewer"
|
|
13
|
+
}
|
|
14
|
+
export interface ObjectUploadStatus {
|
|
15
|
+
uploadedNodes: number | null;
|
|
16
|
+
totalNodes: number | null;
|
|
17
|
+
minimumBlockDepth: number | null;
|
|
18
|
+
maximumBlockDepth: number | null;
|
|
19
|
+
}
|
|
20
|
+
export type ObjectSummary = {
|
|
21
|
+
headCid: string;
|
|
22
|
+
name?: string;
|
|
23
|
+
size: number;
|
|
24
|
+
owners: Owner[];
|
|
25
|
+
uploadStatus: ObjectUploadStatus;
|
|
26
|
+
} & ({
|
|
27
|
+
type: 'file';
|
|
28
|
+
mimeType?: string;
|
|
29
|
+
} | {
|
|
30
|
+
type: 'folder';
|
|
31
|
+
children: (OffchainMetadata & {
|
|
32
|
+
type: 'folder';
|
|
33
|
+
})['children'];
|
|
34
|
+
});
|
|
35
|
+
export interface ObjectInformation {
|
|
36
|
+
cid: string;
|
|
37
|
+
metadata: OffchainMetadata;
|
|
38
|
+
uploadStatus: ObjectUploadStatus;
|
|
39
|
+
owners: Owner[];
|
|
40
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { FileUploadOptions } from '@autonomys/auto-dag-data';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export declare enum UploadType {
|
|
4
|
+
FILE = "file",
|
|
5
|
+
FOLDER = "folder"
|
|
6
|
+
}
|
|
7
|
+
export declare enum UploadStatus {
|
|
8
|
+
PENDING = "pending",
|
|
9
|
+
COMPLETED = "completed",
|
|
10
|
+
MIGRATING = "migrating",
|
|
11
|
+
CANCELLED = "cancelled",
|
|
12
|
+
FAILED = "failed"
|
|
13
|
+
}
|
|
14
|
+
export declare const fileUploadSchema: z.ZodObject<{
|
|
15
|
+
id: z.ZodString;
|
|
16
|
+
rootId: z.ZodString;
|
|
17
|
+
relativeId: z.ZodNullable<z.ZodString>;
|
|
18
|
+
type: z.ZodNativeEnum<typeof UploadType>;
|
|
19
|
+
status: z.ZodNativeEnum<typeof UploadStatus>;
|
|
20
|
+
fileTree: z.ZodNull;
|
|
21
|
+
name: z.ZodString;
|
|
22
|
+
mimeType: z.ZodNullable<z.ZodString>;
|
|
23
|
+
oauthProvider: z.ZodString;
|
|
24
|
+
oauthUserId: z.ZodString;
|
|
25
|
+
}, "strip", z.ZodTypeAny, {
|
|
26
|
+
id?: string;
|
|
27
|
+
rootId?: string;
|
|
28
|
+
relativeId?: string;
|
|
29
|
+
type?: UploadType;
|
|
30
|
+
status?: UploadStatus;
|
|
31
|
+
fileTree?: null;
|
|
32
|
+
name?: string;
|
|
33
|
+
mimeType?: string;
|
|
34
|
+
oauthProvider?: string;
|
|
35
|
+
oauthUserId?: string;
|
|
36
|
+
}, {
|
|
37
|
+
id?: string;
|
|
38
|
+
rootId?: string;
|
|
39
|
+
relativeId?: string;
|
|
40
|
+
type?: UploadType;
|
|
41
|
+
status?: UploadStatus;
|
|
42
|
+
fileTree?: null;
|
|
43
|
+
name?: string;
|
|
44
|
+
mimeType?: string;
|
|
45
|
+
oauthProvider?: string;
|
|
46
|
+
oauthUserId?: string;
|
|
47
|
+
}>;
|
|
48
|
+
export type FileUpload = z.infer<typeof fileUploadSchema> & {
|
|
49
|
+
uploadOptions: FileUploadOptions | null;
|
|
50
|
+
};
|
|
51
|
+
export declare const folderUploadSchema: z.ZodObject<{
|
|
52
|
+
id: z.ZodString;
|
|
53
|
+
rootId: z.ZodString;
|
|
54
|
+
relativeId: z.ZodNullable<z.ZodString>;
|
|
55
|
+
type: z.ZodNativeEnum<typeof UploadType>;
|
|
56
|
+
status: z.ZodNativeEnum<typeof UploadStatus>;
|
|
57
|
+
fileTree: z.ZodObject<{
|
|
58
|
+
name: z.ZodString;
|
|
59
|
+
type: z.ZodLiteral<"folder">;
|
|
60
|
+
children: z.ZodArray<z.ZodLazy<any>, "many">;
|
|
61
|
+
id: z.ZodString;
|
|
62
|
+
}, "strip", z.ZodTypeAny, {
|
|
63
|
+
id?: string;
|
|
64
|
+
type?: "folder";
|
|
65
|
+
name?: string;
|
|
66
|
+
children?: any[];
|
|
67
|
+
}, {
|
|
68
|
+
id?: string;
|
|
69
|
+
type?: "folder";
|
|
70
|
+
name?: string;
|
|
71
|
+
children?: any[];
|
|
72
|
+
}>;
|
|
73
|
+
name: z.ZodString;
|
|
74
|
+
mimeType: z.ZodNull;
|
|
75
|
+
oauthProvider: z.ZodString;
|
|
76
|
+
oauthUserId: z.ZodString;
|
|
77
|
+
uploadOptions: z.ZodNull;
|
|
78
|
+
}, "strip", z.ZodTypeAny, {
|
|
79
|
+
id?: string;
|
|
80
|
+
rootId?: string;
|
|
81
|
+
relativeId?: string;
|
|
82
|
+
type?: UploadType;
|
|
83
|
+
status?: UploadStatus;
|
|
84
|
+
fileTree?: {
|
|
85
|
+
id?: string;
|
|
86
|
+
type?: "folder";
|
|
87
|
+
name?: string;
|
|
88
|
+
children?: any[];
|
|
89
|
+
};
|
|
90
|
+
name?: string;
|
|
91
|
+
mimeType?: null;
|
|
92
|
+
oauthProvider?: string;
|
|
93
|
+
oauthUserId?: string;
|
|
94
|
+
uploadOptions?: null;
|
|
95
|
+
}, {
|
|
96
|
+
id?: string;
|
|
97
|
+
rootId?: string;
|
|
98
|
+
relativeId?: string;
|
|
99
|
+
type?: UploadType;
|
|
100
|
+
status?: UploadStatus;
|
|
101
|
+
fileTree?: {
|
|
102
|
+
id?: string;
|
|
103
|
+
type?: "folder";
|
|
104
|
+
name?: string;
|
|
105
|
+
children?: any[];
|
|
106
|
+
};
|
|
107
|
+
name?: string;
|
|
108
|
+
mimeType?: null;
|
|
109
|
+
oauthProvider?: string;
|
|
110
|
+
oauthUserId?: string;
|
|
111
|
+
uploadOptions?: null;
|
|
112
|
+
}>;
|
|
113
|
+
export type FolderUpload = z.infer<typeof folderUploadSchema>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { AutoDriveApi } from './connection.js';
|
|
2
|
+
type UploadFileOptions = {
|
|
3
|
+
password?: string;
|
|
4
|
+
compression?: boolean;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Uploads a file to the server with optional encryption and compression.
|
|
8
|
+
*
|
|
9
|
+
* This function reads a file from the specified file path, optionally encrypts it
|
|
10
|
+
* using the provided password, and compresses it using the ZLIB algorithm if specified.
|
|
11
|
+
* It then uploads the file in chunks to the server, creating an upload session and
|
|
12
|
+
* completing it once all chunks have been uploaded.
|
|
13
|
+
*
|
|
14
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
15
|
+
* @param {string} filePath - The path to the file to be uploaded.
|
|
16
|
+
* @param {UploadFileOptions} options - Options for the upload process.
|
|
17
|
+
* @param {string} [options.password] - The password for encryption (optional).
|
|
18
|
+
* @param {boolean} [options.compression=true] - Whether to compress the file (optional).
|
|
19
|
+
* @returns {Promise<void>} - A promise that resolves when the upload is complete.
|
|
20
|
+
* @throws {Error} - Throws an error if the upload fails at any stage.
|
|
21
|
+
*/
|
|
22
|
+
export declare const uploadFile: (api: AutoDriveApi, filePath: string, { password, compression }: UploadFileOptions, uploadChunkSize?: number) => Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Uploads an entire folder to the server.
|
|
25
|
+
*
|
|
26
|
+
* This function retrieves all files within the specified folder,
|
|
27
|
+
* constructs a file tree representation, and initiates the upload
|
|
28
|
+
* process. It also handles optional compression of the files during
|
|
29
|
+
* the upload.
|
|
30
|
+
*
|
|
31
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
32
|
+
* @param {string} folderPath - The path of the folder to be uploaded.
|
|
33
|
+
* @returns {Promise<void>} - A promise that resolves when the folder upload is complete.
|
|
34
|
+
* @throws {Error} - Throws an error if the upload fails at any stage.
|
|
35
|
+
*/
|
|
36
|
+
export declare const uploadFolder: (api: AutoDriveApi, folderPath: string, uploadChunkSize?: number) => Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Uploads a file within an existing folder upload session.
|
|
39
|
+
*
|
|
40
|
+
* @param {AutoDriveApi} api - The API instance to interact with the AutoDrive service.
|
|
41
|
+
* @param {string} uploadId - The ID of the folder upload session to which the file will be added.
|
|
42
|
+
* @param {string} filepath - The path of the file to be uploaded.
|
|
43
|
+
*
|
|
44
|
+
* @returns {Promise<void>} A promise that resolves when the file upload is complete.
|
|
45
|
+
*/
|
|
46
|
+
export declare const uploadFileWithinFolderUpload: (api: AutoDriveApi, uploadId: string, filepath: string, uploadChunkSize?: number) => Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Downloads a file from the AutoDrive service.
|
|
49
|
+
*
|
|
50
|
+
* @param {AutoDriveApi} api - The API instance to interact with the AutoDrive service.
|
|
51
|
+
* @param {string} cid - The CID of the file to be downloaded.
|
|
52
|
+
* @returns {Promise<ReadableStream<Uint8Array>>} A promise that resolves to a ReadableStream of the downloaded file.
|
|
53
|
+
*/
|
|
54
|
+
export declare const downloadFile: (api: AutoDriveApi, cid: string, password?: string) => Promise<AsyncIterable<Buffer>>;
|
|
55
|
+
/**
|
|
56
|
+
* Downloads a folder from the AutoDrive service without encryption.
|
|
57
|
+
*
|
|
58
|
+
* @param {AutoDriveApi} api - The API instance to interact with the AutoDrive service.
|
|
59
|
+
* @param {string} cid - The CID of the folder to be downloaded.
|
|
60
|
+
*
|
|
61
|
+
* @returns {Promise<ReadableStream<Uint8Array>>} A promise that resolves to a ReadableStream of the downloaded folder.
|
|
62
|
+
*
|
|
63
|
+
* @warning If the folder is encrypted, a warning will be logged, but the download will proceed without decryption.
|
|
64
|
+
*/
|
|
65
|
+
export declare const downloadFolderWithoutEncryption: (api: AutoDriveApi, cid: string) => Promise<ReadableStream<Uint8Array>>;
|
|
66
|
+
export {};
|