This repository was archived by the owner on Sep 20, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import {Command, IOHandler, ArgType} from '../command'; | ||
import {ShellApi} from '../shellapi'; | ||
import {Path} from 'src/app/api/files/path'; | ||
import {File} from 'src/app/api/files/file'; | ||
|
||
export class Dl extends Command { | ||
constructor(shellApi: ShellApi) { | ||
super('dl', shellApi); | ||
this.addDescription('download a file to your own device'); | ||
this.addPositionalArgument({name: 'source', argType: ArgType.FILE}); | ||
this.addPositionalArgument({name: 'destination'}); | ||
} | ||
|
||
async run(iohandler: IOHandler): Promise<number> { | ||
let srcFile: File; | ||
let dstPath: Path; | ||
const ownUuid = this.shellApi.websocket.account.uuid; | ||
const activeUuid = this.shellApi.activeDevice['uuid']; | ||
try { | ||
const srcPath = Path.fromString(iohandler.positionalArgs[0], this.shellApi.working_dir); | ||
srcFile = await this.shellApi.fileService.getFromPath(this.shellApi.activeDevice['uuid'], srcPath).toPromise(); | ||
} | ||
catch { | ||
iohandler.stderr('The source file was not found'); | ||
return 1; | ||
} | ||
if (srcFile.is_directory) { | ||
iohandler.stderr('Cannot download a directory'); | ||
return 1; | ||
} | ||
try { | ||
dstPath = Path.fromString(iohandler.positionalArgs[1], this.shellApi.working_dir); | ||
} catch { | ||
iohandler.stderr('The specified destination path is not valid'); | ||
return 1; | ||
} | ||
// check if the file already exists | ||
// TODO | ||
// const file = this.shellApi.fileService.move() | ||
|
||
} | ||
} |