@fairdatasociety/fdp-cli
Version:
CLI tool for FDP-Storage
45 lines (37 loc) • 1.25 kB
text/typescript
import { Argument, LeafCommand } from 'furious-commander'
import { Message } from '../../utils/message'
import { FileCommand } from './file-command'
import { readFileSync } from 'fs'
import { expectFile, getString } from '../../utils'
export class Upload extends FileCommand implements LeafCommand {
public readonly name = 'upload'
public readonly description = 'Upload a file'
public postageBatchRequired = true
public pathSource!: string
public pathDestination!: string
public async run(): Promise<void> {
await super.init()
try {
expectFile(this.pathSource)
const data = readFileSync(this.pathSource)
await this.fdpStorage.file.uploadData(
await this.getCurrentPodName(this.account, this.pod),
this.pathDestination,
data,
)
this.console.log(Message.fileUploadedSuccessfully(this.pathSource, this.pathDestination))
} catch (error: unknown) {
this.console.log(Message.fileUploadError(getString(error, 'message')))
}
}
}