fix(buffer) copy, cut

This commit is contained in:
coderaiser 2019-08-22 18:30:38 +03:00
parent 7e6b3c6ba5
commit 3ac7ee4b76
4 changed files with 38 additions and 32 deletions

View file

@ -16,7 +16,6 @@ const isDev = process.env.NODE_ENV === 'development';
const Images = require('./dom/images');
const {unregisterSW} = require('./sw/register');
const jonny = require('jonny/legacy');
const currify = require('currify/legacy');
const noJS = (a) => a.replace(/.js$/, '');
@ -345,15 +344,18 @@ function CloudCmdProto(DOM) {
*
*/
function ajaxLoad(path, options, panel, callback) {
const {Dialog, RESTful} = DOM;
const create = async (error, json) => {
const {RESTful} = DOM;
if (error)
return Dialog.alert(`Can't get from store: ${e.message}`);
const name = options.currentName || Info.name;
const obj = jonny.parse(json);
const isRefresh = options.refresh;
const {noCurrent} = options;
if (!isRefresh && json)
return createFileTable(obj, panel, options, callback);
return createFileTable(json, panel, options, callback);
const position = DOM.getPanelPosition(panel);
const sort = CloudCmd.sort[position];
@ -364,10 +366,10 @@ function CloudCmdProto(DOM) {
order,
});
const [, newObj] = await RESTful.read(path + query, 'json');
const [e, newObj] = await RESTful.read(path + query, 'json');
if (!newObj)
return;
return Dialog.alert(`Can't read: ${e.message}`);
options.sort = sort;
options.order = order;

View file

@ -2,8 +2,6 @@
/* global CloudCmd */
const jonny = require('jonny/legacy');
const tryToPromiseAll = require('../../common/try-to-promise-all');
const Storage = require('./storage');
const DOM = require('./');
@ -59,14 +57,15 @@ function BufferProto() {
}
async function readBuffer() {
const [e, result] = await tryToPromiseAll([
const [e, cp, ct] = await tryToPromiseAll([
Storage.get(COPY),
Storage.get(CUT),
]);
return [
e,
...result,
cp,
ct,
];
}
@ -74,7 +73,7 @@ function BufferProto() {
const names = getNames();
const from = Info.dirPath;
clear();
await clear();
if (!names.length)
return;
@ -90,7 +89,7 @@ function BufferProto() {
const names = getNames();
const from = Info.dirPath;
clear();
await clear();
if (!names.length)
return;
@ -103,9 +102,9 @@ function BufferProto() {
});
}
function clear() {
Storage.remove(COPY)
.remove(CUT);
async function clear() {
await Storage.remove(COPY);
await Storage.remove(CUT);
rmCutClass();
}
@ -117,19 +116,20 @@ function BufferProto() {
return showMessage(error || 'Buffer is empty!');
const opStr = cp ? 'copy' : 'move';
const opData = cp || ct;
const data = cp || ct;
const {Operation} = CloudCmd;
const msg = 'Path is same!';
const path = Info.dirPath;
const to = Info.dirPath;
const data = jonny.parse(opData);
data.to = path;
if (data.from === path)
if (data.from === to)
return showMessage(msg);
Operation.show(opStr, data);
clear();
Operation.show(opStr, {
...data,
to,
});
await clear();
}
return Buffer;

View file

@ -2,8 +2,6 @@
'use strict';
const itype = require('itype/legacy');
const jonny = require('jonny/legacy');
const tryToPromiseAll = require('../../common/try-to-promise-all');
const Util = require('../../common/util');
@ -341,16 +339,12 @@ function CmdProto() {
if (hash === hashNew)
return await Storage.get(`${path}-data`);
let [e, data] = await RESTful.read(path);
const [e, data] = await RESTful.read(path);
if (e)
return;
const ONE_MEGABYTE = 1024 * 1024 * 1024;
if (itype.object(data))
data = jonny.stringify(data);
const {length} = data;
if (hash && length < ONE_MEGABYTE)

View file

@ -1,11 +1,21 @@
'use strict';
const tryCatch = require('try-catch');
const {parse, stringify} = JSON;
const isObj = (a) => typeof a === 'object';
module.exports.set = async (name, data) => {
localStorage.setItem(name, data);
const primitive = !isObj(data) ? data : stringify(data);
localStorage.setItem(name, primitive);
};
module.exports.get = async (name) => {
return localStorage.getItem(name);
const data = localStorage.getItem(name);
const [, result = data] = tryCatch(parse, data);
return result;
};
module.exports.clear = async () => {