Skip to content

Commit

Permalink
Merge pull request #201 from autonomys/update/enhance
Browse files Browse the repository at this point in the history
Solve devExp issues
  • Loading branch information
clostao authored Dec 11, 2024
2 parents 78863c8 + b2c74b1 commit 9aa9862
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
3 changes: 3 additions & 0 deletions packages/auto-drive/src/api/models/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ export interface GenericFile {
name: string
mimeType?: string
size: number
}

export interface GenericFileWithinFolder extends GenericFile {
path: string
}
12 changes: 7 additions & 5 deletions packages/auto-drive/src/api/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -64,9 +64,10 @@ const uploadFileChunks = (
export const uploadFileFromInput = (
api: AutoDriveApi,
file: File,
{ password, compression = true }: UploadFileOptions,
options: UploadFileOptions = {},
uploadChunkSize?: number,
): PromisedObservable<UploadFileStatus> => {
const { password = undefined, compression = true } = options
return new PromisedObservable<UploadFileStatus>(async (subscriber) => {
const { stringToCid, compressFile, CompressionAlgorithm, encryptFile, EncryptionAlgorithm } =
await import('@autonomys/auto-dag-data')
Expand Down Expand Up @@ -135,9 +136,11 @@ export const uploadFileFromInput = (
export const uploadFile = (
api: AutoDriveApi,
file: GenericFile,
{ password, compression = true }: UploadFileOptions,
options: UploadFileOptions = {},
uploadChunkSize?: number,
): PromisedObservable<UploadFileStatus> => {
const { password = undefined, compression = true } = options

return new PromisedObservable<UploadFileStatus>(async (subscriber) => {
const { stringToCid, compressFile, CompressionAlgorithm, encryptFile, EncryptionAlgorithm } =
await import('@autonomys/auto-dag-data')
Expand Down Expand Up @@ -226,7 +229,6 @@ export const uploadFolderFromInput = async (
name: `${name}.zip`,
mimeType: 'application/zip',
size: zipBlob.size,
path: name,
},
{
password,
Expand Down Expand Up @@ -284,7 +286,7 @@ export const uploadFolderFromInput = async (
export const uploadFileWithinFolderUpload = (
api: AutoDriveApi,
uploadId: string,
file: GenericFile,
file: GenericFileWithinFolder,
uploadChunkSize?: number,
): PromisedObservable<UploadChunksStatus> => {
return new PromisedObservable<UploadChunksStatus>(async (subscriber) => {
Expand Down
9 changes: 4 additions & 5 deletions packages/auto-drive/src/fs/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { 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'
Expand Down Expand Up @@ -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<UploadFileStatus> => {
const { password = undefined, compression = true } = options
const name = filePath.split('/').pop()!

return uploadFile(
Expand All @@ -43,7 +44,6 @@ export const uploadFileFromFilepath = (
name,
mimeType: mime.lookup(name) || undefined,
size: fs.statSync(filePath).size,
path: filePath,
},
{
password,
Expand Down Expand Up @@ -90,7 +90,6 @@ export const uploadFolderFromFolderPath = async (
name: `${name}.zip`,
mimeType: 'application/zip',
size: zipBlob.size,
path: name,
},
{
password,
Expand All @@ -111,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,
Expand Down

0 comments on commit 9aa9862

Please sign in to comment.