Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Akida31 committed May 31, 2021
1 parent cf3cc5d commit 509ece6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/app/shell/builtins/builtins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {Cd} from './cd';
import {Ls} from './ls';
import {Clear} from './clear';
import {Exit} from './exit';
import {Dl} from './dl';

export const BUILTINS = [Status, Hostname, Miner, Cd, Ls, Clear, Exit];
export const BUILTINS = [Status, Hostname, Miner, Cd, Ls, Clear, Exit, Dl];

42 changes: 42 additions & 0 deletions src/app/shell/builtins/dl.ts
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()

}
}

0 comments on commit 509ece6

Please sign in to comment.