Skip to content

Commit

Permalink
v2.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
akaJes committed Nov 7, 2017
1 parent 69ee06f commit 114c06c
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/mc-tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var mc = require('./mc');
var promisify = require('./helpers').promisify;

//common
var inFile=name=>promisify(fs.readFile)( name, 'utf8' )
var inFile = name => typeof name == 'string' ? promisify(fs.readFile)(name, 'utf8') : Promise.resolve(name.toString());
var outFile=name=>text=>promisify(fs.writeFile)(name,text)
var toJson=a=>JSON.stringify(a,null,2);
var parseJson=a=>JSON.parse(a);
Expand Down
49 changes: 49 additions & 0 deletions app/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var moment = require('moment');
var mkdirp = require('mkdirp');
var machineId = require('node-machine-id').machineId;
var yazl = require("yazl");
var yauzl = require("yauzl");
var crypto = require("crypto");
var FormData = require('form-data');
var tmp = require('tmp');
Expand Down Expand Up @@ -342,6 +343,54 @@ app.post('/publicate', function (req, res) {
.then(a => res.send(a))
.catch(e=>res.status(403).send(e))
});
var fetchStream = res =>
new Promise((resolve, reject) => {
var data = [];
res.on('data', function(chunk) {
data.push(chunk);
}).on('end', function() {
resolve(Buffer.concat(data));
});
})
var readZip = zip =>
new Promise((resolve, reject) => {
var files = [];
zip.readEntry();
zip.on("entry", function(entry) {
if (/\/$/.test(entry.fileName))
zip.readEntry();
else {
// file entry
promisify('openReadStream', zip)(entry)
.then(fetchStream)
.then(file => {
files.push({entry: entry, file: file});
zip.readEntry();
})
}
})
zip.on("end", function(){
resolve(Promise.all(files))
});
});
var httpGet = url =>
new Promise((resolve, reject) => {
http.get(url, function(res) {
resolve(res);
});
})
app.get('/site/:Id', function (req, res) {
var url = 'http://lt.rv.ua/mc/s/getzip/' + req.params.Id;
httpGet(url)
.then(fetchStream)
.then(buf => promisify(yauzl.fromBuffer)(buf, {lazyEntries:true}))
.then(readZip)
.then(files => files.map(i => ({path: i.file, name: i.entry.fileName})))
.then(uploadFiles)
.then(a => (SSEsend('reload'),"page/application reloaded"))
.then(a => res.send(a))
.catch(e => (console.error(e),res.status(403).send(e)))
});
app.get('/zip/:path', function (req, res) {
var name = atob(decodeURI(req.params.path)).toString();
Promise.all([configFiles(name != 'Marlin' && path.join(store, name)), git.Tag()])
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"tty2html": "^1.0.0",
"universal-analytics": "^0.4.13",
"which": "^1.2.14",
"yauzl": "^2.9.1",
"yazl": "^2.4.3"
},
"devDependencies": {
Expand Down
5 changes: 4 additions & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,12 @@
</style>
<script>
//open links externally by default
window.opener = window.open;
if (typeof require === 'function') { //commonJS from electron
var shell = require('electron').shell;
window.opener = shell.openExternal;
$(document).on('click', 'a[href^="http"]', function(event) {
event.preventDefault();
var shell = require('electron').shell;
shell.openExternal(this.href);
});
}
Expand Down Expand Up @@ -409,6 +411,7 @@ <h5 class="modal-title" id="mct-restoreModalLabel">Choose desired configuration
<div class="dropdown-menu" aria-labelledby="dropdownUploadLink">
<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>
<button class="dropdown-item mct-restore" title="Get files from storage"><i class="fa fa-heart"></i> Saved</button>
<button class="dropdown-item mct-published" title="Get published files from site"><i class="fa fa-globe"></i> Published</button>
</div>
</div>
<input type="file" name="files[]" class="mct-upload" multiple style="display:none;">
Expand Down
17 changes: 10 additions & 7 deletions static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ $(function(){
d.find('.col-sm-6').attr('title',title)//.tooltip(tooltip_large);
}
var b=d.find('button');
b.eq(1).on('click', function(){ window.open("https://github.com/MarlinFirmware/Marlin/search?q=" + define + "&type=Issues&utf8=%E2%9C%93", "_blank"); })
b.eq(1).on('click', function(){ window.opener("https://github.com/MarlinFirmware/Marlin/search?q=" + define + "&type=Issues&utf8=%E2%9C%93", "_blank"); })
if ( def.hint == undefined )
b.eq(0).remove();
else
Expand Down Expand Up @@ -615,10 +615,13 @@ $(function(){
m.modal('hide');
$.ajax('/publicate/', {method: 'POST', data: m.find('[name]')})
.then(function(data) {
window.open('http://lt.rv.ua/mc/?h=' + location.host + '&s=' + obj.session, "_blank")
window.opener('http://lt.rv.ua/mc/?h=' + location.host + '&s=' + obj.session, "_blank")
})
});
}($('#mct-publishModal'), $('.mct-publish')));
$('.mct-published').on('click', function() {
window.opener('http://lt.rv.ua/mc/?h=' + location.host, "_blank");
});
// upload menu - restore
(function(btn,m){
var p=m.find('.modal-body p');
Expand All @@ -635,7 +638,7 @@ $(function(){
.on('click', function() {
if (selected) {
var path = btoa(selected);
window.open('/zip/' + encodeURI(path), '_blank');
window.opener('/zip/' + encodeURI(path), '_blank');
}
});
btn.on('click',function(){
Expand Down Expand Up @@ -685,6 +688,9 @@ $(function(){
source.addEventListener('open', function(event) {
$('.mct-consoles,.mct-pio-ports').removeAttr('disabled')
});
source.addEventListener('reload', function(event) {
location.reload()
});
source.addEventListener('created', function(event) {
var port= JSON.parse(event.data);
createPort(port);
Expand Down Expand Up @@ -794,10 +800,7 @@ $(function(){
text+='\n//file '+file.file.base+' Release:'+file.tag+'\n'+f;
})
var url=encodeURI('https://github.com/MarlinFirmware/Marlin/issues/new?title=&body='+text).replace(/\#/g,'%23');
if( typeof require === 'function' )
require('electron').shell.openExternal(url);
else
window.open(url)
window.opener(url)
})
})
}());
Expand Down

0 comments on commit 114c06c

Please sign in to comment.