From a6ed641996ba57a34d61c22ba9194d5cf8c6aa11 Mon Sep 17 00:00:00 2001 From: Carlos Lostao Date: Wed, 11 Dec 2024 16:11:00 +0100 Subject: [PATCH 1/4] update: solve https://github.com/autonomys/auto-sdk/issues/197 --- packages/auto-drive/src/api/wrappers.ts | 7 +++++-- packages/auto-drive/src/fs/wrappers.ts | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/auto-drive/src/api/wrappers.ts b/packages/auto-drive/src/api/wrappers.ts index 2a86d66..a1c1c06 100644 --- a/packages/auto-drive/src/api/wrappers.ts +++ b/packages/auto-drive/src/api/wrappers.ts @@ -64,9 +64,10 @@ const uploadFileChunks = ( export const uploadFileFromInput = ( api: AutoDriveApi, file: File, - { password, compression = true }: UploadFileOptions, + options: UploadFileOptions = {}, uploadChunkSize?: number, ): PromisedObservable => { + const { password = undefined, compression = true } = options return new PromisedObservable(async (subscriber) => { const { stringToCid, compressFile, CompressionAlgorithm, encryptFile, EncryptionAlgorithm } = await import('@autonomys/auto-dag-data') @@ -135,9 +136,11 @@ export const uploadFileFromInput = ( export const uploadFile = ( api: AutoDriveApi, file: GenericFile, - { password, compression = true }: UploadFileOptions, + options: UploadFileOptions = {}, uploadChunkSize?: number, ): PromisedObservable => { + const { password = undefined, compression = true } = options + return new PromisedObservable(async (subscriber) => { const { stringToCid, compressFile, CompressionAlgorithm, encryptFile, EncryptionAlgorithm } = await import('@autonomys/auto-dag-data') diff --git a/packages/auto-drive/src/fs/wrappers.ts b/packages/auto-drive/src/fs/wrappers.ts index 8c675bd..fd3b515 100644 --- a/packages/auto-drive/src/fs/wrappers.ts +++ b/packages/auto-drive/src/fs/wrappers.ts @@ -31,9 +31,10 @@ import { constructZipFromTreeAndFileSystemPaths, getFiles } from './utils.js' export const uploadFileFromFilepath = ( api: AutoDriveApi, filePath: string, - { password, compression = true }: UploadFileOptions, + options: UploadFileOptions = {}, uploadChunkSize?: number, ): PromisedObservable => { + const { password = undefined, compression = true } = options const name = filePath.split('/').pop()! return uploadFile( From 31da6babd0393fd44c15b4aa9736d2123cf3e489 Mon Sep 17 00:00:00 2001 From: Carlos Lostao Date: Wed, 11 Dec 2024 16:15:36 +0100 Subject: [PATCH 2/4] chore: separate single generic file and within folder --- packages/auto-drive/src/api/models/file.ts | 3 +++ packages/auto-drive/src/api/wrappers.ts | 5 ++--- packages/auto-drive/src/fs/wrappers.ts | 6 ++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/auto-drive/src/api/models/file.ts b/packages/auto-drive/src/api/models/file.ts index 57e3f14..eb982b3 100644 --- a/packages/auto-drive/src/api/models/file.ts +++ b/packages/auto-drive/src/api/models/file.ts @@ -3,5 +3,8 @@ export interface GenericFile { name: string mimeType?: string size: number +} + +export interface GenericFileWithinFolder extends GenericFile { path: string } diff --git a/packages/auto-drive/src/api/wrappers.ts b/packages/auto-drive/src/api/wrappers.ts index a1c1c06..fd86890 100644 --- a/packages/auto-drive/src/api/wrappers.ts +++ b/packages/auto-drive/src/api/wrappers.ts @@ -14,7 +14,7 @@ import { uploadFileChunk, } from './calls/index' import { AutoDriveApi } from './connection' -import { GenericFile } from './models/file' +import { GenericFile, GenericFileWithinFolder } from './models/file' import { constructFromInput, constructZipBlobFromTreeAndPaths } from './models/folderTree' import { UploadChunksStatus, UploadFileStatus, UploadFolderStatus } from './models/uploads' @@ -229,7 +229,6 @@ export const uploadFolderFromInput = async ( name: `${name}.zip`, mimeType: 'application/zip', size: zipBlob.size, - path: name, }, { password, @@ -287,7 +286,7 @@ export const uploadFolderFromInput = async ( export const uploadFileWithinFolderUpload = ( api: AutoDriveApi, uploadId: string, - file: GenericFile, + file: GenericFileWithinFolder, uploadChunkSize?: number, ): PromisedObservable => { return new PromisedObservable(async (subscriber) => { diff --git a/packages/auto-drive/src/fs/wrappers.ts b/packages/auto-drive/src/fs/wrappers.ts index fd3b515..a3c6a1c 100644 --- a/packages/auto-drive/src/fs/wrappers.ts +++ b/packages/auto-drive/src/fs/wrappers.ts @@ -2,7 +2,7 @@ import fs from 'fs' import mime from 'mime-types' import { AutoDriveApi } from '../api/connection.js' import { completeUpload, createFolderUpload } from '../api/index.js' -import { GenericFile } from '../api/models/file.js' +import { GenericFile, GenericFileWithinFolder } from '../api/models/file.js' import { constructFromFileSystemEntries } from '../api/models/folderTree.js' import { UploadFileStatus, UploadFolderStatus } from '../api/models/uploads.js' import { uploadFile, UploadFileOptions, uploadFileWithinFolderUpload } from '../api/wrappers.js' @@ -44,7 +44,6 @@ export const uploadFileFromFilepath = ( name, mimeType: mime.lookup(name) || undefined, size: fs.statSync(filePath).size, - path: filePath, }, { password, @@ -91,7 +90,6 @@ export const uploadFolderFromFolderPath = async ( name: `${name}.zip`, mimeType: 'application/zip', size: zipBlob.size, - path: name, }, { password, @@ -112,7 +110,7 @@ export const uploadFolderFromFolderPath = async ( }, }) - const genericFiles: GenericFile[] = files.map((file) => ({ + const genericFiles: GenericFileWithinFolder[] = files.map((file) => ({ read: () => fs.createReadStream(file), name: file.split('/').pop()!, mimeType: mime.lookup(file.split('/').pop()!) || undefined, From 8acc1d6fc5c28825cca26282bf2ce57f7428bf2a Mon Sep 17 00:00:00 2001 From: Carlos Lostao Date: Wed, 11 Dec 2024 16:21:29 +0100 Subject: [PATCH 3/4] chore: remove unused import --- packages/auto-drive/src/fs/wrappers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/auto-drive/src/fs/wrappers.ts b/packages/auto-drive/src/fs/wrappers.ts index a3c6a1c..c6284fe 100644 --- a/packages/auto-drive/src/fs/wrappers.ts +++ b/packages/auto-drive/src/fs/wrappers.ts @@ -2,7 +2,7 @@ import fs from 'fs' import mime from 'mime-types' import { AutoDriveApi } from '../api/connection.js' import { completeUpload, createFolderUpload } from '../api/index.js' -import { GenericFile, GenericFileWithinFolder } from '../api/models/file.js' +import { GenericFileWithinFolder } from '../api/models/file.js' import { constructFromFileSystemEntries } from '../api/models/folderTree.js' import { UploadFileStatus, UploadFolderStatus } from '../api/models/uploads.js' import { uploadFile, UploadFileOptions, uploadFileWithinFolderUpload } from '../api/wrappers.js' From e19f65e4630de7ec0ce138efffe6b923f87b50f5 Mon Sep 17 00:00:00 2001 From: Carlos Lostao Date: Wed, 11 Dec 2024 16:44:58 +0100 Subject: [PATCH 4/4] chore: fix example build problem --- examples/next/src/components/actions/balance.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/next/src/components/actions/balance.tsx b/examples/next/src/components/actions/balance.tsx index 89a576f..856c507 100644 --- a/examples/next/src/components/actions/balance.tsx +++ b/examples/next/src/components/actions/balance.tsx @@ -36,7 +36,7 @@ export const Balance = () => { {balanceFree && (
- Free: {parseTokenAmount(balanceFree)} tSSC + Free: {String(parseTokenAmount(balanceFree))} tSSC
)}