Personal blog written from scratch using Node.js, Bootstrap, and MySQL. https://jrtechs.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

56 lines
1.6 KiB

/**
Utilities is a node modules created to make tasks like
including html files easier for me programming.
*/
const Promise = require('promise');
const utils = require('../utils/utils.js');
const sql = require('../utils/sql');
module.exports=
{
/**
* TODO
* @param res
* @param requestURL
* @param request
* @returns {*|Promise}
*/
main: function(res, requestURL, request)
{
return new Promise(function(resolve, reject)
{
var urlSplit = requestURL.split("/");
console.log(urlSplit);
if(urlSplit.length == 3 || urlSplit.length == 4)
{
console.log(urlSplit[2]);
sql.getDownload(urlSplit[2]).then(function(result)
{
console.log(result);
if(result.length == 1)
{
const file = './downloads/content/' + result[0].file;
res.download(file);
}
else
{
utils.print404(res).then(function()
{
resolve();
})
}
});
}
else
{
utils.print404().then(function(content)
{
resolve(content);
})
}
});
}
};