feature(cloudcmd) add ability to use not only alphabet and number symbols (#167)

This commit is contained in:
coderaiser 2018-04-25 16:11:54 +03:00
parent 48c36eb5d3
commit 5479dce7da
8 changed files with 199 additions and 117 deletions

13
common/btoa.js Normal file
View file

@ -0,0 +1,13 @@
'use strict';
/* global btoa */
module.exports = (str) => {
if (typeof btoa === 'function')
return btoa(str);
return Buffer
.from(str)
.toString('base64');
};

View file

@ -4,6 +4,7 @@ const rendy = require('rendy');
const currify = require('currify/legacy');
const store = require('fullstore/legacy');
const encode = require('./entity').encode;
const btoa = require('./btoa');
const getHeaderField = currify(_getHeaderField);
@ -12,7 +13,6 @@ const getHeaderField = currify(_getHeaderField);
/* название программы */
const NAME = 'Cloud Commander';
const FS = '/fs';
const Path = store();
Path('/');
@ -96,6 +96,11 @@ function getPathLink(url, prefix, template) {
return pathHTML;
}
const getDataName = (name) => {
const encoded = btoa(name);
return `data-name="js-file-${encoded}" `;
};
/**
* Функция строит таблицу файлв из JSON-информации о файлах
* @param params - информация о файлах
@ -108,7 +113,7 @@ module.exports.buildFromJSON = (params) => {
const templateLink = template.link;
const json = params.data;
const path = json.path;
const path = encode(json.path);
const files = json.files;
const sort = params.sort || 'name';
@ -123,7 +128,7 @@ module.exports.buildFromJSON = (params) => {
let fileTable = rendy(template.path, {
link : prefix + FS + path,
fullPath : path,
path : htmlPath
path : htmlPath,
});
const owner = 'owner';
@ -197,7 +202,7 @@ module.exports.buildFromJSON = (params) => {
attribute: getAttribute(file.size)
});
const dataName = `data-name="js-file-${name}" `;
const dataName = getDataName(file.name);
const attribute = `draggable="true" ${dataName}`;
return rendy(templateFile, {