From 91a7ec7286e1855ecebb7face35f1677a0f752e5 Mon Sep 17 00:00:00 2001 From: pitu Date: Sat, 14 Jan 2017 22:36:24 -0300 Subject: WIP admin, probably not smart to clone repo now --- lolisafe.js | 4 ++- pages/admin/index.html | 56 +++++++++++++++++++++++++++++++ pages/home.html | 63 +++++++++++++++++++++++++++++++++++ public/index.html | 61 ---------------------------------- routes/api.js | 21 ++++++++++++ routes/routes.js | 90 ++++++++++++++++++++++++++++++++++++++++++++------ 6 files changed, 222 insertions(+), 73 deletions(-) create mode 100644 pages/admin/index.html create mode 100644 pages/home.html delete mode 100644 public/index.html create mode 100644 routes/api.js diff --git a/lolisafe.js b/lolisafe.js index 2e9135d..ab3a3c8 100644 --- a/lolisafe.js +++ b/lolisafe.js @@ -1,4 +1,5 @@ const config = require('./config.js') +const api = require('./routes/api.js') const routes = require('./routes/routes.js') const express = require('express') const db = require('knex')(config.database) @@ -18,7 +19,8 @@ if( prefix !== '' ) safe.use('/' + prefix, express.static('./uploads')) safe.use('/', express.static('./public')) -safe.use('/api' , routes) +safe.use('/', routes) +safe.use('/api', api) safe.use(function (req, res, next) { res.status(404).sendFile('404.html', { diff --git a/pages/admin/index.html b/pages/admin/index.html new file mode 100644 index 0000000..8049be8 --- /dev/null +++ b/pages/admin/index.html @@ -0,0 +1,56 @@ + + + + loli-safe - A self hosted upload service + + + + + + +
+
+

Dashboard

+

A simple dashboard, to sort your uploaded stuff

+
+
+
+ +
+
+ +
+
+
+
+ + \ No newline at end of file diff --git a/pages/home.html b/pages/home.html new file mode 100644 index 0000000..555878c --- /dev/null +++ b/pages/home.html @@ -0,0 +1,63 @@ + + + + loli-safe - A self hosted upload service + + + + + + + +
+
+
+

+ +

+

loli-safe

+

A modern self-hosted file upload service

+ +
+
+
+ +

+ + Check +

+ + View on Github + +
+
+
+ +
+
+ +
+
+ +
+
+
+

+
+
+

+
+
+ +

+ +
+
+
+ +
+
+
+ + + \ No newline at end of file diff --git a/public/index.html b/public/index.html deleted file mode 100644 index 1b1ebab..0000000 --- a/public/index.html +++ /dev/null @@ -1,61 +0,0 @@ - - - - loli-safe - A self hosted upload service - - - - - - - -
-
-
-

- -

-

- loli-safe -

-

- A modern self-hosted file upload service -

- -
-
-
- -

- - Check -

- - View on Github - -
-
-
- -
-
-
-

-
-
-

-
-
- -

- -
-
-
- -
-
-
- - - \ No newline at end of file diff --git a/routes/api.js b/routes/api.js new file mode 100644 index 0000000..23a1a60 --- /dev/null +++ b/routes/api.js @@ -0,0 +1,21 @@ +const config = require('../config.js') +const routes = require('express').Router() +const uploadController = require('../controllers/uploadController') +const galleryController = require('../controllers/galleryController') + +routes.get ('/info', (req, res, next) => { + + if(config.TOKEN !== '') + if(req.headers.auth !== config.TOKEN) + return res.status(401).send('not-authorized') + + return res.json({ + maxFileSize: config.uploads.maxsize.slice(0, -2) + }) +}) + +routes.post ('/upload', (req, res, next) => uploadController.upload(req, res, next)) +routes.get ('/gallery', (req, res, next) => galleryController.list(req, res, next)) +routes.get ('/gallery/test', (req, res, next) => galleryController.test(req, res, next)) + +module.exports = routes \ No newline at end of file diff --git a/routes/routes.js b/routes/routes.js index 23a1a60..fcbba34 100644 --- a/routes/routes.js +++ b/routes/routes.js @@ -1,21 +1,89 @@ const config = require('../config.js') const routes = require('express').Router() -const uploadController = require('../controllers/uploadController') -const galleryController = require('../controllers/galleryController') +const path = require('path') -routes.get ('/info', (req, res, next) => { +routes.get('/', (req, res) => { + + let options = { + root: 'pages/', + dotfiles: 'deny', + headers: { + 'x-timestamp': Date.now(), + 'x-sent': true + } + } + + res.sendFile('home.html', options, function (err) { + if (err) { + console.log(err) + res.status(err.status).end() + } else { + console.log('Sent: home.html') + } + }) + +}) + +routes.get('/admin', function (req, res, next) { + + let options = { + root: 'pages/admin/', + dotfiles: 'deny', + headers: { + 'x-timestamp': Date.now(), + 'x-sent': true + } + } + + res.sendFile('index.html', options, function (err) { + if (err) { + console.log(err) + res.status(err.status).end() + } else { + console.log('Sent: index.html') + } + }) + +}) + +routes.get('/admin/:name', function (req, res, next) { + + let options = { + root: 'pages/admin/', + dotfiles: 'deny', + headers: { + 'x-timestamp': Date.now(), + 'x-sent': true + } + } + + let fileName = req.params.name + + res.sendFile(fileName, options, function (err) { + if (err) { + console.log(err) + res.status(err.status).end() + } else { + console.log('Sent:', fileName) + } + }) + +}) + +/* +routes.get('/', (req, res) => { + res.sendFile('pages/home.html') +}) + +routes.get('/dashboard', (req, res, next) => { if(config.TOKEN !== '') if(req.headers.auth !== config.TOKEN) return res.status(401).send('not-authorized') - - return res.json({ - maxFileSize: config.uploads.maxsize.slice(0, -2) - }) -}) + + return res.sendFile('pages/home.html') -routes.post ('/upload', (req, res, next) => uploadController.upload(req, res, next)) -routes.get ('/gallery', (req, res, next) => galleryController.list(req, res, next)) -routes.get ('/gallery/test', (req, res, next) => galleryController.test(req, res, next)) +}) +*/ module.exports = routes \ No newline at end of file -- cgit v1.2.3