This repository has been archived by the owner on Jul 16, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
153 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
var tools = require('../../server/tools'); | ||
var constant = require('../../constants'); | ||
var multipart = require('connect-multiparty'); | ||
|
||
module.exports = [multipart(), function (req, res) { | ||
|
||
if (!req.files ||!req.files.file || !req.files.file.name || !req.files.file.path) { | ||
return res.json({error: 'Upload error'}); | ||
} | ||
|
||
var file = req.files.file; | ||
var sources = []; | ||
|
||
handleFile(file.path, file.name, sources) | ||
.then(function () { | ||
return tools.fs.unlink(file.path); | ||
}) | ||
.then(function () { | ||
return tools.source.reload(); | ||
}) | ||
.then(function () { | ||
return tools.source.list(); | ||
}) | ||
.then(function (sources) { | ||
res.json({ | ||
sources: sources.map(function (source) { | ||
return source.toJSON(); | ||
}) | ||
}); | ||
}) | ||
.catch(function (err) { | ||
res.send({error: err ? err.message : 'Unknown error'}); | ||
}); | ||
}]; | ||
|
||
/** | ||
* Try to identify an archive as a source package | ||
* @param {string} source | ||
* @param {string} filename - Original filename (if different from source) | ||
* @param {array} sources output | ||
* @return {Promise} | ||
*/ | ||
function handleFile (source, filename, sources) { | ||
|
||
filename = filename || path.basename(source); | ||
|
||
if (!tools.compression.hasArchiveExtension(filename)) { | ||
return Promise.resolve(false); | ||
} | ||
|
||
return tools.compression.uncompressToTmp(source, ['js', 'json', 'jpg', 'png', 'gif']) | ||
.then(function (result) { | ||
try { | ||
var source = require(result.tmpPath); | ||
if (source.guid) { | ||
return tools.fs.rename(result.tmpPath, constant.SOURCES_PATH + '/' + source.guid); | ||
} | ||
} catch (err) { | ||
return tools.fs.rmTmpDir(result.tmpPath); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var path = require('path'); | ||
|
||
var exports = module.exports = {}; | ||
|
||
exports.SOURCES_PATH = path.resolve('sources'); | ||
|
||
Object.freeze(exports); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
#sources | ||
#sources.dropable(ng-class="{uploading: uploading.length}", ngf-drop, ngf-select, ng-model='files', ngf-drag-over-class="'dragover'", ngf-multiple='true', ngf-select-disabled='true', ngf-allow-dir='true') | ||
|
||
#pictures | ||
i.fa.fa-cloud | ||
|
||
h1 {{system.name}} | ||
|
||
uploading-list(list="uploading") | ||
|
||
.no-entry(ng-if="!sources.length") | ||
span No source found | ||
|
||
.channel(ng-repeat="source in sources", ui-sref="source({sourceId: source.id})") | ||
.box | ||
span.helper | ||
img(ng-if="source.picture", ng-src="{{'images/sources/' + source.id + '/' + source.picture}}") | ||
.footer | ||
span {{source.name}} | ||
span {{source.name}} | ||
|
||
.drop-label | ||
i.fa.fa-download | ||
span Drop your SOURCEs files here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters