mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
chore: lint
This commit is contained in:
parent
f1279666b5
commit
4717e035ee
173 changed files with 1388 additions and 1627 deletions
|
|
@ -5,61 +5,73 @@ const CDN = 'https://cdn.jsdelivr.net/gh/cloudcmd/user-menu@1.2.4';
|
|||
|
||||
module.exports = {
|
||||
'__settings': {
|
||||
select: [
|
||||
RENAME_FILE,
|
||||
],
|
||||
select: [RENAME_FILE],
|
||||
run: false,
|
||||
},
|
||||
[`F2 - ${RENAME_FILE}`]: async ({DOM}) => {
|
||||
await DOM.renameCurrent();
|
||||
},
|
||||
|
||||
|
||||
'F6 - Copy URL to current file': async ({DOM}) => {
|
||||
const {copyURLToCurrentFile} = await import(`${CDN}/menu/copy-url-to-current-file.js`);
|
||||
await copyURLToCurrentFile({DOM});
|
||||
await copyURLToCurrentFile({
|
||||
DOM,
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
'R - cd /': async ({CloudCmd}) => {
|
||||
await CloudCmd.changeDir('/');
|
||||
},
|
||||
'Y - Convert YouTube to MP3': async ({CloudCmd, DOM}) => {
|
||||
const {convertYouTubeToMp3} = await import(`${CDN}/menu/convert-youtube-to-mp3.js`);
|
||||
await convertYouTubeToMp3({CloudCmd, DOM});
|
||||
await convertYouTubeToMp3({
|
||||
CloudCmd,
|
||||
DOM,
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
'F - Convert flac to mp3 [ffmpeg]': async ({CloudCmd, DOM}) => {
|
||||
const {convertFlacToMp3} = await import(`${CDN}/menu/ffmpeg.js`);
|
||||
await convertFlacToMp3({CloudCmd, DOM});
|
||||
await convertFlacToMp3({
|
||||
CloudCmd,
|
||||
DOM,
|
||||
});
|
||||
},
|
||||
'M - Convert mp4 to mp3 [ffmpeg]': async ({CloudCmd, DOM}) => {
|
||||
const {convertMp4ToMp3} = await import(`${CDN}/menu/ffmpeg.js`);
|
||||
await convertMp4ToMp3({CloudCmd, DOM});
|
||||
await convertMp4ToMp3({
|
||||
CloudCmd,
|
||||
DOM,
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
'O - Convert mov to mp3 [ffmpeg]': async ({CloudCmd, DOM}) => {
|
||||
const {convertMovToMp3} = await import(`${CDN}/menu/ffmpeg.js`);
|
||||
await convertMovToMp3({CloudCmd, DOM});
|
||||
await convertMovToMp3({
|
||||
CloudCmd,
|
||||
DOM,
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
'C - Create User Menu File': async ({DOM, CloudCmd}) => {
|
||||
const {
|
||||
Dialog,
|
||||
CurrentInfo,
|
||||
} = DOM;
|
||||
const {Dialog, CurrentInfo} = DOM;
|
||||
|
||||
const currentFile = DOM.getCurrentByName('.cloudcmd.menu.js');
|
||||
|
||||
|
||||
if (currentFile) {
|
||||
const [cancel] = await Dialog.confirm(`Looks like file '.cloudcmd.menu.js' already exists. Overwrite?`);
|
||||
|
||||
|
||||
if (cancel)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const {dirPath} = CurrentInfo;
|
||||
const path = `${dirPath}.cloudcmd.menu.js`;
|
||||
const {prefix} = CloudCmd;
|
||||
|
||||
const data = await readDefaultMenu({prefix});
|
||||
|
||||
const data = await readDefaultMenu({
|
||||
prefix,
|
||||
});
|
||||
await createDefaultMenu({
|
||||
path,
|
||||
data,
|
||||
|
|
@ -74,25 +86,25 @@ module.exports = {
|
|||
getCurrentByName,
|
||||
selectFile,
|
||||
} = DOM;
|
||||
|
||||
|
||||
const {
|
||||
files,
|
||||
filesPassive,
|
||||
panel,
|
||||
panelPassive,
|
||||
} = CurrentInfo;
|
||||
|
||||
|
||||
const names = getFilenames(files);
|
||||
const namesPassive = getFilenames(filesPassive);
|
||||
|
||||
|
||||
const selectedNames = compare(names, namesPassive);
|
||||
const selectedNamesPassive = compare(namesPassive, names);
|
||||
|
||||
|
||||
selectNames(selectedNames, panel, {
|
||||
selectFile,
|
||||
getCurrentByName,
|
||||
});
|
||||
|
||||
|
||||
selectNames(selectedNamesPassive, panelPassive, {
|
||||
selectFile,
|
||||
getCurrentByName,
|
||||
|
|
@ -102,19 +114,19 @@ module.exports = {
|
|||
|
||||
async function createDefaultMenu({path, data, DOM, CloudCmd}) {
|
||||
const {IO} = DOM;
|
||||
|
||||
|
||||
await IO.write(path, data);
|
||||
await CloudCmd.refresh();
|
||||
|
||||
|
||||
DOM.setCurrentByName('.cloudcmd.menu.js');
|
||||
|
||||
|
||||
await CloudCmd.EditFile.show();
|
||||
}
|
||||
|
||||
async function readDefaultMenu({prefix}) {
|
||||
const res = await fetch(`${prefix}/api/v1/user-menu/default`);
|
||||
const data = await res.text();
|
||||
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
|
@ -129,14 +141,13 @@ function selectNames(names, panel, {selectFile, getCurrentByName}) {
|
|||
module.exports._compare = compare;
|
||||
function compare(a, b) {
|
||||
const result = [];
|
||||
|
||||
|
||||
for (const el of a) {
|
||||
if (b.includes(el))
|
||||
continue;
|
||||
|
||||
|
||||
result.push(el);
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ test('cloudcmd: static: user menu: R', (t) => {
|
|||
};
|
||||
|
||||
const fn = defaultMenu[name];
|
||||
|
||||
fn({
|
||||
CloudCmd,
|
||||
});
|
||||
|
|
@ -48,7 +49,7 @@ test('cloudcmd: static: user menu: R', (t) => {
|
|||
test('cloudcmd: static: user menu: F6', async (t) => {
|
||||
const name = 'F6 - Copy URL to current file';
|
||||
const DOM = {};
|
||||
|
||||
|
||||
const fn = defaultMenu[name];
|
||||
const [error] = await tryToCatch(fn, {
|
||||
DOM,
|
||||
|
|
@ -61,7 +62,7 @@ test('cloudcmd: static: user menu: F6', async (t) => {
|
|||
test('cloudcmd: static: user menu: Y', async (t) => {
|
||||
const name = 'Y - Convert YouTube to MP3';
|
||||
const DOM = {};
|
||||
|
||||
|
||||
const fn = defaultMenu[name];
|
||||
const [error] = await tryToCatch(fn, {
|
||||
DOM,
|
||||
|
|
@ -74,7 +75,7 @@ test('cloudcmd: static: user menu: Y', async (t) => {
|
|||
test('cloudcmd: static: user menu: F', async (t) => {
|
||||
const name = 'F - Convert flac to mp3 [ffmpeg]';
|
||||
const DOM = {};
|
||||
|
||||
|
||||
const fn = defaultMenu[name];
|
||||
const [error] = await tryToCatch(fn, {
|
||||
DOM,
|
||||
|
|
@ -87,7 +88,7 @@ test('cloudcmd: static: user menu: F', async (t) => {
|
|||
test('cloudcmd: static: user menu: M', async (t) => {
|
||||
const name = 'M - Convert mp4 to mp3 [ffmpeg]';
|
||||
const DOM = {};
|
||||
|
||||
|
||||
const fn = defaultMenu[name];
|
||||
const [error] = await tryToCatch(fn, {
|
||||
DOM,
|
||||
|
|
@ -100,7 +101,7 @@ test('cloudcmd: static: user menu: M', async (t) => {
|
|||
test('cloudcmd: static: user menu: O', async (t) => {
|
||||
const name = 'O - Convert mov to mp3 [ffmpeg]';
|
||||
const DOM = {};
|
||||
|
||||
|
||||
const fn = defaultMenu[name];
|
||||
const [error] = await tryToCatch(fn, {
|
||||
DOM,
|
||||
|
|
@ -131,10 +132,12 @@ test('cloudcmd: static: user menu: C: exists: ok', async (t) => {
|
|||
const name = 'C - Create User Menu File';
|
||||
const DOM = getDOM();
|
||||
const CloudCmd = getCloudCmd();
|
||||
|
||||
const {
|
||||
Dialog,
|
||||
getCurrentByName,
|
||||
} = DOM;
|
||||
|
||||
const {confirm} = Dialog;
|
||||
const {write} = DOM.IO;
|
||||
|
||||
|
|
@ -156,21 +159,23 @@ test('cloudcmd: static: user menu: C: exists: cancel', async (t) => {
|
|||
const name = 'C - Create User Menu File';
|
||||
const DOM = getDOM();
|
||||
const CloudCmd = getCloudCmd();
|
||||
|
||||
const {
|
||||
Dialog,
|
||||
getCurrentByName,
|
||||
} = DOM;
|
||||
|
||||
const {confirm} = Dialog;
|
||||
const {write} = DOM.IO;
|
||||
|
||||
|
||||
getCurrentByName.returns({});
|
||||
confirm.resolves([Error('cancel')]);
|
||||
|
||||
|
||||
await defaultMenu[name]({
|
||||
DOM,
|
||||
CloudCmd,
|
||||
});
|
||||
|
||||
|
||||
t.notCalled(write);
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -298,9 +303,7 @@ test('cloudcmd: static: user menu: compare directories: select names: compare',
|
|||
const b = [1, 3];
|
||||
|
||||
const result = _compare(a, b);
|
||||
const expected = [
|
||||
2,
|
||||
];
|
||||
const expected = [2];
|
||||
|
||||
t.deepEqual(result, expected);
|
||||
t.end();
|
||||
|
|
@ -342,4 +345,3 @@ function getCloudCmd() {
|
|||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue