feature: static: user-menu: add recipes from Cookbook

This commit is contained in:
coderaiser 2023-01-17 18:10:09 +02:00
parent 1309d825e4
commit 8126b51831
2 changed files with 87 additions and 1 deletions

View file

@ -1,6 +1,7 @@
'use strict'; 'use strict';
const RENAME_FILE = 'Rename file'; const RENAME_FILE = 'Rename file';
const CDN = 'https://cdn.jsdelivr.net/gh/cloudcmd/user-menu@';
module.exports = { module.exports = {
'__settings': { '__settings': {
@ -13,12 +14,45 @@ module.exports = {
await DOM.renameCurrent(); await DOM.renameCurrent();
}, },
'F6 - Copy URL to current file': async ({DOM}) => {
const {copyURLToCurrentFile} = await import(`${CDN}@1.1.0/menu/copy-url-to-current-file.js`);
await copyURLToCurrentFile({DOM});
},
'R - cd /': async ({CloudCmd}) => {
await CloudCmd.changeDir('/');
},
'Y - Convert YouTube to MP3': async ({CloudCmd, DOM}) => {
const {convertYouTubeToMp3} = await import(`${CDN}@v1.1.0/menu/convert-youtube-to-mp3.js`);
await convertYouTubeToMp3({CloudCmd, DOM});
},
'F - Convert flac to mp3 [ffmpeg]': async ({CloudCmd, DOM}) => {
const {convertFlacToMp3} = await import(`${CDN}@v1.1.0/menu/ffmpeg.js`);
await convertFlacToMp3({CloudCmd, DOM});
},
'M - Convert mpeg to mp3 [ffmpeg]': async ({CloudCmd, DOM}) => {
const {convertMp4ToMp3} = await import(`${CDN}@v1.1.0/menu/ffmpeg.js`);
await convertMp4ToMp3({CloudCmd, DOM});
},
'C - Create User Menu File': async ({DOM, CloudCmd}) => { 'C - Create User Menu File': async ({DOM, CloudCmd}) => {
const {Dialog} = 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 {CurrentInfo} = DOM; const {CurrentInfo} = DOM;
const {dirPath} = CurrentInfo; const {dirPath} = CurrentInfo;
const path = `${dirPath}.cloudcmd.menu.js`; const path = `${dirPath}.cloudcmd.menu.js`;
const {prefix} = CloudCmd; const {prefix} = CloudCmd;
const data = await readDefaultMenu({prefix}); const data = await readDefaultMenu({prefix});
await createDefaultMenu({ await createDefaultMenu({
path, path,

View file

@ -9,8 +9,8 @@ const defaultMenu = require('./user-menu');
const test = autoGlobals(require('supertape')); const test = autoGlobals(require('supertape'));
const {create} = autoGlobals; const {create} = autoGlobals;
const {_data} = defaultMenu; const {_data} = defaultMenu;
const reject = wraptile(async (a) => { const reject = wraptile(async (a) => {
throw Error(a); throw Error(a);
}); });
@ -29,6 +29,58 @@ test('cloudcmd: static: user menu: Rename', async (t) => {
t.end(); t.end();
}); });
test('cloudcmd: static: user menu: R', (t) => {
const name = 'R - cd /';
const changeDir = stub();
const CloudCmd = {
changeDir,
};
const fn = defaultMenu[name];
fn({
CloudCmd,
});
t.calledWith(changeDir, ['/']);
t.end();
});
test('cloudcmd: static: user menu: F6', (t) => {
const name = 'F6 - Copy URL to current file';
const fn = defaultMenu[name];
t.ok(fn);
t.end();
});
test('cloudcmd: static: user menu: Y', (t) => {
const name = 'Y - Convert YouTube to MP3';
const fn = defaultMenu[name];
t.ok(fn);
t.end();
});
test('cloudcmd: static: user menu: F', (t) => {
const name = 'F - Convert flac to mp3 [ffmpeg]';
const fn = defaultMenu[name];
t.ok(fn);
t.end();
});
test('cloudcmd: static: user menu: M', (t) => {
const name = 'M - Convert mpeg to mp3 [ffmpeg]';
const fn = defaultMenu[name];
t.ok(fn);
t.end();
});
test('cloudcmd: static: user menu: IO.write', async (t) => { test('cloudcmd: static: user menu: IO.write', async (t) => {
const name = 'C - Create User Menu File'; const name = 'C - Create User Menu File';
const DOM = getDOM(); const DOM = getDOM();