Skip to content

Commit 8b15973

Browse files
authored
Merge pull request #7 from totaljs/total4
Total.js
2 parents 1a26901 + 17585a6 commit 8b15973

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2294
-844
lines changed

bundle.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ cp -a ../schemas/ schemas
88
cp -a ../public/ public
99
cp -a ../resources/ resources
1010
cp -a ../views/ views
11+
cp -a ../workers/ workers
1112
cp ../clone.sh clone.sh
1213

1314
totaljs --bundle code.bundle

changelog.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
========================= 1.5
2+
3+
- added color palette
4+
- added version parser
5+
- added Transform to Responsive
6+
- updated tree by adding `Show this folder only`
7+
18
========================= 1.4
29

310
- new and improved UI

code.bundle

Lines changed: 46 additions & 42 deletions
Large diffs are not rendered by default.

config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name : Code
22
allow_custom_titles : true
33

4-
cookie : __sauth
5-
authkey : seEdCollabo
4+
cookie (generate) : 10
5+
authkey (generate) : 10
66

77
backup : /www/tmp/backup/
88
autodiscover : /www/www/

controllers/api.js

Lines changed: 71 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
const CP = require('child_process');
12
const READDIROPTIONS = { withFileTypes: true };
23
const Path = require('path');
34
const Fs = require('fs');
4-
const Exec = require('child_process').exec;
5+
const Exec = CP.exec;
6+
const Spawn = CP.spawn;
57

