From add31607f9d726d51880f4d4b8717928400bd449 Mon Sep 17 00:00:00 2001 From: coderiaser Date: Fri, 16 Jan 2026 23:05:16 +0200 Subject: [PATCH] feature: common: cloudfunc: get rid of bas64 --- client/dom/current-file.js | 3 --- common/base64.js | 19 -------------- common/base64.spec.js | 54 -------------------------------------- common/cloudfunc.js | 9 ++++--- common/cloudfunc.spec.js | 9 +++++++ 5 files changed, 14 insertions(+), 80 deletions(-) delete mode 100644 common/base64.js delete mode 100644 common/base64.spec.js diff --git a/client/dom/current-file.js b/client/dom/current-file.js index 3ac29ae7..f684b4fe 100644 --- a/client/dom/current-file.js +++ b/client/dom/current-file.js @@ -3,10 +3,7 @@ /* global DOM */ /* global CloudCmd */ const createElement = require('@cloudcmd/create-element'); -const {atob, btoa} = require('../../common/base64'); - const {encode, decode} = require('../../common/entity'); - const {getTitle, FS} = require('../../common/cloudfunc'); let Title; diff --git a/common/base64.js b/common/base64.js deleted file mode 100644 index c1a82c17..00000000 --- a/common/base64.js +++ /dev/null @@ -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'); -}; diff --git a/common/base64.spec.js b/common/base64.spec.js deleted file mode 100644 index cf34d540..00000000 --- a/common/base64.spec.js +++ /dev/null @@ -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(); -}); diff --git a/common/cloudfunc.js b/common/cloudfunc.js index c906b548..0bbdf15e 100644 --- a/common/cloudfunc.js +++ b/common/cloudfunc.js @@ -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, { diff --git a/common/cloudfunc.spec.js b/common/cloudfunc.spec.js index e4e06dd7..b6a41459 100644 --- a/common/cloudfunc.spec.js +++ b/common/cloudfunc.spec.js @@ -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(); +});