diff --git a/client/key/index.spec.js b/client/key/index.spec.js index 2a61660c..aec4bfe3 100644 --- a/client/key/index.spec.js +++ b/client/key/index.spec.js @@ -38,7 +38,6 @@ test('cloudcmd: client: key: enable vim', async (t) => { }); test('cloudcmd: client: key: disable vim', async (t) => { - const vim = stub(); const _config = stub(); const {_listener, setBind} = reRequire('.'); diff --git a/client/modules/view.js b/client/modules/view.js index b000c356..aefb1d65 100644 --- a/client/modules/view.js +++ b/client/modules/view.js @@ -79,6 +79,7 @@ const Config = { title: {}, }, }; +module.exports._Config = Config; module.exports.init = async () => { await loadAll(); @@ -126,6 +127,9 @@ async function show(data, options) { default: return viewFile(); + case 'html': + return viewHtml(path); + case 'image': return viewImage(prefixURL); @@ -137,7 +141,8 @@ async function show(data, options) { } } -function viewPDF(src) { +module.exports._createIframe = createIframe; +function createIframe(src) { const element = createElement('iframe', { src, width: '100%', @@ -147,6 +152,15 @@ function viewPDF(src) { element.addEventListener('load', () => { element.contentWindow.addEventListener('keydown', listener); }); +} + +module.exports._viewHtml = viewHtml; +function viewHtml(src) { + modal.open(createIframe(src), Config); +} + +function viewPDF(src) { + const element = createIframe(src); const options = assign({}, Config); @@ -285,7 +299,8 @@ function isVideo(name) { return /\.(mp4|avi|webm)$/i.test(name); } -const isPDF = (name) => /\.(pdf)$/i.test(name); +const isPDF = (name) => /\.pdf$/i.test(name); +const isHTML = (name) => /\.html/.test(name); function getType(name) { if (isPDF(name)) @@ -296,6 +311,9 @@ function getType(name) { if (isMedia(name)) return 'media'; + + if (isHTML(name)) + return 'html'; } async function getMediaElement(src) { diff --git a/client/modules/view.spec.js b/client/modules/view.spec.js index 027b1461..51f8a998 100644 --- a/client/modules/view.spec.js +++ b/client/modules/view.spec.js @@ -2,8 +2,11 @@ require('css-modules-require-hook/preset'); -const test = require('supertape'); -const {reRequire} = require('mock-require'); +const autoGlobals = require('auto-globals'); +const test = autoGlobals(require('supertape')); +const stub = require('@cloudcmd/stub'); +const mockRequire = require('mock-require'); +const {reRequire} = mockRequire; test('cloudcmd: client: view: initConfig', (t) => { let config; @@ -50,3 +53,30 @@ test('cloudcmd: client: view: initConfig: no options', (t) => { t.end(); }); +test('cloudcmd: client: view: html', (t) => { + const {CloudCmd, DOM} = global; + + global.CloudCmd = {}; + global.DOM = {}; + const open = stub(); + + mockRequire('@cloudcmd/modal', { + open, + }); + + const { + _viewHtml, + _createIframe, + _Config, + } = reRequire('./view'); + + const src = '/hello.html'; + _viewHtml(src); + + global.CloudCmd = CloudCmd; + global.DOM = DOM; + + t.calledWith(open, [_createIframe(src), _Config]); + t.end(); +}); + diff --git a/common/cloudfunc.js b/common/cloudfunc.js index e4cc5b46..6824be82 100644 --- a/common/cloudfunc.js +++ b/common/cloudfunc.js @@ -259,7 +259,7 @@ function getSize(file) { type, } = file; - if (/^directory$/.test(type)) + if (type === 'directory') return '<dir>'; if (/link/.test(type))