mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
chore: cloudcmd: actions: lint ☘️
This commit is contained in:
parent
564de89333
commit
a03185e14e
1 changed files with 34 additions and 35 deletions
|
|
@ -53,37 +53,37 @@ module.exports = (params) => {
|
|||
const config = p.configManager || createConfig({
|
||||
configPath,
|
||||
});
|
||||
|
||||
|
||||
const {modules} = p;
|
||||
const keys = Object.keys(options);
|
||||
|
||||
|
||||
for (const name of keys) {
|
||||
let value = options[name];
|
||||
|
||||
|
||||
if (/root/.test(name))
|
||||
validate.root(value, config);
|
||||
|
||||
|
||||
if (/editor|packer|columns/.test(name))
|
||||
validate[name](value);
|
||||
|
||||
|
||||
if (/prefix/.test(name))
|
||||
value = prefixer(value);
|
||||
|
||||
|
||||
config(name, value);
|
||||
}
|
||||
|
||||
|
||||
config('console', defaultValue(config, 'console', options));
|
||||
config('configDialog', defaultValue(config, 'configDialog', options));
|
||||
|
||||
|
||||
const prefixSocket = prefixer(options.prefixSocket);
|
||||
|
||||
|
||||
if (p.socket)
|
||||
listen({
|
||||
prefixSocket,
|
||||
config,
|
||||
socket: p.socket,
|
||||
});
|
||||
|
||||
|
||||
return cloudcmd({
|
||||
modules,
|
||||
config,
|
||||
|
|
@ -98,10 +98,10 @@ module.exports._getIndexPath = getIndexPath;
|
|||
function defaultValue(config, name, options) {
|
||||
const value = options[name];
|
||||
const previous = config(name);
|
||||
|
||||
|
||||
if (isUndefined(value))
|
||||
return previous;
|
||||
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
|
@ -109,7 +109,7 @@ module.exports._getPrefix = getPrefix;
|
|||
function getPrefix(prefix) {
|
||||
if (isFn(prefix))
|
||||
return prefix() || '';
|
||||
|
||||
|
||||
return prefix || '';
|
||||
}
|
||||
|
||||
|
|
@ -117,59 +117,59 @@ module.exports._initAuth = _initAuth;
|
|||
function _initAuth(config, accept, reject, username, password) {
|
||||
if (!config('auth'))
|
||||
return accept();
|
||||
|
||||
|
||||
const isName = username === config('username');
|
||||
const isPass = password === config('password');
|
||||
|
||||
|
||||
if (isName && isPass)
|
||||
return accept();
|
||||
|
||||
|
||||
reject();
|
||||
}
|
||||
|
||||
function listen({prefixSocket, socket, config}) {
|
||||
const root = apart(config, 'root');
|
||||
const auth = initAuth(config);
|
||||
|
||||
|
||||
prefixSocket = getPrefix(prefixSocket);
|
||||
config.listen(socket, auth);
|
||||
|
||||
|
||||
edward.listen(socket, {
|
||||
root,
|
||||
auth,
|
||||
prefixSocket: `${prefixSocket}/edward`,
|
||||
});
|
||||
|
||||
|
||||
dword.listen(socket, {
|
||||
root,
|
||||
auth,
|
||||
prefixSocket: `${prefixSocket}/dword`,
|
||||
});
|
||||
|
||||
|
||||
deepword.listen(socket, {
|
||||
root,
|
||||
auth,
|
||||
prefixSocket: `${prefixSocket}/deepword`,
|
||||
});
|
||||
|
||||
|
||||
config('console') && konsole.listen(socket, {
|
||||
auth,
|
||||
prefixSocket: `${prefixSocket}/console`,
|
||||
});
|
||||
|
||||
|
||||
fileop.listen(socket, {
|
||||
root,
|
||||
auth,
|
||||
prefix: `${prefixSocket}/fileop`,
|
||||
});
|
||||
|
||||
|
||||
config('terminal') && terminal(config).listen(socket, {
|
||||
auth,
|
||||
prefix: `${prefixSocket}/gritty`,
|
||||
command: config('terminalCommand'),
|
||||
autoRestart: config('terminalAutoRestart'),
|
||||
});
|
||||
|
||||
|
||||
distribute.export(config, socket);
|
||||
}
|
||||
|
||||
|
|
@ -179,15 +179,15 @@ function cloudcmd({modules, config}) {
|
|||
const diff = apart(config, 'diff');
|
||||
const zip = apart(config, 'zip');
|
||||
const root = apart(config, 'root');
|
||||
|
||||
|
||||
const ponseStatic = ponse.static({
|
||||
cache,
|
||||
root: DIR_ROOT,
|
||||
});
|
||||
|
||||
|
||||
const dropbox = config('dropbox');
|
||||
const dropboxToken = config('dropboxToken');
|
||||
|
||||
|
||||
const funcs = clean([
|
||||
config('console') && konsole({
|
||||
online,
|
||||
|
|
@ -243,14 +243,14 @@ function cloudcmd({modules, config}) {
|
|||
}),
|
||||
ponseStatic,
|
||||
]);
|
||||
|
||||
|
||||
return funcs;
|
||||
}
|
||||
|
||||
function logout(req, res, next) {
|
||||
if (req.url !== '/logout')
|
||||
return next();
|
||||
|
||||
|
||||
res.sendStatus(401);
|
||||
}
|
||||
|
||||
|
|
@ -259,26 +259,25 @@ module.exports._replaceDist = replaceDist;
|
|||
function replaceDist(url) {
|
||||
if (!isDev())
|
||||
return url;
|
||||
|
||||
|
||||
return url.replace(/^\/dist\//, '/dist-dev/');
|
||||
}
|
||||
|
||||
function setUrl(req, res, next) {
|
||||
if (/^\/cloudcmd\.js(\.map)?$/.test(req.url))
|
||||
req.url = `/dist${req.url}`;
|
||||
|
||||
|
||||
req.url = replaceDist(req.url);
|
||||
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
function setSW(req, res, next) {
|
||||
const {url} = req;
|
||||
const isSW = /^\/sw\.js(\.map)?$/.test(url);
|
||||
|
||||
|
||||
if (isSW)
|
||||
req.url = replaceDist(`/dist${url}`);
|
||||
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue