mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature(cloudcmd) rm option: localStorage
This commit is contained in:
parent
62f166f15c
commit
28892b3933
10 changed files with 12 additions and 136 deletions
3
HELP.md
3
HELP.md
|
|
@ -365,9 +365,8 @@ Here is description of options:
|
||||||
"packer" : "tar", /* default, could be "tar" or "zip" */
|
"packer" : "tar", /* default, could be "tar" or "zip" */
|
||||||
"diff" : true, /* when save - send patch, not whole file */
|
"diff" : true, /* when save - send patch, not whole file */
|
||||||
"zip" : true, /* zip text before send / unzip before save */
|
"zip" : true, /* zip text before send / unzip before save */
|
||||||
"localStorage" : true, /* local storage (deprecated) */
|
|
||||||
"buffer" : true, /* buffer for copying files */
|
"buffer" : true, /* buffer for copying files */
|
||||||
"dirStorage" : true, /* store directory listing to localStorage */
|
"dirStorage" : true, /* store directory listing */
|
||||||
"online" : true, /* load js files from cdn or local path */
|
"online" : true, /* load js files from cdn or local path */
|
||||||
"open" : false /* open web browser when server started */
|
"open" : false /* open web browser when server started */
|
||||||
"cache" : true, /* enable cache */
|
"cache" : true, /* enable cache */
|
||||||
|
|
|
||||||
|
|
@ -221,8 +221,6 @@ function CloudCmdProto(Util, DOM) {
|
||||||
config[key] = value;
|
config[key] = value;
|
||||||
};
|
};
|
||||||
|
|
||||||
DOM.Storage.setAllowed(CloudCmd.config('localStorage'));
|
|
||||||
|
|
||||||
if (config.onePanelMode)
|
if (config.onePanelMode)
|
||||||
CloudCmd.MIN_ONE_PANEL_WIDTH = Infinity;
|
CloudCmd.MIN_ONE_PANEL_WIDTH = Infinity;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ const itype = require('itype/legacy');
|
||||||
const currify = require('currify/legacy');
|
const currify = require('currify/legacy');
|
||||||
const exec = require('execon');
|
const exec = require('execon');
|
||||||
|
|
||||||
const Storage = require('./storage');
|
|
||||||
const load = require('./load');
|
const load = require('./load');
|
||||||
const RESTful = require('./rest');
|
const RESTful = require('./rest');
|
||||||
|
|
||||||
|
|
@ -136,7 +135,6 @@ function getConfig(callback) {
|
||||||
|
|
||||||
Promises.config.then((data) => {
|
Promises.config.then((data) => {
|
||||||
is = false;
|
is = false;
|
||||||
Storage.setAllowed(data.localStorage);
|
|
||||||
|
|
||||||
callback(null, data);
|
callback(null, data);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,22 +6,10 @@ const exec = require('execon');
|
||||||
const tryCatch = require('try-catch');
|
const tryCatch = require('try-catch');
|
||||||
const setItem = localStorage.setItem.bind(localStorage);
|
const setItem = localStorage.setItem.bind(localStorage);
|
||||||
|
|
||||||
/* приватный переключатель возможности работы с кэшем */
|
|
||||||
let Allowed;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* allow Storage usage
|
|
||||||
*/
|
|
||||||
module.exports.setAllowed = (isAllowed) => {
|
|
||||||
Allowed = isAllowed;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** remove element */
|
/** remove element */
|
||||||
module.exports.remove = (item, callback) => {
|
module.exports.remove = (item, callback) => {
|
||||||
if (Allowed)
|
localStorage.removeItem(item);
|
||||||
localStorage.removeItem(item);
|
exec(callback, null);
|
||||||
|
|
||||||
exec(callback, null, Allowed);
|
|
||||||
|
|
||||||
return module.exports;
|
return module.exports;
|
||||||
};
|
};
|
||||||
|
|
@ -50,7 +38,7 @@ module.exports.set = (name, data, callback) => {
|
||||||
if (itype.object(data))
|
if (itype.object(data))
|
||||||
str = jonny.stringify(data);
|
str = jonny.stringify(data);
|
||||||
|
|
||||||
if (Allowed && name)
|
if (name)
|
||||||
[error] = tryCatch(setItem, name, str || data);
|
[error] = tryCatch(setItem, name, str || data);
|
||||||
|
|
||||||
exec(callback, error);
|
exec(callback, error);
|
||||||
|
|
@ -60,10 +48,7 @@ module.exports.set = (name, data, callback) => {
|
||||||
|
|
||||||
/** Если доступен Storage принимаем из него данные*/
|
/** Если доступен Storage принимаем из него данные*/
|
||||||
module.exports.get = (name, callback) => {
|
module.exports.get = (name, callback) => {
|
||||||
let ret;
|
const ret = localStorage.getItem(name);
|
||||||
|
|
||||||
if (Allowed)
|
|
||||||
ret = localStorage.getItem(name);
|
|
||||||
|
|
||||||
exec(callback, null, ret);
|
exec(callback, null, ret);
|
||||||
|
|
||||||
|
|
@ -72,12 +57,9 @@ module.exports.get = (name, callback) => {
|
||||||
|
|
||||||
/** функция чистит весь кэш для всех каталогов*/
|
/** функция чистит весь кэш для всех каталогов*/
|
||||||
module.exports.clear = (callback) => {
|
module.exports.clear = (callback) => {
|
||||||
const ret = Allowed;
|
localStorage.clear();
|
||||||
|
|
||||||
if (ret)
|
exec(callback);
|
||||||
localStorage.clear();
|
|
||||||
|
|
||||||
exec(callback, null, ret);
|
|
||||||
|
|
||||||
return module.exports;
|
return module.exports;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ const Info = DOM.CurrentInfo;
|
||||||
|
|
||||||
const exec = require('execon');
|
const exec = require('execon');
|
||||||
const clipboard = require('@cloudcmd/clipboard');
|
const clipboard = require('@cloudcmd/clipboard');
|
||||||
|
const wraptile = require('wraptile/legacy');
|
||||||
|
|
||||||
const Events = require('../dom/events');
|
const Events = require('../dom/events');
|
||||||
const Buffer = require('../dom/buffer');
|
const Buffer = require('../dom/buffer');
|
||||||
|
|
@ -465,11 +466,7 @@ function KeyProto() {
|
||||||
case Key.D:
|
case Key.D:
|
||||||
if (ctrlMeta) {
|
if (ctrlMeta) {
|
||||||
CloudCmd.log('clearing storage...');
|
CloudCmd.log('clearing storage...');
|
||||||
|
DOM.Storage.clear(wraptile(CloudCmd.log, 'storage cleared'));
|
||||||
DOM.Storage.clear(() => {
|
|
||||||
CloudCmd.log('storage cleared');
|
|
||||||
});
|
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -101,10 +101,6 @@ function initSocket() {
|
||||||
Config.save = save;
|
Config.save = save;
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('config', (config) => {
|
|
||||||
DOM.Storage.setAllowed(config.localStorage);
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on('message', onSave);
|
socket.on('message', onSave);
|
||||||
socket.on('log', CloudCmd.log);
|
socket.on('log', CloudCmd.log);
|
||||||
|
|
||||||
|
|
@ -205,17 +201,11 @@ function onChange(el) {
|
||||||
const obj = {};
|
const obj = {};
|
||||||
const name = input.getName(el);
|
const name = input.getName(el);
|
||||||
const data = input.getValue(name, Element);
|
const data = input.getValue(name, Element);
|
||||||
const type = el.type;
|
|
||||||
|
|
||||||
if (name === 'name')
|
if (name === 'name')
|
||||||
onNameChange(data);
|
onNameChange(data);
|
||||||
else if (type === 'checkbox')
|
else if (name === 'auth')
|
||||||
if (/^(diff|buffer|dirStorage)$/.test(name))
|
onAuthChange(data);
|
||||||
onLSChange(name, data);
|
|
||||||
else if (name === 'localStorage')
|
|
||||||
onLocalStorageChange();
|
|
||||||
else if (name === 'auth')
|
|
||||||
onAuthChange(data);
|
|
||||||
|
|
||||||
obj[name] = data;
|
obj[name] = data;
|
||||||
|
|
||||||
|
|
@ -229,8 +219,6 @@ function onSave(obj) {
|
||||||
CloudCmd._config(name, data);
|
CloudCmd._config(name, data);
|
||||||
input.setValue(name, data, Element);
|
input.setValue(name, data, Element);
|
||||||
});
|
});
|
||||||
|
|
||||||
DOM.Storage.setAllowed(obj.localStorage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveHttp(obj) {
|
function saveHttp(obj) {
|
||||||
|
|
@ -244,50 +232,6 @@ function saveHttp(obj) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function onLocalStorageChange() {
|
|
||||||
const names = ['diff', 'buffer', 'dirStorage', 'localStorage'];
|
|
||||||
const elements = names.map((name) => {
|
|
||||||
return input.getElementByName(name, Element);
|
|
||||||
});
|
|
||||||
const el = {};
|
|
||||||
const msg = 'Diff, Buffer and Directory Storage do not work without localStorage';
|
|
||||||
|
|
||||||
let isChecked;
|
|
||||||
|
|
||||||
elements.forEach((element) => {
|
|
||||||
const name = input.getName(element);
|
|
||||||
|
|
||||||
el[name] = element;
|
|
||||||
|
|
||||||
if (element.checked)
|
|
||||||
isChecked = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!isChecked || el.localStorage.checked)
|
|
||||||
return;
|
|
||||||
|
|
||||||
alert(msg);
|
|
||||||
|
|
||||||
elements.forEach((element) => {
|
|
||||||
if (!element.checked)
|
|
||||||
return;
|
|
||||||
|
|
||||||
element.checked = false;
|
|
||||||
onChange(element);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function onLSChange(name, data) {
|
|
||||||
const elLocalStorage = input.getElementByName('localStorage', Element);
|
|
||||||
const msg = `${name} depends on localStorage`;
|
|
||||||
|
|
||||||
if (!data || elLocalStorage.checked)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Dialog.alert(TITLE, msg);
|
|
||||||
elLocalStorage.checked = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function onAuthChange(checked) {
|
function onAuthChange(checked) {
|
||||||
const elUsername = input.getElementByName('username', Element);
|
const elUsername = input.getElementByName('username', Element);
|
||||||
const elPassword = input.getElementByName('password', Element);
|
const elPassword = input.getElementByName('password', Element);
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@
|
||||||
"packer": "tar",
|
"packer": "tar",
|
||||||
"diff": true,
|
"diff": true,
|
||||||
"zip" : true,
|
"zip" : true,
|
||||||
"localStorage": true,
|
|
||||||
"buffer": true,
|
"buffer": true,
|
||||||
"dirStorage": false,
|
"dirStorage": false,
|
||||||
"online": true,
|
"online": true,
|
||||||
|
|
|
||||||
|
|
@ -51,11 +51,6 @@ const deprecateOnePanelMode = (value) => {
|
||||||
config('oneFilePanel', value);
|
config('oneFilePanel', value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const deprecateLocalStorage = (value) => {
|
|
||||||
util.deprecate(noop, 'localStorage is deprecated', 'DP0002')();
|
|
||||||
config('localStorage', value);
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = (params) => {
|
module.exports = (params) => {
|
||||||
const p = params || {};
|
const p = params || {};
|
||||||
const options = p.config || {};
|
const options = p.config || {};
|
||||||
|
|
@ -69,9 +64,7 @@ module.exports = (params) => {
|
||||||
keys.forEach((name) => {
|
keys.forEach((name) => {
|
||||||
const value = options[name];
|
const value = options[name];
|
||||||
|
|
||||||
if (name === 'localStorage')
|
if (name === 'onePanelMode')
|
||||||
deprecateLocalStorage(value);
|
|
||||||
else if (name === 'onePanelMode')
|
|
||||||
deprecateOnePanelMode();
|
deprecateOnePanelMode();
|
||||||
else if (name === 'oneFilePanel')
|
else if (name === 'oneFilePanel')
|
||||||
config('onePanelMode', value);
|
config('onePanelMode', value);
|
||||||
|
|
|
||||||
|
|
@ -222,31 +222,6 @@ test('cloudcmd: getIndexPath: development', (t) => {
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('cloudcmd: deprecated: localStorage', (t) => {
|
|
||||||
const config = {
|
|
||||||
localStorage: false
|
|
||||||
};
|
|
||||||
|
|
||||||
const {
|
|
||||||
deprecate: originalDeprecate
|
|
||||||
} = util;
|
|
||||||
|
|
||||||
const deprecate = sinon
|
|
||||||
.stub()
|
|
||||||
.returns(noop);
|
|
||||||
|
|
||||||
util.deprecate = deprecate;
|
|
||||||
|
|
||||||
cloudcmd({
|
|
||||||
config
|
|
||||||
});
|
|
||||||
|
|
||||||
util.deprecate = originalDeprecate;
|
|
||||||
|
|
||||||
t.ok(deprecate.called, 'should call deprecate');
|
|
||||||
t.end();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('cloudcmd: deprecated: one panel mode', (t) => {
|
test('cloudcmd: deprecated: one panel mode', (t) => {
|
||||||
const config = {
|
const config = {
|
||||||
onePanelMode: true
|
onePanelMode: true
|
||||||
|
|
|
||||||
|
|
@ -66,15 +66,6 @@
|
||||||
Vim
|
Vim
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
|
||||||
<label>
|
|
||||||
<input
|
|
||||||
data-name="js-localStorage"
|
|
||||||
type="checkbox"
|
|
||||||
{{ localStorage }}>
|
|
||||||
Local Storage
|
|
||||||
</label>
|
|
||||||
</li>
|
|
||||||
<li>
|
<li>
|
||||||
<label>
|
<label>
|
||||||
<input data-name="js-buffer" type="checkbox" {{ buffer }}>
|
<input data-name="js-buffer" type="checkbox" {{ buffer }}>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue