@autonomys/auto-drive 1.0.3 → 1.0.5
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 → api}/calls/download.d.ts +1 -0
- package/dist/api/calls/download.d.ts.map +1 -0
- package/dist/api/calls/download.js +21 -0
- package/dist/{esm/api → api}/calls/index.d.ts +1 -0
- package/dist/api/calls/index.d.ts.map +1 -0
- package/dist/{esm/api → api}/calls/read.d.ts +1 -0
- package/dist/api/calls/read.d.ts.map +1 -0
- package/dist/{cjs/api/calls/read.d.ts → api/calls/read.js} +72 -20
- package/dist/{esm/api → api}/calls/upload.d.ts +4 -3
- package/dist/api/calls/upload.d.ts.map +1 -0
- package/dist/{cjs/api/calls/upload.d.ts → api/calls/upload.js} +65 -29
- package/dist/{cjs/api → api}/calls/write.d.ts +1 -0
- package/dist/api/calls/write.d.ts.map +1 -0
- package/dist/{esm/api/calls/write.d.ts → api/calls/write.js} +38 -12
- package/dist/api/connection.d.ts +15 -0
- package/dist/api/connection.d.ts.map +1 -0
- package/dist/api/connection.js +24 -0
- package/dist/{esm/api → api}/index.d.ts +1 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/models/file.d.ts +8 -0
- package/dist/api/models/file.d.ts.map +1 -0
- package/dist/api/models/file.js +1 -0
- package/dist/api/models/folderTree.d.ts +47 -0
- package/dist/api/models/folderTree.d.ts.map +1 -0
- package/dist/api/models/folderTree.js +103 -0
- package/dist/{esm/api → api}/models/index.d.ts +1 -0
- package/dist/api/models/index.d.ts.map +1 -0
- package/dist/{cjs/api → api}/models/objects.d.ts +1 -0
- package/dist/api/models/objects.d.ts.map +1 -0
- package/dist/api/models/objects.js +10 -0
- package/dist/api/models/uploads.d.ts +130 -0
- package/dist/api/models/uploads.d.ts.map +1 -0
- package/dist/api/models/uploads.js +40 -0
- package/dist/api/wrappers.d.ts +107 -0
- package/dist/api/wrappers.d.ts.map +1 -0
- package/dist/api/wrappers.js +316 -0
- package/dist/{esm/index.d.ts → index.d.ts} +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/{cjs/utils → utils}/async.d.ts +2 -0
- package/dist/utils/async.d.ts.map +1 -0
- package/dist/utils/async.js +66 -0
- package/dist/{cjs/utils → utils}/folder.d.ts +1 -0
- package/dist/utils/folder.d.ts.map +1 -0
- package/dist/utils/folder.js +23 -0
- package/dist/{esm/utils → utils}/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/misc.d.ts +2 -0
- package/dist/utils/misc.d.ts.map +1 -0
- package/dist/utils/misc.js +1 -0
- package/dist/utils/observable.d.ts +7 -0
- package/dist/utils/observable.d.ts.map +1 -0
- package/dist/utils/observable.js +15 -0
- package/dist/{cjs/utils → utils}/stream.d.ts +1 -0
- package/dist/utils/stream.d.ts.map +1 -0
- package/dist/utils/stream.js +22 -0
- package/dist/{cjs/utils → utils}/types.d.ts +1 -0
- package/dist/utils/types.d.ts.map +1 -0
- package/dist/utils/types.js +1 -0
- package/package.json +4 -3
- package/src/api/calls/upload.ts +2 -2
- package/src/api/connection.ts +1 -1
- package/src/api/models/file.ts +7 -0
- package/src/api/models/folderTree.ts +51 -0
- package/src/api/models/uploads.ts +17 -1
- package/src/api/wrappers.ts +274 -102
- package/src/utils/async.ts +7 -0
- package/src/utils/misc.ts +1 -0
- package/src/utils/observable.ts +19 -0
- package/dist/cjs/api/connection.d.ts +0 -7
- package/dist/cjs/api/models/folderTree.d.ts +0 -29
- package/dist/cjs/api/models/uploads.d.ts +0 -113
- package/dist/cjs/api/wrappers.d.ts +0 -66
- package/dist/cjs/index.js +0 -28810
- package/dist/cjs/index.js.map +0 -1
- package/dist/esm/api/calls/download.d.ts +0 -5
- package/dist/esm/api/connection.d.ts +0 -7
- package/dist/esm/api/models/folderTree.d.ts +0 -29
- package/dist/esm/api/models/objects.d.ts +0 -40
- package/dist/esm/api/models/uploads.d.ts +0 -113
- package/dist/esm/api/wrappers.d.ts +0 -66
- package/dist/esm/index.js +0 -28762
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/utils/async.d.ts +0 -2
- package/dist/esm/utils/folder.d.ts +0 -1
- package/dist/esm/utils/stream.d.ts +0 -2
- package/dist/esm/utils/types.d.ts +0 -5
- /package/dist/{cjs/api/calls/index.d.ts → api/calls/index.js} +0 -0
- /package/dist/{cjs/api/index.d.ts → api/index.js} +0 -0
- /package/dist/{cjs/api/models/index.d.ts → api/models/index.js} +0 -0
- /package/dist/{cjs/index.d.ts → index.js} +0 -0
- /package/dist/{cjs/utils/index.d.ts → utils/index.js} +0 -0
|
@@ -0,0 +1,103 @@
|
|
|
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';
|
|
11
|
+
import JSZip from 'jszip';
|
|
12
|
+
import { z } from 'zod';
|
|
13
|
+
export const FolderTreeFolderSchema = z.object({
|
|
14
|
+
name: z.string(),
|
|
15
|
+
type: z.literal('folder'),
|
|
16
|
+
children: z.array(z.lazy(() => FolderTreeSchema)),
|
|
17
|
+
id: z.string(),
|
|
18
|
+
});
|
|
19
|
+
export const FolderTreeFileSchema = z.object({
|
|
20
|
+
name: z.string(),
|
|
21
|
+
type: z.literal('file'),
|
|
22
|
+
id: z.string(),
|
|
23
|
+
});
|
|
24
|
+
export const FolderTreeSchema = z.discriminatedUnion('type', [
|
|
25
|
+
FolderTreeFolderSchema,
|
|
26
|
+
FolderTreeFileSchema,
|
|
27
|
+
]);
|
|
28
|
+
export const constructFromFileSystemEntries = (entries) => {
|
|
29
|
+
const root = {
|
|
30
|
+
name: 'root',
|
|
31
|
+
type: 'folder',
|
|
32
|
+
children: [],
|
|
33
|
+
id: 'root',
|
|
34
|
+
};
|
|
35
|
+
for (const entry of entries) {
|
|
36
|
+
const pathParts = entry.split('/').filter(Boolean);
|
|
37
|
+
let currentFolder = root;
|
|
38
|
+
for (const [index, part] of Array.from(pathParts.entries())) {
|
|
39
|
+
// Check if the part already exists in the current folder's children
|
|
40
|
+
let existingFolder = currentFolder.children.find((child) => child.name === part);
|
|
41
|
+
if (!existingFolder) {
|
|
42
|
+
// If it's the last part, create a file node
|
|
43
|
+
if (index === pathParts.length - 1) {
|
|
44
|
+
const fileNode = {
|
|
45
|
+
name: part,
|
|
46
|
+
type: 'file',
|
|
47
|
+
id: entry,
|
|
48
|
+
};
|
|
49
|
+
currentFolder.children.push(fileNode);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
// Create a new folder node
|
|
53
|
+
const folderNode = {
|
|
54
|
+
name: part,
|
|
55
|
+
type: 'folder',
|
|
56
|
+
children: [],
|
|
57
|
+
id: `${currentFolder.id.split('/').slice(1).join('/')}/${part}`,
|
|
58
|
+
};
|
|
59
|
+
currentFolder.children.push(folderNode);
|
|
60
|
+
existingFolder = folderNode;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
currentFolder = existingFolder; // Move to the next folder
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return root.children.length === 1 ? root.children[0] : root;
|
|
67
|
+
};
|
|
68
|
+
export const constructFromInput = (input) => {
|
|
69
|
+
return constructFromFileSystemEntries(Array.from(input).map((file) => {
|
|
70
|
+
if (!file.webkitRelativePath) {
|
|
71
|
+
throw new Error('webkitRelativePath is not supported');
|
|
72
|
+
}
|
|
73
|
+
return file.webkitRelativePath;
|
|
74
|
+
}));
|
|
75
|
+
};
|
|
76
|
+
const addFilesToZip = (folder, folderNode, files) => {
|
|
77
|
+
folderNode.children.forEach((child) => {
|
|
78
|
+
if (child.type === 'file') {
|
|
79
|
+
const file = files[child.id];
|
|
80
|
+
if (typeof file === 'string') {
|
|
81
|
+
folder.file(child.name, fs.createReadStream(file));
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
folder.file(child.name, file);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else if (child.type === 'folder') {
|
|
88
|
+
const subFolder = folder.folder(child.name);
|
|
89
|
+
if (!subFolder) {
|
|
90
|
+
throw new Error('Failed to create folder in zip');
|
|
91
|
+
}
|
|
92
|
+
addFilesToZip(subFolder, child, files);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
export const constructZipBlobFromTreeAndPaths = (tree, files) => __awaiter(void 0, void 0, void 0, function* () {
|
|
97
|
+
if (tree.type === 'file') {
|
|
98
|
+
throw new Error('Cannot construct zip from file');
|
|
99
|
+
}
|
|
100
|
+
const zip = new JSZip();
|
|
101
|
+
addFilesToZip(zip, tree, files);
|
|
102
|
+
return zip.generateAsync({ type: 'blob' });
|
|
103
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/models/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objects.d.ts","sourceRoot":"","sources":["../../../src/api/models/objects.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAE3D,oBAAY,KAAK;IACf,MAAM,WAAW;IACjB,IAAI,SAAS;CACd;AAED,MAAM,WAAW,KAAK;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,SAAS,CAAA;CAChB;AAED,oBAAY,SAAS;IACnB,KAAK,UAAU;IACf,MAAM,WAAW;CAClB;AAED,MAAM,WAAW,kBAAkB;IACjC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAA;IAChC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAA;CACjC;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,YAAY,EAAE,kBAAkB,CAAA;CACjC,GAAG,CACA;IACE,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,GACD;IACE,IAAI,EAAE,QAAQ,CAAA;IACd,QAAQ,EAAE,CAAC,gBAAgB,GAAG;QAAE,IAAI,EAAE,QAAQ,CAAA;KAAE,CAAC,CAAC,UAAU,CAAC,CAAA;CAC9D,CACJ,CAAA;AAED,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,gBAAgB,CAAA;IAC1B,YAAY,EAAE,kBAAkB,CAAA;IAChC,MAAM,EAAE,KAAK,EAAE,CAAA;CAChB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export var Scope;
|
|
2
|
+
(function (Scope) {
|
|
3
|
+
Scope["Global"] = "global";
|
|
4
|
+
Scope["User"] = "user";
|
|
5
|
+
})(Scope || (Scope = {}));
|
|
6
|
+
export var OwnerRole;
|
|
7
|
+
(function (OwnerRole) {
|
|
8
|
+
OwnerRole["ADMIN"] = "admin";
|
|
9
|
+
OwnerRole["VIEWER"] = "viewer";
|
|
10
|
+
})(OwnerRole || (OwnerRole = {}));
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { CID, 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
|
+
name: string;
|
|
27
|
+
type: UploadType;
|
|
28
|
+
status: UploadStatus;
|
|
29
|
+
id: string;
|
|
30
|
+
rootId: string;
|
|
31
|
+
relativeId: string | null;
|
|
32
|
+
fileTree: null;
|
|
33
|
+
mimeType: string | null;
|
|
34
|
+
oauthProvider: string;
|
|
35
|
+
oauthUserId: string;
|
|
36
|
+
}, {
|
|
37
|
+
name: string;
|
|
38
|
+
type: UploadType;
|
|
39
|
+
status: UploadStatus;
|
|
40
|
+
id: string;
|
|
41
|
+
rootId: string;
|
|
42
|
+
relativeId: string | null;
|
|
43
|
+
fileTree: null;
|
|
44
|
+
mimeType: string | null;
|
|
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<z.ZodType<import("./folderTree.js").FolderTree, z.ZodTypeDef, import("./folderTree.js").FolderTree>>, "many">;
|
|
61
|
+
id: z.ZodString;
|
|
62
|
+
}, "strip", z.ZodTypeAny, {
|
|
63
|
+
children: import("./folderTree.js").FolderTree[];
|
|
64
|
+
name: string;
|
|
65
|
+
type: "folder";
|
|
66
|
+
id: string;
|
|
67
|
+
}, {
|
|
68
|
+
children: import("./folderTree.js").FolderTree[];
|
|
69
|
+
name: string;
|
|
70
|
+
type: "folder";
|
|
71
|
+
id: string;
|
|
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
|
+
name: string;
|
|
80
|
+
type: UploadType;
|
|
81
|
+
status: UploadStatus;
|
|
82
|
+
id: string;
|
|
83
|
+
rootId: string;
|
|
84
|
+
relativeId: string | null;
|
|
85
|
+
fileTree: {
|
|
86
|
+
children: import("./folderTree.js").FolderTree[];
|
|
87
|
+
name: string;
|
|
88
|
+
type: "folder";
|
|
89
|
+
id: string;
|
|
90
|
+
};
|
|
91
|
+
mimeType: null;
|
|
92
|
+
oauthProvider: string;
|
|
93
|
+
oauthUserId: string;
|
|
94
|
+
uploadOptions: null;
|
|
95
|
+
}, {
|
|
96
|
+
name: string;
|
|
97
|
+
type: UploadType;
|
|
98
|
+
status: UploadStatus;
|
|
99
|
+
id: string;
|
|
100
|
+
rootId: string;
|
|
101
|
+
relativeId: string | null;
|
|
102
|
+
fileTree: {
|
|
103
|
+
children: import("./folderTree.js").FolderTree[];
|
|
104
|
+
name: string;
|
|
105
|
+
type: "folder";
|
|
106
|
+
id: string;
|
|
107
|
+
};
|
|
108
|
+
mimeType: null;
|
|
109
|
+
oauthProvider: string;
|
|
110
|
+
oauthUserId: string;
|
|
111
|
+
uploadOptions: null;
|
|
112
|
+
}>;
|
|
113
|
+
export type FolderUpload = z.infer<typeof folderUploadSchema>;
|
|
114
|
+
export type CompleteUploadResponse = {
|
|
115
|
+
cid: string;
|
|
116
|
+
};
|
|
117
|
+
export type UploadFileStatus = {
|
|
118
|
+
type: 'file';
|
|
119
|
+
progress: number;
|
|
120
|
+
cid?: CID;
|
|
121
|
+
};
|
|
122
|
+
export type UploadFolderStatus = {
|
|
123
|
+
type: 'folder';
|
|
124
|
+
progress: number;
|
|
125
|
+
cid?: CID;
|
|
126
|
+
};
|
|
127
|
+
export type UploadChunksStatus = {
|
|
128
|
+
uploadBytes: number;
|
|
129
|
+
};
|
|
130
|
+
//# sourceMappingURL=uploads.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uploads.d.ts","sourceRoot":"","sources":["../../../src/api/models/uploads.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,oBAAY,UAAU;IACpB,IAAI,SAAS;IACb,MAAM,WAAW;CAClB;AAED,oBAAY,YAAY;IACtB,OAAO,YAAY;IACnB,SAAS,cAAc;IACvB,SAAS,cAAc;IACvB,SAAS,cAAc;IACvB,MAAM,WAAW;CAClB;AAED,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAW3B,CAAA;AAEF,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,GAAG;IAC1D,aAAa,EAAE,iBAAiB,GAAG,IAAI,CAAA;CACxC,CAAA;AAED,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAY7B,CAAA;AAEF,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAA;AAE7D,MAAM,MAAM,sBAAsB,GAAG;IACnC,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,CAAC,EAAE,GAAG,CAAA;CACV,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,QAAQ,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,CAAC,EAAE,GAAG,CAAA;CACV,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { FolderTreeFolderSchema } from './folderTree.js';
|
|
3
|
+
export var UploadType;
|
|
4
|
+
(function (UploadType) {
|
|
5
|
+
UploadType["FILE"] = "file";
|
|
6
|
+
UploadType["FOLDER"] = "folder";
|
|
7
|
+
})(UploadType || (UploadType = {}));
|
|
8
|
+
export var UploadStatus;
|
|
9
|
+
(function (UploadStatus) {
|
|
10
|
+
UploadStatus["PENDING"] = "pending";
|
|
11
|
+
UploadStatus["COMPLETED"] = "completed";
|
|
12
|
+
UploadStatus["MIGRATING"] = "migrating";
|
|
13
|
+
UploadStatus["CANCELLED"] = "cancelled";
|
|
14
|
+
UploadStatus["FAILED"] = "failed";
|
|
15
|
+
})(UploadStatus || (UploadStatus = {}));
|
|
16
|
+
export const fileUploadSchema = z.object({
|
|
17
|
+
id: z.string(),
|
|
18
|
+
rootId: z.string(),
|
|
19
|
+
relativeId: z.string().nullable(),
|
|
20
|
+
type: z.nativeEnum(UploadType),
|
|
21
|
+
status: z.nativeEnum(UploadStatus),
|
|
22
|
+
fileTree: z.null(),
|
|
23
|
+
name: z.string(),
|
|
24
|
+
mimeType: z.string().nullable(),
|
|
25
|
+
oauthProvider: z.string(),
|
|
26
|
+
oauthUserId: z.string(),
|
|
27
|
+
});
|
|
28
|
+
export const folderUploadSchema = z.object({
|
|
29
|
+
id: z.string(),
|
|
30
|
+
rootId: z.string(),
|
|
31
|
+
relativeId: z.string().nullable(),
|
|
32
|
+
type: z.nativeEnum(UploadType),
|
|
33
|
+
status: z.nativeEnum(UploadStatus),
|
|
34
|
+
fileTree: FolderTreeFolderSchema,
|
|
35
|
+
name: z.string(),
|
|
36
|
+
mimeType: z.null(),
|
|
37
|
+
oauthProvider: z.string(),
|
|
38
|
+
oauthUserId: z.string(),
|
|
39
|
+
uploadOptions: z.null(),
|
|
40
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { PromisedObservable } from '../utils/observable.js';
|
|
2
|
+
import { AutoDriveApi } from './connection.js';
|
|
3
|
+
import { GenericFile } from './models/file.js';
|
|
4
|
+
import { UploadChunksStatus, UploadFileStatus, UploadFolderStatus } from './models/uploads.js';
|
|
5
|
+
type UploadFileOptions = {
|
|
6
|
+
password?: string;
|
|
7
|
+
compression?: boolean;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Uploads a file to the server with optional encryption and compression.
|
|
11
|
+
*
|
|
12
|
+
* This function reads a file from the specified file path, optionally encrypts it
|
|
13
|
+
* using the provided password, and compresses it using the specified algorithm if requested.
|
|
14
|
+
* It then uploads the file in chunks to the server, creating an upload session and
|
|
15
|
+
* completing it once all chunks have been successfully uploaded.
|
|
16
|
+
*
|
|
17
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
18
|
+
* @param {string} filePath - The path to the file to be uploaded.
|
|
19
|
+
* @param {UploadFileOptions} options - Options for the upload process.
|
|
20
|
+
* @param {string} [options.password] - The password for encryption (optional).
|
|
21
|
+
* @param {boolean} [options.compression=true] - Whether to compress the file (optional).
|
|
22
|
+
* @param {number} [uploadChunkSize] - The size of each chunk to upload (optional).
|
|
23
|
+
* @returns {PromisedObservable<UploadFileStatus>} - An observable that emits the upload status.
|
|
24
|
+
* @throws {Error} - Throws an error if the upload fails at any stage.
|
|
25
|
+
*/
|
|
26
|
+
export declare const uploadFileFromFilepath: (api: AutoDriveApi, filePath: string, { password, compression }: UploadFileOptions, uploadChunkSize?: number) => PromisedObservable<UploadFileStatus>;
|
|
27
|
+
/**
|
|
28
|
+
* Uploads a file to the server with optional encryption and compression.
|
|
29
|
+
*
|
|
30
|
+
* This function reads a file from the provided input, optionally encrypts it
|
|
31
|
+
* using the specified password, and compresses it using the specified algorithm if requested.
|
|
32
|
+
* It uploads the file in chunks to the server, creating an upload session and
|
|
33
|
+
* completing it once all chunks have been successfully uploaded.
|
|
34
|
+
*
|
|
35
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
36
|
+
* @param {File | GenericFile} file - The file to be uploaded, which can be a File or a GenericFile.
|
|
37
|
+
* @param {UploadFileOptions} options - Options for the upload process.
|
|
38
|
+
* @param {string} [options.password] - The password for encryption (optional).
|
|
39
|
+
* @param {boolean} [options.compression=true] - Whether to compress the file (optional).
|
|
40
|
+
* @param {number} [uploadChunkSize] - The size of each chunk to upload (optional).
|
|
41
|
+
* @returns {Promise<CID>} - A promise that resolves with the CID of the uploaded file.
|
|
42
|
+
* @throws {Error} - Throws an error if the upload fails at any stage.
|
|
43
|
+
*/
|
|
44
|
+
export declare const uploadFileFromInput: (api: AutoDriveApi, file: File | GenericFile, { password, compression }: UploadFileOptions, uploadChunkSize?: number) => PromisedObservable<UploadFileStatus>;
|
|
45
|
+
/**
|
|
46
|
+
* Uploads an entire folder to the server.
|
|
47
|
+
*
|
|
48
|
+
* This function retrieves all files within the specified folder,
|
|
49
|
+
* constructs a file tree representation, and initiates the upload
|
|
50
|
+
* process. It also handles optional compression and encryption of the files during
|
|
51
|
+
* the upload.
|
|
52
|
+
*
|
|
53
|
+
* If a password is provided, the files will be zipped before uploading.
|
|
54
|
+
*
|
|
55
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
56
|
+
* @param {string} folderPath - The path of the folder to be uploaded.
|
|
57
|
+
* @param {Object} options - Optional parameters for the upload.
|
|
58
|
+
* @param {number} [options.uploadChunkSize] - The size of each chunk to be uploaded.
|
|
59
|
+
* @param {string} [options.password] - An optional password for encrypting the files.
|
|
60
|
+
* @returns {Promise<PromisedObservable<UploadFileStatus | UploadFolderStatus>>} - A promise that resolves to an observable that tracks the upload progress.
|
|
61
|
+
* @throws {Error} - Throws an error if the upload fails at any stage.
|
|
62
|
+
*/
|
|
63
|
+
export declare const uploadFolderFromFolderPath: (api: AutoDriveApi, folderPath: string, { uploadChunkSize, password }?: {
|
|
64
|
+
uploadChunkSize?: number;
|
|
65
|
+
password?: string;
|
|
66
|
+
}) => Promise<PromisedObservable<UploadFileStatus | UploadFolderStatus>>;
|
|
67
|
+
/**
|
|
68
|
+
* Uploads an entire folder to the server.
|
|
69
|
+
*
|
|
70
|
+
* This function retrieves all files within the specified folder,
|
|
71
|
+
* constructs a file tree representation, and initiates the upload
|
|
72
|
+
* process. It also handles optional compression of the files during
|
|
73
|
+
* the upload. If a password is provided, the files will be zipped
|
|
74
|
+
* before uploading.
|
|
75
|
+
*
|
|
76
|
+
* @param {AutoDriveApi} api - The API instance used to send requests.
|
|
77
|
+
* @param {FileList | File[]} fileList - The list of files to be uploaded.
|
|
78
|
+
* @param {Object} options - Options for the upload process.
|
|
79
|
+
* @param {number} [options.uploadChunkSize] - The size of each chunk to upload (optional).
|
|
80
|
+
* @param {string} [options.password] - The password for encryption (optional).
|
|
81
|
+
* @returns {PromisedObservable<UploadFileStatus | UploadFolderStatus>} - An observable that emits the upload status.
|
|
82
|
+
* @throws {Error} - Throws an error if the upload fails at any stage.
|
|
83
|
+
*/
|
|
84
|
+
export declare const uploadFolderFromInput: (api: AutoDriveApi, fileList: FileList | File[], { uploadChunkSize, password }?: {
|
|
85
|
+
uploadChunkSize?: number;
|
|
86
|
+
password?: string;
|
|
87
|
+
}) => Promise<PromisedObservable<UploadFileStatus | UploadFolderStatus>>;
|
|
88
|
+
/**
|
|
89
|
+
* Uploads a file within an existing folder upload session.
|
|
90
|
+
*
|
|
91
|
+
* @param {AutoDriveApi} api - The API instance to interact with the AutoDrive service.
|
|
92
|
+
* @param {string} uploadId - The ID of the folder upload session to which the file will be added.
|
|
93
|
+
* @param {string} filepath - The path of the file to be uploaded.
|
|
94
|
+
*
|
|
95
|
+
* @returns {Promise<void>} A promise that resolves when the file upload is complete.
|
|
96
|
+
*/
|
|
97
|
+
export declare const uploadFileWithinFolderUpload: (api: AutoDriveApi, uploadId: string, file: GenericFile, uploadChunkSize?: number) => PromisedObservable<UploadChunksStatus>;
|
|
98
|
+
/**
|
|
99
|
+
* Downloads a file from the AutoDrive service.
|
|
100
|
+
*
|
|
101
|
+
* @param {AutoDriveApi} api - The API instance to interact with the AutoDrive service.
|
|
102
|
+
* @param {string} cid - The CID of the file to be downloaded.
|
|
103
|
+
* @returns {Promise<ReadableStream<Uint8Array>>} A promise that resolves to a ReadableStream of the downloaded file.
|
|
104
|
+
*/
|
|
105
|
+
export declare const downloadFile: (api: AutoDriveApi, cid: string, password?: string) => Promise<AsyncIterable<Buffer>>;
|
|
106
|
+
export {};
|
|
107
|
+
//# sourceMappingURL=wrappers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrappers.d.ts","sourceRoot":"","sources":["../../src/api/wrappers.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAU3D,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAM9C,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAE9F,KAAK,iBAAiB,GAAG;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,CAAA;AAuBD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,sBAAsB,QAC5B,YAAY,YACP,MAAM,6BACkB,iBAAiB,oBACjC,MAAM,KACvB,kBAAkB,CAAC,gBAAgB,CAkBrC,CAAA;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,mBAAmB,QACzB,YAAY,QACX,IAAI,GAAG,WAAW,6BACU,iBAAiB,oBACjC,MAAM,KACvB,kBAAkB,CAAC,gBAAgB,CA8CrC,CAAA;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,0BAA0B,QAChC,YAAY,cACL,MAAM,kCACa;IAAE,eAAe,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,KAC7E,OAAO,CAAC,kBAAkB,CAAC,gBAAgB,GAAG,kBAAkB,CAAC,CA6DnE,CAAA;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,qBAAqB,QAC3B,YAAY,YACP,QAAQ,GAAG,IAAI,EAAE,kCACI;IAAE,eAAe,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,KAC7E,OAAO,CAAC,kBAAkB,CAAC,gBAAgB,GAAG,kBAAkB,CAAC,CA+DnE,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,4BAA4B,QAClC,YAAY,YACP,MAAM,QACV,WAAW,oBACC,MAAM,KACvB,kBAAkB,CAAC,kBAAkB,CAkBvC,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,QAClB,YAAY,OACZ,MAAM,aACA,MAAM,KAChB,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAoB/B,CAAA"}
|