From 8126b51831af2bbd83a45efce6d2edca214cfb89 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 17 Jan 2023 18:10:09 +0200 Subject: [PATCH] feature: static: user-menu: add recipes from Cookbook --- static/user-menu.js | 34 +++++++++++++++++++++++++ static/user-menu.spec.js | 54 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/static/user-menu.js b/static/user-menu.js index 2b4b2625..c9126895 100644 --- a/static/user-menu.js +++ b/static/user-menu.js @@ -1,6 +1,7 @@ 'use strict'; const RENAME_FILE = 'Rename file'; +const CDN = 'https://cdn.jsdelivr.net/gh/cloudcmd/user-menu@'; module.exports = { '__settings': { @@ -13,12 +14,45 @@ module.exports = { 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}) => { + 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 {dirPath} = CurrentInfo; const path = `${dirPath}.cloudcmd.menu.js`; const {prefix} = CloudCmd; + const data = await readDefaultMenu({prefix}); await createDefaultMenu({ path, diff --git a/static/user-menu.spec.js b/static/user-menu.spec.js index 91040308..ea5e0a69 100644 --- a/static/user-menu.spec.js +++ b/static/user-menu.spec.js @@ -9,8 +9,8 @@ const defaultMenu = require('./user-menu'); const test = autoGlobals(require('supertape')); const {create} = autoGlobals; - const {_data} = defaultMenu; + const reject = wraptile(async (a) => { throw Error(a); }); @@ -29,6 +29,58 @@ test('cloudcmd: static: user menu: Rename', async (t) => { 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) => { const name = 'C - Create User Menu File'; const DOM = getDOM();