68
exports.install = function() {
79

@@ -41,8 +43,10 @@ exports.install = function() {
4143
ROUTE('+GET /api/projects/timespent/', timespent);
4244
ROUTE('+GET /api/projects/{id}/modify/', files_modify);
4345
ROUTE('+GET /api/projects/{id}/bundle/', makebundle, [10000]);
44-
ROUTE('+GET /api/projects/{id}/localize/ *Projects --> @localize', [10000]);
46+
ROUTE('+GET /api/projects/{id}/wiki/ *Projects --> @wiki_make', [30000]);
47+
ROUTE('+GET /api/projects/{id}/localize/ *Projects --> @localize', [30000]);
4548
ROUTE('+GET /api/projects/discover/', autodiscover);
49+
ROUTE('GET /wiki/{id}/ *Projects --> @wiki_read');
4650

4751
ROUTE('+POST /api/database/pg/ *DBCommand --> @exec', [10000]);
4852

@@ -63,14 +67,15 @@ exports.install = function() {
6367
ROUTE('+GET /api/templates/{id}/', template);
6468
ROUTE('+GET /api/download/{id}/', files_download);
6569
ROUTE('+GET /api/metainfo/{id}/', files_metainfo);
66-
ROUTE('+POST /api/files/minify/ *Minify', files_minify);
70+
ROUTE('+POST /api/files/minify/ *Minify --> @exec');
6771
ROUTE('+GET /logout/', redirect_logout);
6872

6973
ROUTE('+GET /api/users/online/', users_online);
7074
ROUTE('+GET /api/users/refresh/', users_refresh);
7175
ROUTE('+GET /api/users/export/', users_export);
7276
ROUTE('+GET /api/common/directories/', directories);
7377
ROUTE('+GET /api/common/uid/', custom_uid);
78+
ROUTE('+GET /api/common/uid16/', custom_uid16);
7479
ROUTE('+GET /api/common/ip/', custom_ip);
7580
ROUTE('+GET /api/common/ipserver/', custom_ipsever);
7681
ROUTE('+POST /api/common/encrypt/ *Encoder --> @exec');
@@ -262,19 +267,21 @@ function users_online() {
262267
var self = this;
263268
var arr = [];
264269

265-
for (var i = 0; i < MAIN.ws._keys.length; i++) {
266-
var key = MAIN.ws._keys[i];
267-
var conn = MAIN.ws.connections[key];
270+
if (MAIN.ws && MAIN.ws.keys) {
271+
for (var i = 0; i < MAIN.ws.keys.length; i++) {
272+
var key = MAIN.ws.keys[i];
273+
var conn = MAIN.ws.connections[key];
268274

269-
var item = {};
275+
var item = {};
270276

271-
var project = conn.code.projectid ? MAIN.projects.findItem('id', conn.code.projectid) : null;
272-
if (project)
273-
item.project = project.name + (conn.code.fileid || '');
277+
var project = conn.code.projectid ? MAIN.projects.findItem('id', conn.code.projectid) : null;
278+
if (project)
279+
item.project = project.name + (conn.code.fileid || '');
274280

275-
item.name = conn.user.name;
276-
item.ip = conn.ip;
277-
arr.push(item);
281+
item.name = conn.user.name;
282+
item.ip = conn.ip;
283+
arr.push(item);
284+
}
278285
}
279286

280287
self.json(arr);
@@ -289,32 +296,34 @@ function users_refresh() {
289296
self.invalid('error-permissions');
290297
}
291298

292-
function files_minify() {
293-
var self = this;
294-
self.body.$workflow('exec', (err, response) => self.plain(response || ''));
295-
}
296-
297299
function custom_uid() {
298300
this.plain(UID('custom'));
299301
}
300302

303+
function custom_uid16() {
304+
this.plain(UID16('custom'));
305+
}
306+
301307
function custom_ip() {
302308
this.plain(this.ip);
303309
}
304310

305311
function custom_ipsever() {
306312
var self = this;
307-
REQUEST('https://ipecho.net/plain', ['get'], function(err, response) {
308-
self.plain(response || 'undefined');
309-
});
313+
var opt = {};
314+
opt.url = 'https://ipecho.net/plain';
315+
opt.callback = function(err, response) {
316+
self.plain(response.body || 'undefined');
317+
};
318+
REQUEST(opt);
310319
}
311320

312321
function files_changes(id) {
313322
var self = this;
314323
var builder = NOSQL(id + '_changes').find2();
315324

316325
if (self.query.recent)
317-
builder.rule(doc => doc.type === 'save' | doc.type === 'save_sync');
326+
builder.rule('doc.type===\'save\'||doc.type===\'save_sync\'');
318327

319328
builder.take(self.query.recent ? 30 : 50).callback(function(err, response) {
320329
for (var i = 0; i < response.length; i++) {
@@ -418,15 +427,11 @@ function makerequest() {
418427
var beg = Date.now();
419428

420429
builder.exec(function(err, response, output) {
421-
if (err)
422-
self.invalid(err.toString());
423-
else {
424-
output.url = method + ' ' + url;
425-
output.value = undefined;
426-
output.duration = Date.now() - beg;
427-
output.statustext = U.httpStatus(output.status);
428-
self.json(output);
429-
}
430+
output.url = method + ' ' + url;
431+
output.value = undefined;
432+
output.duration = Date.now() - beg;
433+
output.statustext = U.httpstatus(output.status);
434+
self.json(output);
430435
});
431436
}
432437

@@ -460,11 +465,13 @@ function makerequestscript(id) {
460465
}
461466
}
462467

468+
var meta = {};
463469
var beg = Date.now();
470+
var id = self.query.id;
464471

465-
self.childtimeout = setTimeout(function() {
466-
child.kill(9);
467-
}, 19000);
472+
meta.childtimeout = setTimeout(function() {
473+
meta.child.kill(9);
474+
}, id ? (60000 * 30) : 19000);
468475

469476
var ext = U.getExtension(self.query.path);
470477
var can = { js: 1, sh: 1 };
@@ -474,13 +481,35 @@ function makerequestscript(id) {
474481
return;
475482
}
476483

477-
var child = Exec((ext === 'sh' ? 'bash ' : 'node ') + Path.join(project.path, self.query.path), function(err, stdout, stderr) {
478-
clearTimeout(self.childtimeout);
479-
var data = {};
480-
data.response = stderr || stdout;
481-
data.duration = Date.now() - beg;
482-
self.json(data);
483-
});
484+
if (id) {
485+
486+
self.success();
487+
488+
MAIN.spawns[id] = meta.child = Spawn((ext === 'sh' ? 'bash ' : 'node'), [Path.join(project.path, self.query.path)], { detached: true, cwd: project.path });
489+
meta.child.on('close', function() {
490+
delete MAIN.spawns[id];
491+
MAIN.send({ TYPE: 'spawn', id: id, body: '\n--END--\n' + (Date.now() - beg) + ' ms' }, user);
492+
clearTimeout(meta.childtimeout);
493+
meta = null;
494+
});
495+
496+
meta.child.stdout.on('data', function(data) {
497+
MAIN.send({ TYPE: 'spawn', id: id, body: data.toString('utf8') }, user);
498+
});
499+
500+
meta.child.stderr.on('data', function(data) {
501+
MAIN.send({ TYPE: 'spawn', id: id, body: data.toString('utf8'), error: true }, user);
502+
});
503+
504+
} else {
505+
meta.child = Exec((ext === 'sh' ? 'bash ' : 'node ') + Path.join(project.path, self.query.path), function(err, stdout, stderr) {
506+
clearTimeout(meta.childtimeout);
507+
var data = {};
508+
data.response = stderr || stdout;
509+
data.duration = Date.now() - beg;
510+
self.json(data);
511+
});
512+
}
484513
}
485514

486515
function timespent() {
@@ -610,7 +639,7 @@ function makebundle(id) {
610639
if (filename.toLowerCase().lastIndexOf('.bundle') === -1)
611640
filename += '.bundle';
612641

613-
F.backup(filename, project.path, function(err) {
642+
BACKUP(filename, project.path, function(err) {
614643
if (err)
615644
self.invalid(err);
616645
else {

controllers/default.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ exports.install = function() {
1010
ROUTE('+GET /docs/{id}/', docs);
1111

1212
// File routes
13-
FILE('/manifest.json', manifest);
13+
ROUTE('FILE /manifest.json', manifest);
1414
};
1515

1616
function manifest(req, res) {
@@ -26,14 +26,6 @@ function docs(id) {
2626
return;
2727
}
2828

29-
if (!self.user.sa) {
30-
var user = project.users.indexOf($.user.id);
31-
if (!user) {
32-
self.throw401();
33-
return;
34-
}
35-
}
36-
3729
NOSQL(id + '_parts').find().callback(function(err, response) {
3830
var docs = JSON.stringify(response);
3931
Fs.readFile(PATH.public('docs.html'), function(err, data) {

controllers/realtime.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const MSG_ONLINE = { TYPE: 'online' };
33
const MSG_OFFLINE = { TYPE: 'offline' };
44

55
exports.install = function() {
6-
WEBSOCKET('/', realtime, ['authorize'], 1024);
6+
ROUTE('+SOCKET /', realtime, ['text'], 1024);
77
};
88

99
function realtime() {
@@ -42,18 +42,26 @@ function realtime() {
4242
// {"TYPE":"edit"
4343
// {"TYPE":"online"
4444
// {"TYPE":"offline"
45+
// {"TYPE":"x" -> spawn destroy
4546
if (msg[9] === 'e') {
4647
msg = msg.parseJSON();
47-
client.code.fileid && refresh_collaborators(self, client);
48-
client.code.projectid = msg.projectid || '';
49-
client.code.fileid = msg.fileid;
50-
client.code.openid = (msg.openid || 0).toString();
51-
client.code.ts = Date.now();
52-
refresh_collaborators(self, client, true);
48+
if (msg) {
49+
client.code.fileid && refresh_collaborators(self, client);
50+
client.code.projectid = msg.projectid || '';
51+
client.code.fileid = msg.fileid;
52+
client.code.openid = (msg.openid || 0).toString();
53+
client.code.ts = Date.now();
54+
refresh_collaborators(self, client, true);
55+
}
5356
} else if (msg[9] === 's' && msg[12] === 'e')
54-
self.send2(msg);
55-
else
56-
self.send2(msg, openidcomparer);
57+
self.send(msg);
58+
else if (msg[9] === 'x') {
59+
msg = msg.parseJSON();
60+
if (MAIN.spawns[msg.id]) {
61+
MAIN.spawns[msg.id].kill(9);
62+
}
63+
} else
64+
self.send(msg, openidcomparer);
5765
});
5866
}
5967

@@ -70,8 +78,8 @@ function refresh_collaborators(ws, client, add) {
7078
MSG_OPEN.project = [];
7179
MSG_OPEN.file = [];
7280

73-
for (var i = 0; i < ws._keys.length; i++) {
74-
var key = ws._keys[i];
81+
for (var i = 0; i < ws.keys.length; i++) {
82+
var key = ws.keys[i];
7583
var con = ws.connections[key];
7684

7785
if (!con.code.fileid || (con.code.id !== client.code.id && !add))
@@ -89,5 +97,5 @@ function refresh_collaborators(ws, client, add) {
8997
else
9098
MSG_OPEN.TYPE = 'close';
9199

92-
ws.send2(MSG_OPEN);
100+
ws.send(MSG_OPEN);
93101
}

databases/branch_backup.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
#!/bin/sh
22

3-
tar -cvf $1 $2
4-
tar --append --file $1 $3
5-
tar --append --file $1 $4
3+
echo "$2/logs/debug.log"
4+
5+
tar --exclude="$2logs" -cvf $1 $2
6+
7+
if [ -f "$3" ]; then
8+
tar --append --file $1 $3
9+
fi
10+
11+
if [ -f "$4" ]; then
12+
tar --append --file $1 $4
13+
fi

databases/branch_restore.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/sh
22

3-
rm -r $2*
3+
# rm -r $2* !("/logs/")
4+
find $2 | grep -v "logs" | grep -v ".pid" | xargs -0 rm -rf
45
tar -xf $1 -C /

debug.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)