mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-17 16:38:18 +00:00
feature: common: cloudfunc: get rid of bas64
This commit is contained in:
parent
e36de00ce8
commit
add31607f9
5 changed files with 14 additions and 80 deletions
|
|
@ -1,19 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
module.exports.btoa = (str) => {
|
||||
if (typeof btoa === 'function')
|
||||
return btoa(str);
|
||||
|
||||
return Buffer
|
||||
.from(str)
|
||||
.toString('base64');
|
||||
};
|
||||
|
||||
module.exports.atob = (str) => {
|
||||
if (typeof atob === 'function')
|
||||
return atob(str);
|
||||
|
||||
return Buffer
|
||||
.from(str, 'base64')
|
||||
.toString('binary');
|
||||
};
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
const {test, stub} = require('supertape');
|
||||
const {btoa, atob} = require('./base64');
|
||||
|
||||
test('btoa: browser', (t) => {
|
||||
const btoaOriginal = globalThis.btoa;
|
||||
const btoaStub = stub();
|
||||
const str = 'hello';
|
||||
|
||||
globalThis.btoa = btoaStub;
|
||||
|
||||
btoa(str);
|
||||
globalThis.btoa = btoaOriginal;
|
||||
|
||||
t.calledWith(btoaStub, [str], 'should call globalThis.btoa');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('btoa: node', (t) => {
|
||||
const str = 'hello';
|
||||
const expected = 'aGVsbG8=';
|
||||
|
||||
const result = btoa(str);
|
||||
|
||||
t.equal(result, expected, 'should encode base64');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('atob: browser', (t) => {
|
||||
const atobOriginal = globalThis.atob;
|
||||
const atobStub = stub();
|
||||
|
||||
const str = 'hello';
|
||||
|
||||
globalThis.atob = atobStub;
|
||||
|
||||
atob(str);
|
||||
|
||||
globalThis.atob = atobOriginal;
|
||||
|
||||
t.calledWith(atobStub, [str], 'should call globalThis.btoa');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('atob: node', (t) => {
|
||||
const str = 'aGVsbG8=';
|
||||
const expected = 'hello';
|
||||
|
||||
const result = atob(str);
|
||||
|
||||
t.equal(result, expected, 'should encode base64');
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -4,7 +4,6 @@ const rendy = require('rendy');
|
|||
const currify = require('currify');
|
||||
const store = require('fullstore');
|
||||
const {encode} = require('./entity');
|
||||
const {btoa} = require('./base64');
|
||||
|
||||
const getHeaderField = currify(_getHeaderField);
|
||||
|
||||
|
|
@ -109,7 +108,9 @@ function getPathLink(url, prefix, template) {
|
|||
return lines.join('');
|
||||
}
|
||||
|
||||
const getDataName = (name) => {
|
||||
module.exports._getDataName = _getDataName;
|
||||
|
||||
function _getDataName(name) {
|
||||
const encoded = btoa(encodeURI(name));
|
||||
return `data-name="js-file-${encoded}" `;
|
||||
};
|
||||
|
|
@ -185,7 +186,7 @@ module.exports.buildFromJSON = (params) => {
|
|||
name: '..',
|
||||
});
|
||||
|
||||
const dataName = getDataName('..');
|
||||
const dataName = _getDataName('..');
|
||||
const attribute = `draggable="true" ${dataName}`;
|
||||
|
||||
/* Сохраняем путь к каталогу верхнего уровня*/
|
||||
|
|
@ -226,7 +227,7 @@ module.exports.buildFromJSON = (params) => {
|
|||
attribute: getAttribute(file.type),
|
||||
});
|
||||
|
||||
const dataName = getDataName(file.name);
|
||||
const dataName = _getDataName(file.name);
|
||||
const attribute = `draggable="true" ${dataName}`;
|
||||
|
||||
return rendy(templateFile, {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ const {
|
|||
_getSize,
|
||||
getPathLink,
|
||||
buildFromJSON,
|
||||
_getDataName,
|
||||
} = require('./cloudfunc');
|
||||
|
||||
const templatePath = join(__dirname, '../tmpl/fs');
|
||||
|
|
@ -175,3 +176,11 @@ test('cloudfunc: buildFromJSON: showDotFiles: false', (t) => {
|
|||
t.equal(result, expected);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudfunc: _getDataName', (t) => {
|
||||
const result = _getDataName('s');
|
||||
const expected = 'data-name="js-file-cw==" ';
|
||||
|
||||
t.equal(result, expected);
|
||||
t.end();
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue