lx-scan
Version:
License eXtension to find 5-tuples of all installed packages: name, version, project home page, license (e. g. Apache v2, BSD) and required notice. It includes a GUI to edit information for each package and to enter information if necessary.
80 lines (68 loc) • 2.17 kB
JavaScript
var fs = require("fs");
var lxu = require("lxutils");
var pa = require("path");
module.exports.post = function(req,res) {
var pathToJSON,pathindex;
pathindex = req.body.jfile;
pathToJSON = req.app.locals.jfiles[pathindex];
var newPath = 0;
lxu.parseJSON(pathToJSON,function(err,jfile) {
if(err) {
// Something went wrong with the parsing
// redirect back to index with error
var errortext = ["Could not parse given file."];
if(pathToJSON="") {
res.render("index",{title:"LX Viewer",jfile:pathindex,caller:"/",error:errortext});
} else {
lxu.jRender(newpath,"index",{title:"LX Viewer",jfile:pathindex,caller:"/",error:errortext},res);
}
return;
}
if(typeof req.files.file!=='undefined') {
newPath = req.app.get("dirname") + "/lib/license_texts/"+req.files.file.originalname;
fs.rename(req.files.file.path, newPath, function(err) {
if(err) {
console.log(err);
}
});
jfile = lxu.updateJPath(jfile,req.body.entry,newPath,Number(req.body.lnumber));
} else if(typeof req.body.newlink!=='undefined' && req.body.newlink!=='') {
jfile = lxu.updateJPath(jfile,req.body.entry,req.body.newlink,Number(req.body.lnumber));
}
if(req.body.notice!=='Click to modify') {
jfile = lxu.updateJNote(jfile,req.body.entry,req.body.notice,Number(req.body.lnumber));
}
if(req.body.home!=="") {
jfile = lxu.updateJHome(jfile,req.body.entry,req.body.home);
}
var type;
switch( ((typeof req.body.type==='undefined') ? 0:req.body.type)) {
case 'apa':
type = 'Apache v2';
break;
case 'bsd':
type = 'BSD';
break;
case 'isc':
type = 'ISC';
break;
case 'mit':
type = 'MIT';
break;
case 'oth':
type = req.body.lchange;
break;
default:
type = 0;
}
if(type) {
jfile = lxu.updateJType(jfile,req.body.entry,type);
}
lxu.writeJSON(pathToJSON,jfile,function() {
var path = typeof req.body.terse === "undefined" ? "/?jfile=" : "/terse?jfile=";
path += pathindex;
path += typeof req.body.path === "undefined" ? "" : ("&path="+req.body.path);
res.redirect(path);
});
});
};