From 0c6912d2c344253dc116d17a78ae364c53cb1eaa Mon Sep 17 00:00:00 2001 From: kanadeko Date: Sun, 15 Jan 2017 03:15:08 -0300 Subject: stuff --- config.sample.js | 2 +- pages/admin/index.html | 56 ------------------------------------ pages/home.html | 2 +- pages/panel.html | 56 ++++++++++++++++++++++++++++++++++++ public/css/style.css | 2 +- public/js/.DS_Store | Bin 0 -> 6148 bytes public/js/panel.js | 0 public/js/upload.js | 43 +++++++++++++++++++++------- routes/api.js | 6 ++++ routes/routes.js | 75 ++++++++----------------------------------------- 10 files changed, 109 insertions(+), 133 deletions(-) delete mode 100644 pages/admin/index.html create mode 100644 pages/panel.html create mode 100644 public/js/.DS_Store create mode 100644 public/js/panel.js diff --git a/config.sample.js b/config.sample.js index cf5f49d..ade99e0 100644 --- a/config.sample.js +++ b/config.sample.js @@ -6,7 +6,7 @@ module.exports = { Ideally the only options you should change are port and basedomain. */ - // Your base domain where the app is running. + // Your base domain where the app is running. Remember to finish it with '/' basedomain: 'https://i.kanacchi.moe/', // Token to use on the api. Leave blank for public diff --git a/pages/admin/index.html b/pages/admin/index.html deleted file mode 100644 index 8049be8..0000000 --- a/pages/admin/index.html +++ /dev/null @@ -1,56 +0,0 @@ - - - - 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 index 555878c..b4aa56d 100644 --- a/pages/home.html +++ b/pages/home.html @@ -35,7 +35,7 @@
- +
diff --git a/pages/panel.html b/pages/panel.html new file mode 100644 index 0000000..8926c46 --- /dev/null +++ b/pages/panel.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/public/css/style.css b/public/css/style.css index 324bb9d..fcd4923 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -50,7 +50,7 @@ div#dropzone:hover { color: #fff; } -div#uploads, p#tokenContainer { display: none; } +div#uploads, p#tokenContainer, a#panel { display: none; } img.logo { height: 200px; margin-top: 20px; } .dz-preview .dz-details { display: flex; } diff --git a/public/js/.DS_Store b/public/js/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/public/js/.DS_Store differ diff --git a/public/js/panel.js b/public/js/panel.js new file mode 100644 index 0000000..e69de29 diff --git a/public/js/upload.js b/public/js/upload.js index 488ca3a..be15ace 100644 --- a/public/js/upload.js +++ b/public/js/upload.js @@ -1,15 +1,33 @@ window.onload = function () { + var USINGTOKEN; var maxSize = '512'; - if(!localStorage.token){ - document.getElementById('tokenContainer').style.display = 'flex' - document.getElementById("tokenSubmit").addEventListener("click", function(){ - getInfo(document.getElementById("token").value) - }); - }else{ - getInfo(localStorage.token); + // First check to see if the service is using token or not + var xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function() { + if (xhr.readyState == XMLHttpRequest.DONE) { + USINGTOKEN = JSON.parse(xhr.responseText).token; + prepareTokenThing(); + } + } + xhr.open('GET', '/api/check', true); + xhr.send(null); + + function prepareTokenThing(){ + + if(!USINGTOKEN) return getInfo(); + + if(!localStorage.token){ + document.getElementById('tokenContainer').style.display = 'flex' + document.getElementById("tokenSubmit").addEventListener("click", function(){ + getInfo(document.getElementById("token").value) + }); + }else{ + getInfo(localStorage.token); + } + } function prepareDropzone(){ @@ -73,15 +91,20 @@ window.onload = function () { document.getElementById('btnGithub').style.display = 'none'; document.getElementById('tokenContainer').style.display = 'none'; document.getElementById('uploadContainer').appendChild(div); - - if(xhr.responseText.maxFileSize) maxSize = xhr.responseText.maxFileSize; + document.getElementById('panel').style.display = 'block'; + + if(xhr.responseText.maxFileSize) maxSize = JSON.parse(xhr.responseText).maxFileSize; if(token) localStorage.token = token; + prepareDropzone(); } } } xhr.open('GET', '/api/info', true); - xhr.setRequestHeader('auth', token); + + if(token !== undefined) + xhr.setRequestHeader('auth', token); + xhr.send(null); } }; \ No newline at end of file diff --git a/routes/api.js b/routes/api.js index 23a1a60..a4e8e0b 100644 --- a/routes/api.js +++ b/routes/api.js @@ -3,6 +3,12 @@ const routes = require('express').Router() const uploadController = require('../controllers/uploadController') const galleryController = require('../controllers/galleryController') +routes.get ('/check', (req, res, next) => { + if(config.TOKEN === '') + return res.json({token: false}) + return res.json({token: true}) +}) + routes.get ('/info', (req, res, next) => { if(config.TOKEN !== '') diff --git a/routes/routes.js b/routes/routes.js index fcbba34..c849335 100644 --- a/routes/routes.js +++ b/routes/routes.js @@ -2,88 +2,35 @@ const config = require('../config.js') const routes = require('express').Router() const path = require('path') -routes.get('/', (req, res) => { - - let options = { - root: 'pages/', - dotfiles: 'deny', - headers: { - 'x-timestamp': Date.now(), - 'x-sent': true - } +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 - } - } +routes.get('/', (req, res) => { - res.sendFile('index.html', options, function (err) { + res.sendFile('home.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) { +routes.get('/panel', 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) { + res.sendFile('panel.html', 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.sendFile('pages/home.html') - -}) -*/ - module.exports = routes \ No newline at end of file -- cgit v1.2.3