Browse Source

Updated the downloads route to work.

pull/61/head
jrtechs 5 years ago
parent
commit
f4e0438361
6 changed files with 18 additions and 27 deletions
  1. +4
    -13
      includes/downloads.js
  2. +1
    -9
      includes/includes.js
  3. +0
    -1
      includes/staticContentServer.js
  4. +2
    -1
      routes/downloads/index.js
  5. +4
    -1
      routes/index.js
  6. +7
    -2
      utils/utils.js

+ 4
- 13
includes/downloads.js View File

@ -26,13 +26,10 @@ module.exports=
return new Promise(function(resolve, reject)
{
const urlSplit = requestURL.split("/");
console.log(urlSplit);
if(urlSplit.length == 3 || urlSplit.length == 4)
if(urlSplit.length == 2 || urlSplit.length == 4)
{
console.log(urlSplit[2]);
sql.getDownload(urlSplit[2]).then(function(result)
sql.getDownload(urlSplit[1]).then(function(result)
{
console.log(result);
if(result.length == 1)
{
const file = './blogContent/downloads/' +
@ -41,19 +38,13 @@ module.exports=
}
else
{
utils.print404(res).then(function()
{
resolve();
})
utils.print404(res);
}
});
}
else
{
utils.print404().then(function(content)
{
resolve(content);
})
utils.print404(res);
}
});
}

+ 1
- 9
includes/includes.js View File

@ -133,15 +133,7 @@ module.exports =
*/
include: function(fileName)
{
try
{
return(fs.readFileSync(fileName));
}
catch (e)
{
console.log("Could not find " + fileName);
return("");
}
return readFile(fileName);
},
/**

+ 0
- 1
includes/staticContentServer.js View File

@ -2,7 +2,6 @@
const includes = require('../includes/includes.js');
/**
* @author Jeffery Russell 10-30-18
*

+ 2
- 1
routes/downloads/index.js View File

@ -3,8 +3,9 @@ const routes = require('express').Router();
/** used to parse the request URL */
const url = require('url');
routes.get('/', (request, result) =>
routes.get('*', (request, result) =>
{
console.log("ping");
const filename = url.parse(request.url, true).pathname;
require("../../includes/downloads.js").main(result, filename);
});

+ 4
- 1
routes/index.js View File

@ -6,6 +6,9 @@ routes.use('/about', about);
const contact = require('./contact');
routes.use('/contact', contact);
const downloads = require('./downloads');
routes.use('/downloads', downloads);
const includes = require('./includes');
routes.use('/includes', includes);
@ -22,7 +25,7 @@ routes.get('/', (request, result) =>
routes.get('*', (request, result) =>
{
//error
console.log("Un registered event.")
});

+ 7
- 2
utils/utils.js View File

@ -111,8 +111,13 @@ module.exports=
* @param result
* @returns {*}
*/
print404: function()
print404: function(result)
{
return this.include("includes/html/404.html");
includes.include("includes/html/404.html").then(function(html)
{
result.write(html);
result.end();
})
}
};

Loading…
Cancel
Save