wget, mkdir commands on resume

This commit is contained in:
b1ek 2023-03-16 16:35:49 +10:00
parent 25eb62968b
commit 589fd08c61
Signed by: blek
GPG Key ID: 14546221E3595D0C
3 changed files with 92 additions and 1 deletions

View File

@ -5,8 +5,9 @@ let cmds = {
'help': require('./cmds'), 'help': require('./cmds'),
'ls': require('./ls'), 'ls': require('./ls'),
'skills': require('./skills'), 'skills': require('./skills'),
'mkdir': require('./mkdir'),
'wget': require('./wget'),
// alias l='ls -l' // alias l='ls -l'
'l': (a,t) => {require('./ls')([...a, '-l'], t)}, 'l': (a,t) => {require('./ls')([...a, '-l'], t)},
}; };

View File

@ -0,0 +1,26 @@
import { Terminal } from 'xterm';
const fs = require('../fs');
/**
* @param {string[]} argv
* @param {Terminal} terminal
*/
module.exports = (argv, terminal) => {
if (argv.indexOf('--help') != -1) {
terminal.write(`
Usage: ${argv[0]} [DIRECTORY] [-p]
Create a directory
-p Create parent directories
`);
return;
}
const parents = argv.indexOf('-p') != -1;
const dir = argv[1];
try {
fs.mkdirSync(dir, {recursive: parents});
} catch (err) {
terminal.write(`${argv[0]}: can't create ${dir}: ${err}`);
}
}

View File

@ -0,0 +1,64 @@
import { Terminal } from 'xterm';
const fs = require('../fs');
/**
* @param {string[]} argv
* @param {Terminal} terminal
*/
module.exports = async (argv, terminal) => {
if (argv.indexOf('--help') != -1) {
terminal.write(`
Usage: ${argv[0]} [URL] [-O out.file] [-V] [-Q] [-s]
--help Show this help
-O [FILE] Specify output file
-V Verbose mode
-Q Quiet mode (default)
`);
return;
}
const url = argv[1];
let filepath = url.split('/')[url.split('/').length - 1];
if (argv.indexOf('-O') != -1) {
if (argv.indexOf('-O') + 1 == argv.length) {
terminal.writeln(`${argv[0]}: missing output file`);
return;
}
filepath = argv[argv.indexOf('-O') + 1]
return;
}
function progress(p) {
let total = p.total;
if (total == 0)
total = '?'
terminal.write(`\rDownloading... ${p.loaded}/${total}`);
}
function write(file) {
}
let file;
let req = new XMLHttpRequest();
req.open('GET', 'http://cors.blek.codes/' + url, true);
req.responseType = 'arraybuffer';
req.onprogress = progress;
req.onload = (e) => {
if (e.type == 'load') {
let enc = new TextDecoder("utf-8");
terminal.write(enc.decode(req.response));
}
};
req.send();
const delay = t => new Promise(resolve => setTimeout(resolve, t));
while(req.readyState == 1) await delay(250);
return;
}