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" */
|
||||
"diff" : true, /* when save - send patch, not whole file */
|
||||
"zip" : true, /* zip text before send / unzip before save */
|
||||
"localStorage" : true, /* local storage (deprecated) */
|
||||
"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 */
|
||||
"open" : false /* open web browser when server started */
|
||||
"cache" : true, /* enable cache */
|
||||
|
|
|
|||
|
|
@ -221,8 +221,6 @@ function CloudCmdProto(Util, DOM) {
|
|||
config[key] = value;
|
||||
};
|
||||
|
||||
DOM.Storage.setAllowed(CloudCmd.config('localStorage'));
|
||||
|
||||
if (config.onePanelMode)
|
||||
CloudCmd.MIN_ONE_PANEL_WIDTH = Infinity;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ const itype = require('itype/legacy');
|
|||
const currify = require('currify/legacy');
|
||||
const exec = require('execon');
|
||||
|
||||
const Storage = require('./storage');
|
||||
const load = require('./load');
|
||||
const RESTful = require('./rest');
|
||||
|
||||
|
|
@ -136,7 +135,6 @@ function getConfig(callback) {
|
|||
|
||||
Promises.config.then((data) => {
|
||||
is = false;
|
||||
Storage.setAllowed(data.localStorage);
|
||||
|
||||
callback(null, data);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,22 +6,10 @@ const exec = require('execon');
|
|||
const tryCatch = require('try-catch');
|
||||
const setItem = localStorage.setItem.bind(localStorage);
|
||||
|
||||
/* приватный переключатель возможности работы с кэшем */
|
||||
let Allowed;
|
||||
|
||||
/**
|
||||
* allow Storage usage
|
||||
*/
|
||||
module.exports.setAllowed = (isAllowed) => {
|
||||
Allowed = isAllowed;
|
||||
};
|
||||
|
||||
/** remove element */
|
||||
module.exports.remove = (item, callback) => {
|
||||
if (Allowed)
|
||||
localStorage.removeItem(item);
|
||||
|
||||
exec(callback, null, Allowed);
|
||||
localStorage.removeItem(item);
|
||||
exec(callback, null);
|
||||
|
||||
return module.exports;
|
||||
};
|
||||
|
|
@ -50,7 +38,7 @@ module.exports.set = (name, data, callback) => {
|
|||
if (itype.object(data))
|
||||
str = jonny.stringify(data);
|
||||
|
||||
if (Allowed && name)
|
||||
if (name)
|
||||
[error] = tryCatch(setItem, name, str || data);
|
||||
|
||||
exec(callback, error);
|
||||
|
|
@ -60,10 +48,7 @@ module.exports.set = (name, data, callback) => {
|
|||
|
||||
/** Если доступен Storage принимаем из него данные*/
|
||||
module.exports.get = (name, callback) => {
|
||||
let ret;
|
||||
|
||||
if (Allowed)
|
||||
ret = localStorage.getItem(name);
|
||||
const ret = localStorage.getItem(name);
|
||||
|
||||
exec(callback, null, ret);
|
||||
|
||||
|
|
@ -72,12 +57,9 @@ module.exports.get = (name, callback) => {
|
|||
|
||||
/** функция чистит весь кэш для всех каталогов*/
|
||||
module.exports.clear = (callback) => {
|
||||
const ret = Allowed;
|
||||
localStorage.clear();
|
||||
|
||||
if (ret)
|
||||
localStorage.clear();
|
||||
|
||||
exec(callback, null, ret);
|
||||
exec(callback);
|
||||
|
||||
return module.exports;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ const Info = DOM.CurrentInfo;
|
|||
|
||||
const exec = require('execon');
|
||||
const clipboard = require('@cloudcmd/clipboard');
|
||||
const wraptile = require('wraptile/legacy');
|
||||
|
||||
const Events = require('../dom/events');
|
||||
const Buffer = require('../dom/buffer');
|
||||
|
|
@ -465,11 +466,7 @@ function KeyProto() {
|
|||
case Key.D:
|
||||
if (ctrlMeta) {
|
||||
CloudCmd.log('clearing storage...');
|
||||
|
||||
DOM.Storage.clear(() => {
|
||||
CloudCmd.log('storage cleared');
|
||||
});
|
||||
|
||||
DOM.Storage.clear(wraptile(CloudCmd.log, 'storage cleared'));
|
||||
event.preventDefault();
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -101,10 +101,6 @@ function initSocket() {
|
|||
Config.save = save;
|
||||
});
|
||||
|
||||
socket.on('config', (config) => {
|
||||
DOM.Storage.setAllowed(config.localStorage);
|
||||
});
|
||||
|
||||
socket.on('message', onSave);
|
||||
socket.on('log', CloudCmd.log);
|
||||
|
||||
|
|
@ -205,17 +201,11 @@ function onChange(el) {
|
|||
const obj = {};
|
||||
const name = input.getName(el);
|
||||
const data = input.getValue(name, Element);
|
||||
const type = el.type;
|
||||
|
||||
if (name === 'name')
|
||||
onNameChange(data);
|
||||
else if (type === 'checkbox')
|
||||
if (/^(diff|buffer|dirStorage)$/.test(name))
|
||||
onLSChange(name, data);
|
||||
else if (name === 'localStorage')
|
||||
onLocalStorageChange();
|
||||
else if (name === 'auth')
|
||||
onAuthChange(data);
|
||||
else if (name === 'auth')
|
||||
onAuthChange(data);
|
||||
|
||||
obj[name] = data;
|
||||
|
||||
|
|
@ -229,8 +219,6 @@ function onSave(obj) {
|
|||
CloudCmd._config(name, data);
|
||||
input.setValue(name, data, Element);
|
||||
});
|
||||
|
||||
DOM.Storage.setAllowed(obj.localStorage);
|
||||
}
|
||||
|
||||
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) {
|
||||
const elUsername = input.getElementByName('username', Element);
|
||||
const elPassword = input.getElementByName('password', Element);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
"packer": "tar",
|
||||
"diff": true,
|
||||
"zip" : true,
|
||||
"localStorage": true,
|
||||
"buffer": true,
|
||||
"dirStorage": false,
|
||||
"online": true,
|
||||
|
|
|
|||
|
|
@ -51,11 +51,6 @@ const deprecateOnePanelMode = (value) => {
|
|||
config('oneFilePanel', value);
|
||||
};
|
||||
|
||||
const deprecateLocalStorage = (value) => {
|
||||
util.deprecate(noop, 'localStorage is deprecated', 'DP0002')();
|
||||
config('localStorage', value);
|
||||
};
|
||||
|
||||
module.exports = (params) => {
|
||||
const p = params || {};
|
||||
const options = p.config || {};
|
||||
|
|
@ -69,9 +64,7 @@ module.exports = (params) => {
|
|||
keys.forEach((name) => {
|
||||
const value = options[name];
|
||||
|
||||
if (name === 'localStorage')
|
||||
deprecateLocalStorage(value);
|
||||
else if (name === 'onePanelMode')
|
||||
if (name === 'onePanelMode')
|
||||
deprecateOnePanelMode();
|
||||
else if (name === 'oneFilePanel')
|
||||
config('onePanelMode', value);
|
||||
|
|
|
|||
|
|
@ -222,31 +222,6 @@ test('cloudcmd: getIndexPath: development', (t) => {
|
|||
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) => {
|
||||
const config = {
|
||||
onePanelMode: true
|
||||
|
|
|
|||
|
|
@ -66,15 +66,6 @@
|
|||
Vim
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<label>
|
||||
<input
|
||||
data-name="js-localStorage"
|
||||
type="checkbox"
|
||||
{{ localStorage }}>
|
||||
Local Storage
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<label>
|
||||
<input data-name="js-buffer" type="checkbox" {{ buffer }}>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue