Skip to content

Commit 114c06c

Browse files
committed
v2.8.0
1 parent 69ee06f commit 114c06c

File tree

5 files changed

+65
-9
lines changed

5 files changed

+65
-9
lines changed

app/mc-tool.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var mc = require('./mc');
55
var promisify = require('./helpers').promisify;
66

77
//common
8-
var inFile=name=>promisify(fs.readFile)( name, 'utf8' )
8+
var inFile = name => typeof name == 'string' ? promisify(fs.readFile)(name, 'utf8') : Promise.resolve(name.toString());
99
var outFile=name=>text=>promisify(fs.writeFile)(name,text)
1010
var toJson=a=>JSON.stringify(a,null,2);
1111
var parseJson=a=>JSON.parse(a);

app/server.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var moment = require('moment');
2323
var mkdirp = require('mkdirp');
2424
var machineId = require('node-machine-id').machineId;
2525
var yazl = require("yazl");
26+
var yauzl = require("yauzl");
2627
var crypto = require("crypto");
2728
var FormData = require('form-data');
2829
var tmp = require('tmp');
@@ -342,6 +343,54 @@ app.post('/publicate', function (req, res) {
342343
.then(a => res.send(a))
343344
.catch(e=>res.status(403).send(e))
344345
});
346+
var fetchStream = res =>
347+
new Promise((resolve, reject) => {
348+
var data = [];
349+
res.on('data', function(chunk) {
350+
data.push(chunk);
351+
}).on('end', function() {
352+
resolve(Buffer.concat(data));
353+
});
354+
})
355+
var readZip = zip =>
356+
new Promise((resolve, reject) => {
357+
var files = [];
358+
zip.readEntry();
359+
zip.on("entry", function(entry) {
360+
if (/\/$/.test(entry.fileName))
361+
zip.readEntry();
362+
else {
363+
// file entry
364+
promisify('openReadStream', zip)(entry)
365+
.then(fetchStream)
366+
.then(file => {
367+
files.push({entry: entry, file: file});
368+
zip.readEntry();
369+
})
370+
}
371+
})
372+
zip.on("end", function(){
373+
resolve(Promise.all(files))
374+
});
375+
});
376+
var httpGet = url =>
377+
new Promise((resolve, reject) => {
378+
http.get(url, function(res) {
379+
resolve(res);
380+
});
381+
})
382+
app.get('/site/:Id', function (req, res) {
383+
var url = 'http://lt.rv.ua/mc/s/getzip/' + req.params.Id;
384+
httpGet(url)
385+
.then(fetchStream)
386+
.then(buf => promisify(yauzl.fromBuffer)(buf, {lazyEntries:true}))
387+
.then(readZip)
388+
.then(files => files.map(i => ({path: i.file, name: i.entry.fileName})))
389+
.then(uploadFiles)
390+
.then(a => (SSEsend('reload'),"page/application reloaded"))
391+
.then(a => res.send(a))
392+
.catch(e => (console.error(e),res.status(403).send(e)))
393+
});
345394
app.get('/zip/:path', function (req, res) {
346395
var name = atob(decodeURI(req.params.path)).toString();
347396
Promise.all([configFiles(name != 'Marlin' && path.join(store, name)), git.Tag()])

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
"tty2html": "^1.0.0",
9090
"universal-analytics": "^0.4.13",
9191
"which": "^1.2.14",
92+
"yauzl": "^2.9.1",
9293
"yazl": "^2.4.3"
9394
},
9495
"devDependencies": {

static/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,12 @@
116116
</style>
117117
<script>
118118
//open links externally by default
119+
window.opener = window.open;
119120
if (typeof require === 'function') { //commonJS from electron
121+
var shell = require('electron').shell;
122+
window.opener = shell.openExternal;
120123
$(document).on('click', 'a[href^="http"]', function(event) {
121124
event.preventDefault();
122-
var shell = require('electron').shell;
123125
shell.openExternal(this.href);
124126
});
125127
}
@@ -409,6 +411,7 @@ <h5 class="modal-title" id="mct-restoreModalLabel">Choose desired configuration
409411
<div class="dropdown-menu" aria-labelledby="dropdownUploadLink">
410412
<button class="dropdown-item bg-warning mct-upload" title="Upload your old configuration or drag it in browser"><i class="fa fa-file"></i> Files</button>
411413
<button class="dropdown-item mct-restore" title="Get files from storage"><i class="fa fa-heart"></i> Saved</button>
414+
<button class="dropdown-item mct-published" title="Get published files from site"><i class="fa fa-globe"></i> Published</button>
412415
</div>
413416
</div>
414417
<input type="file" name="files[]" class="mct-upload" multiple style="display:none;">

static/main.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ $(function(){
394394
d.find('.col-sm-6').attr('title',title)//.tooltip(tooltip_large);
395395
}
396396
var b=d.find('button');
397-
b.eq(1).on('click', function(){ window.open("https://github.com/MarlinFirmware/Marlin/search?q=" + define + "&type=Issues&utf8=%E2%9C%93", "_blank"); })
397+
b.eq(1).on('click', function(){ window.opener("https://github.com/MarlinFirmware/Marlin/search?q=" + define + "&type=Issues&utf8=%E2%9C%93", "_blank"); })
398398
if ( def.hint == undefined )
399399
b.eq(0).remove();
400400
else
@@ -615,10 +615,13 @@ $(function(){
615615
m.modal('hide');
616616
$.ajax('/publicate/', {method: 'POST', data: m.find('[name]')})
617617
.then(function(data) {
618-
window.open('http://lt.rv.ua/mc/?h=' + location.host + '&s=' + obj.session, "_blank")
618+
window.opener('http://lt.rv.ua/mc/?h=' + location.host + '&s=' + obj.session, "_blank")
619619
})
620620
});
621621
}($('#mct-publishModal'), $('.mct-publish')));
622+
$('.mct-published').on('click', function() {
623+
window.opener('http://lt.rv.ua/mc/?h=' + location.host, "_blank");
624+
});
622625
// upload menu - restore
623626
(function(btn,m){
624627
var p=m.find('.modal-body p');
@@ -635,7 +638,7 @@ $(function(){
635638
.on('click', function() {
636639
if (selected) {
637640
var path = btoa(selected);
638-
window.open('/zip/' + encodeURI(path), '_blank');
641+
window.opener('/zip/' + encodeURI(path), '_blank');
639642
}
640643
});
641644
btn.on('click',function(){
@@ -685,6 +688,9 @@ $(function(){
685688
source.addEventListener('open', function(event) {
686689
$('.mct-consoles,.mct-pio-ports').removeAttr('disabled')
687690
});
691+
source.addEventListener('reload', function(event) {
692+
location.reload()
693+
});
688694
source.addEventListener('created', function(event) {
689695
var port= JSON.parse(event.data);
690696
createPort(port);
@@ -794,10 +800,7 @@ $(function(){
794800
text+='\n//file '+file.file.base+' Release:'+file.tag+'\n'+f;
795801
})
796802
var url=encodeURI('https://github.com/MarlinFirmware/Marlin/issues/new?title=&body='+text).replace(/\#/g,'%23');
797-
if( typeof require === 'function' )
798-
require('electron').shell.openExternal(url);
799-
else
800-
window.open(url)
803+
window.opener(url)
801804
})
802805
})
803806
}());

0 commit comments

Comments
 (0)