diff options
| -rw-r--r-- | .gitignore | 4 | ||||
| -rw-r--r-- | config.sample.js | 3 | ||||
| -rw-r--r-- | controllers/uploadController.js | 9 | ||||
| -rw-r--r-- | lolisafe.js | 22 |
4 files changed, 31 insertions, 7 deletions
@@ -1,8 +1,10 @@ .DS_Store +!.gitkeep node_modules/ uploads/ logs/ database/db config.js start.json -npm-debug.log
\ No newline at end of file +npm-debug.log +pages/custom/**
\ No newline at end of file diff --git a/config.sample.js b/config.sample.js index 04b87ea..53c6b11 100644 --- a/config.sample.js +++ b/config.sample.js @@ -31,6 +31,9 @@ module.exports = { // Port on which to run the server port: 9999, + // Pages to process for the frontend + pages: ['home', 'auth', 'dashboard', 'faq'], + // Uploads config uploads: { diff --git a/controllers/uploadController.js b/controllers/uploadController.js index 3d41116..e819790 100644 --- a/controllers/uploadController.js +++ b/controllers/uploadController.js @@ -77,7 +77,14 @@ uploadsController.upload = function(req, res, next){ stream.on('end', function () { let fileHash = hash.digest('hex') // 34f7a3113803f8ed3b8fd7ce5656ebec - db.table('files').where({ + db.table('files') + .where(function(){ + if(userid === undefined) + this.whereNull('userid') + else + this.where('userid', userid) + }) + .where({ hash: fileHash, size: file.size }).then((dbfile) => { diff --git a/lolisafe.js b/lolisafe.js index 52d0c4f..dc749ee 100644 --- a/lolisafe.js +++ b/lolisafe.js @@ -9,6 +9,7 @@ const safe = express() require('./database/db.js')(db) +fs.existsSync('./pages/custom' ) || fs.mkdirSync('./pages/custom') fs.existsSync('./' + config.logsFolder) || fs.mkdirSync('./' + config.logsFolder) fs.existsSync('./' + config.uploads.folder) || fs.mkdirSync('./' + config.uploads.folder) fs.existsSync('./' + config.uploads.folder + '/thumbs') || fs.mkdirSync('./' + config.uploads.folder + '/thumbs') @@ -26,11 +27,22 @@ safe.use('/', express.static('./uploads')) safe.use('/', express.static('./public')) safe.use('/api', api) -safe.get('/', (req, res, next) => res.sendFile('home.html', { root: './pages/' })) -safe.get('/faq', (req, res, next) => res.sendFile('faq.html', { root: './pages/' })) -safe.get('/auth', (req, res, next) => res.sendFile('auth.html', { root: './pages/' })) -safe.get('/dashboard', (req, res, next) => res.sendFile('dashboard.html', { root: './pages/' })) +for(let page of config.pages){ + let root = './pages/' + if(fs.existsSync(`./pages/custom/${page}.html`)) + root = './pages/custom/' + + if(page === 'home') safe.get('/', (req, res, next) => res.sendFile(`${page}.html`, { root: root })) + else safe.get(`/${page}`, (req, res, next) => res.sendFile(`${page}.html`, { root: root })) +} + safe.use((req, res, next) => res.status(404).sendFile('404.html', { root: './pages/error/' })) safe.use((req, res, next) => res.status(500).sendFile('500.html', { root: './pages/error/' })) -safe.listen(config.port, () => console.log(`loli-safe started on port ${config.port}`))
\ No newline at end of file +safe.listen(config.port, () => console.log(`loli-safe started on port ${config.port}`)) + +safe.prepareFrontendRoutes = function(){ + + + +}
\ No newline at end of file |