• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

coderaiser / cloudcmd / 26420142854

25 May 2026 09:17PM UTC coverage: 48.74% (-17.2%) from 65.962%
26420142854

push

github

coderaiser
feature: cloudcmd: rate limit: add support (#437)

320 of 424 branches covered (75.47%)

14 of 14 new or added lines in 2 files covered. (100.0%)

1481 existing lines in 47 files now uncovered.

3734 of 7661 relevant lines covered (48.74%)

1075.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.34
/server/cloudcmd.js
1
import path, {dirname, join} from 'node:path';
3✔
2
import {fileURLToPath} from 'node:url';
3✔
3
import process from 'node:process';
3✔
4
import fs from 'node:fs';
3✔
5
import {fullstore} from 'fullstore';
3✔
6
import currify from 'currify';
3✔
7
import apart from 'apart';
3✔
8
import * as ponse from 'ponse';
3✔
9
import {restafary} from 'restafary';
3✔
10
import restbox from 'restbox';
3✔
11
import {konsole} from 'console-io';
3✔
12
import {edward} from 'edward';
3✔
13
import {dword} from 'dword';
3✔
14
import {deepword} from 'deepword';
3✔
15
import {qword} from 'qword';
3✔
16
import nomine from 'nomine';
3✔
17
import {fileop} from '@cloudcmd/fileop';
3✔
18
import * as cloudfunc from '#common/cloudfunc';
3✔
19
import authentication from './auth.js';
3✔
20
import {createConfig, configPath} from './config.js';
3✔
21
import modulas from './modulas.js';
3✔
22
import {userMenu} from './user-menu.js';
3✔
23
import rest from './rest/index.js';
3✔
24
import route from './route.js';
3✔
25
import * as validate from './validate.js';
3✔
26
import prefixer from './prefixer.js';
3✔
27
import terminal from './terminal.js';
3✔
28
import {distributeExport} from './distribute/export.js';
3✔
29
import {createDepStore} from './depstore.js';
3✔
30

3✔
31
const __filename = fileURLToPath(import.meta.url);
3✔
32
const __dirname = dirname(__filename);
3✔
33
const {assign} = Object;
3✔
34
const DIR = `${__dirname}/`;
3✔
35
const DIR_ROOT = join(DIR, '..');
3✔
36
const getDist = (isDev) => isDev ? 'dist-dev' : 'dist';
3!
37

3✔
38
const isDev = fullstore(process.env.NODE_ENV === 'development');
3✔
39

3✔
40
const getIndexPath = (isDev) => path.join(DIR, '..', `${getDist(isDev)}/index.html`);
3✔
41
const html = fs.readFileSync(getIndexPath(isDev()), 'utf8');
3✔
42

3✔
43
const initAuth = currify(_initAuth);
3✔
44
const notEmpty = (a) => a;
3✔
45
const clean = (a) => a.filter(notEmpty);
3✔
46

3✔
47
const isUndefined = (a) => typeof a === 'undefined';
3✔
48
const isFn = (a) => typeof a === 'function';
3✔
49

3✔
50
export default cloudcmd;
3✔
51

3✔
52
export function cloudcmd(params) {
3✔
53
    const p = params || {};
105!
54
    const options = p.config || {};
105✔
55
    
105✔
56
    const config = p.configManager || createConfig({
105✔
57
        configPath,
66✔
58
    });
105✔
59
    
105✔
60
    const {modules} = p;
105✔
61
    const keys = Object.keys(options);
105✔
62
    
105✔
63
    for (const name of keys) {
105✔
64
        let value = options[name];
195✔
65
        
195✔
66
        if (/root/.test(name))
195✔
67
            validate.root(value, config);
195✔
68
        
195✔
69
        if (/editor|packer|themes|menu/.test(name))
195✔
70
            validate[name](value);
195✔
71
        
195✔
72
        if (/prefix/.test(name))
195✔
73
            value = prefixer(value);
195✔
74
        
195✔
75
        config(name, value);
195✔
76
    }
195✔
77
    
105✔
78
    config('console', defaultValue(config, 'console', options));
105✔
79
    config('configDialog', defaultValue(config, 'configDialog', options));
105✔
80
    
105✔
81
    const prefixSocket = prefixer(options.prefixSocket);
105✔
82
    
105✔
83
    if (p.socket)
105✔
84
        listen({
105✔
85
            prefixSocket,
9✔
86
            config,
9✔
87
            socket: p.socket,
9✔
88
        });
9✔
89
    
105✔
90
    return cloudcmdMiddle({
105✔
91
        modules,
105✔
92
        config,
105✔
93
    });
105✔
94
}
105✔
95

3✔
96
const depStore = createDepStore();
3✔
97

3✔
98
export const createConfigManager = createConfig;
3✔
99
export {
3✔
100
    configPath,
3✔
101
};
3✔
102

3✔
103
export const _getIndexPath = getIndexPath;
3✔
104

3✔
105
function defaultValue(config, name, options) {
210✔
106
    const value = options[name];
210✔
107
    const previous = config(name);
210✔
108
    
210✔
109
    if (isUndefined(value))
210✔
110
        return previous;
210✔
111
    
15✔
112
    return value;
15✔
113
}
210✔
114

3✔
115
export const _getPrefix = getPrefix;
3✔
116

3✔
117
function getPrefix(prefix) {
9✔
118
    if (isFn(prefix))
9✔
119
        return prefix() || '';
9!
120
    
9✔
121
    return prefix || '';
9✔
122
}
9✔
123

3✔
124
export function _initAuth(config, accept, reject, username, password) {
3✔
125
    if (!config('auth'))
3✔
126
        return accept();
3✔
UNCOV
127
    
×
UNCOV
128
    const isName = username === config('username');
×
UNCOV
129
    const isPass = password === config('password');
×
UNCOV
130
    
×
131
    if (isName && isPass)
3✔
132
        return accept();
3!
UNCOV
133
    
×
UNCOV
134
    reject();
×
135
}
3✔
136

3✔
137
function listen({prefixSocket, socket, config}) {
9✔
138
    const root = apart(config, 'root');
9✔
139
    const auth = initAuth(config);
9✔
140
    
9✔
141
    prefixSocket = getPrefix(prefixSocket);
9✔
142
    config.listen(socket, auth);
9✔
143
    
9✔
144
    edward.listen(socket, {
9✔
145
        root,
9✔
146
        auth,
9✔
147
        prefixSocket: `${prefixSocket}/edward`,
9✔
148
    });
9✔
149
    
9✔
150
    dword.listen(socket, {
9✔
151
        root,
9✔
152
        auth,
9✔
153
        prefixSocket: `${prefixSocket}/dword`,
9✔
154
    });
9✔
155
    
9✔
156
    qword.listen(socket, {
9✔
157
        root,
9✔
158
        auth,
9✔
159
        prefixSocket: `${prefixSocket}/qword`,
9✔
160
    });
9✔
161
    
9✔
162
    deepword.listen(socket, {
9✔
163
        root,
9✔
164
        auth,
9✔
165
        prefixSocket: `${prefixSocket}/deepword`,
9✔
166
    });
9✔
167
    
9✔
168
    config('console') && konsole.listen(socket, {
9✔
169
        auth,
6✔
170
        prefixSocket: `${prefixSocket}/console`,
6✔
171
    });
9✔
172
    
9✔
173
    fileop.listen(socket, {
9✔
174
        root,
9✔
175
        auth,
9✔
176
        prefix: `${prefixSocket}/fileop`,
9✔
177
    });
9✔
178
    
9✔
179
    config('terminal') && terminal(config).listen(socket, {
9!
180
        auth,
×
181
        prefix: `${prefixSocket}/gritty`,
×
182
        command: config('terminalCommand'),
×
183
        autoRestart: config('terminalAutoRestart'),
×
184
    });
9✔
185
    
9✔
186
    distributeExport(config, socket);
9✔
187
}
9✔
188

3✔
189
function cloudcmdMiddle({modules, config}) {
105✔
190
    const online = apart(config, 'online');
105✔
191
    const cache = false;
105✔
192
    const diff = apart(config, 'diff');
105✔
193
    const zip = apart(config, 'zip');
105✔
194
    const root = apart(config, 'root');
105✔
195
    
105✔
196
    const ponseStatic = ponse.createStatic({
105✔
197
        cache,
105✔
198
        root: DIR_ROOT,
105✔
199
    });
105✔
200
    
105✔
201
    const dropbox = config('dropbox');
105✔
202
    const dropboxToken = config('dropboxToken');
105✔
203
    
105✔
204
    const funcs = clean([
105✔
205
        config('console') && konsole({
105✔
206
            online,
102✔
207
        }),
105✔
208
        config('terminal') && terminal(config, {}),
105!
209
        edward({
105✔
210
            root,
105✔
211
            online,
105✔
212
            diff,
105✔
213
            zip,
105✔
214
            dropbox,
105✔
215
            dropboxToken,
105✔
216
        }),
105✔
217
        dword({
105✔
218
            root,
105✔
219
            online,
105✔
220
            diff,
105✔
221
            zip,
105✔
222
            dropbox,
105✔
223
            dropboxToken,
105✔
224
        }),
105✔
225
        qword({
105✔
226
            root,
105✔
227
            online,
105✔
228
            diff,
105✔
229
            zip,
105✔
230
            dropbox,
105✔
231
            dropboxToken,
105✔
232
        }),
105✔
233
        deepword({
105✔
234
            root,
105✔
235
            online,
105✔
236
            diff,
105✔
237
            zip,
105✔
238
            dropbox,
105✔
239
            dropboxToken,
105✔
240
        }),
105✔
241
        fileop(),
105✔
242
        nomine(),
105✔
243
        setUrl,
105✔
244
        setSW,
105✔
245
        logout,
105✔
246
        authentication(config),
105✔
247
        config.middle,
105✔
248
        modules && modulas(modules),
105✔
249
        config('dropbox') && restbox({
105!
250
            prefix: cloudfunc.apiURL,
×
251
            root,
×
252
            token: dropboxToken,
×
253
        }),
105✔
254
        restafary({
105✔
255
            prefix: cloudfunc.apiURL + '/fs',
105✔
256
            root,
105✔
257
        }),
105✔
258
        userMenu({
105✔
259
            menuName: '.cloudcmd.menu.js',
105✔
260
            config,
105✔
261
        }),
105✔
262
        rest({
105✔
263
            config,
105✔
264
            fs: depStore('fs'),
105✔
265
            moveFiles: depStore('moveFiles'),
105✔
266
        }),
105✔
267
        route(config, {
105✔
268
            html,
105✔
269
            win32: depStore('win32'),
105✔
270
        }),
105✔
271
        ponseStatic,
105✔
272
    ]);
105✔
273
    
105✔
274
    return funcs;
105✔
275
}
105✔
276

3✔
277
function logout(req, res, next) {
3,096✔
278
    if (req.url !== '/logout')
3,096✔
279
        return next();
3,096✔
280
    
3✔
281
    res.sendStatus(401);
3✔
282
}
3,096✔
283

3✔
284
export const _isDev = isDev;
3✔
285
export const _replaceDist = replaceDist;
3✔
286

3✔
287
function replaceDist(url) {
3,096✔
288
    if (!isDev())
3,096✔
289
        return url;
3,096✔
UNCOV
290
    
×
UNCOV
291
    return url.replace(/^\/dist\//, '/dist-dev/');
×
292
}
3,096✔
293

3✔
294
function setUrl(req, res, next) {
3,096✔
295
    if (/^\/cloudcmd\.js(\.map)?$/.test(req.url))
3,096✔
296
        req.url = `/dist${req.url}`;
3,096✔
297
    
3,096✔
298
    req.url = replaceDist(req.url);
3,096✔
299
    
3,096✔
300
    next();
3,096✔
301
}
3,096✔
302

3✔
303
function setSW(req, res, next) {
3,096✔
304
    const {url} = req;
3,096✔
305
    const isSW = /^\/sw\.[mc]?js(\.map)?$/.test(url);
3,096✔
306
    
3,096✔
307
    if (isSW) {
3,096!
UNCOV
308
        const url = req.url.replace(/[cm]js/, 'js');
×
UNCOV
309
        req.url = replaceDist(`/dist${url}`);
×
UNCOV
310
    }
×
311
    
3,096✔
312
    next();
3,096✔
313
}
3,096✔
314

3✔
315
assign(cloudcmd, {
3✔
316
    depStore,
3✔
317
    createConfigManager,
3✔
318
});
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc