aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--controllers/albumsController.js32
-rw-r--r--controllers/galleryController.js34
-rw-r--r--pages/panel.html10
-rw-r--r--public/js/panel.js133
-rw-r--r--routes/api.js6
5 files changed, 58 insertions, 157 deletions
diff --git a/controllers/albumsController.js b/controllers/albumsController.js
new file mode 100644
index 0000000..7639b3d
--- /dev/null
+++ b/controllers/albumsController.js
@@ -0,0 +1,32 @@
+const config = require('../config.js')
+const db = require('knex')(config.database)
+
+let albumsController = {}
+
+albumsController.list = function(req, res, next){
+
+ if(req.headers.auth !== config.adminToken)
+ return res.status(401).send('not-authorized')
+
+ db.table('albums').select('id', 'name').then((albums) => {
+ return res.json({ albums })
+ })
+}
+
+albumsController.test = function(req, res, next){
+
+ if(req.headers.auth !== config.adminToken)
+ return res.status(401).send('not-authorized')
+
+ let testdata = [
+ {name: 'Test 1'},
+ {name: 'Test 2'},
+ {name: 'Test 3'},
+ {name: 'Test 4'},
+ {name: 'Test 5'}
+ ]
+
+ db.table('albums').insert(testdata).then(() => {})
+}
+
+module.exports = albumsController \ No newline at end of file
diff --git a/controllers/galleryController.js b/controllers/galleryController.js
deleted file mode 100644
index 0f64086..0000000
--- a/controllers/galleryController.js
+++ /dev/null
@@ -1,34 +0,0 @@
-const config = require('../config.js')
-const db = require('knex')(config.database)
-
-let galleryController = {}
-
-galleryController.list = function(req, res, next){
-
- if(config.private === true)
- if(req.headers.auth !== config.clientToken)
- return res.status(401).send('not-authorized')
-
- db.table('gallery').select('id', 'name').then((galleries) => {
- return res.json({ galleries })
- })
-}
-
-galleryController.test = function(req, res, next){
-
- if(config.private === true)
- if(req.headers.auth !== config.clientToken)
- return res.status(401).send('not-authorized')
-
- let testdata = [
- {name: 'Test 1'},
- {name: 'Test 2'},
- {name: 'Test 3'},
- {name: 'Test 4'},
- {name: 'Test 5'}
- ]
-
- db.table('gallery').insert(testdata).then(() => {})
-}
-
-module.exports = galleryController \ No newline at end of file
diff --git a/pages/panel.html b/pages/panel.html
index a54cebb..8565264 100644
--- a/pages/panel.html
+++ b/pages/panel.html
@@ -38,14 +38,14 @@
<li><a href="/">Frontpage</a></li>
<li><a id='itemUploads'>Uploads</a></li>
</ul>
- <p class="menu-label">Galleries</p>
+ <p class="menu-label">Albums</p>
<ul class="menu-list">
- <li><a id='itemManageGallery'>Manage your galleries</a></li>
+ <li><a id='itemManageGallery'>Manage your albums</a></li>
<li>
<ul id='galleryContainer'>
- <li><a>Gallery 1</a></li>
- <li><a>Gallery 2</a></li>
- <li><a>Gallery 3</a></li>
+ <li><a>Album 1</a></li>
+ <li><a>Album 2</a></li>
+ <li><a>Album 3</a></li>
</ul>
</li>
</ul>
diff --git a/public/js/panel.js b/public/js/panel.js
index 27af9f8..e008abd 100644
--- a/public/js/panel.js
+++ b/public/js/panel.js
@@ -106,126 +106,29 @@ panel.getUploads = function(){
xhr.send(null);
}
-window.onload = function () {
- panel.preparePage();
-}
-
-/*
- var page;
-
- if(!localStorage.admintoken)
- return askForToken();
-
- prepareDashboard();
-
- function askForToken(){
- document.getElementById('tokenSubmit').addEventListener('click', function(){
- checkToken();
- });
-
- function checkToken(){
- var xhr = new XMLHttpRequest();
-
- xhr.onreadystatechange = function() {
- if (xhr.readyState == XMLHttpRequest.DONE) {
- try{
-
- var json = JSON.parse(xhr.responseText);
- if(json.success === false)
- return alert(json.description);
-
- localStorage.admintoken = document.getElementById('token').value;
- prepareDashboard();
-
- }catch(e){
- console.log(e);
- }
+panel.getGalleries = function(){
+ var xhr = new XMLHttpRequest();
- console.log(xhr.responseText);
- // xhr.responseText
- }
- }
- xhr.open('GET', '/api/token/verify', true);
- xhr.setRequestHeader('type', 'admin');
- xhr.setRequestHeader('token', document.getElementById('token').value);
- xhr.send(null);
- }
- }
+ xhr.onreadystatechange = function() {
+ if (xhr.readyState == XMLHttpRequest.DONE) {
+
+ var json = JSON.parse(xhr.responseText);
+ if(json.success === false)
+ return alert(json.description);
- function prepareDashboard(){
- page = document.getElementById('page');
- document.getElementById('auth').style.display = 'none';
- document.getElementById('dashboard').style.display = 'block';
- document.getElementById('itemUploads').addEventListener('click', function(){
- getUploads();
- });
- document.getElementById('itemManageGallery').addEventListener('click', function(){
- getGalleries();
- });
- }
+ localStorage.admintoken = token;
+ panel.token = token;
+ return panel.prepareDashboard();
- function getUploads(){
- page.innerHTML = '';
- var xhr = new XMLHttpRequest();
-
- xhr.onreadystatechange = function() {
- if(xhr.readyState == XMLHttpRequest.DONE){
-
- if(xhr.responseText === 'not-authorized')
- return notAuthorized();
-
- var json = JSON.parse(xhr.responseText);
-
- var container = document.createElement('div');
- container.innerHTML = `
- <table class="table">
- <thead>
- <tr>
- <th>File</th>
- <th>Gallery</th>
- <th>Date</th>
- </tr>
- </thead>
- <tbody id="table">
- </tbody>
- </table>`;
- page.appendChild(container);
-
- var table = document.getElementById('table');
-
- for(var item of json){
-
- var tr = document.createElement('tr');
- tr.innerHTML = `
- <tr>
- <th><a href="${item.file}" target="_blank">${item.file}</a></th>
- <th>${item.gallery}</th>
- <td>${item.date}</td>
- </tr>
- `;
-
- table.appendChild(tr);
- }
-
- }
}
- xhr.open('GET', '/api/uploads', true);
- xhr.setRequestHeader('auth', localStorage.admintoken);
- xhr.send(null);
- }
-
- function getContent(item, value){
- let endpoint;
- if(item === 'uploads') endpoint = '/api/uploads'
- if(item === 'galleries') endpoint = '/api/uploads'
-
- }
-
- function notAuthorized() {
- localStorage.removeItem("admintoken");
- location.reload();
}
+ xhr.open('GET', '/api/galleries', true);
+ xhr.setRequestHeader('auth', panel.token);
+ xhr.send(null);
+}
-*/
+window.onload = function () {
+ panel.preparePage();
+}
diff --git a/routes/api.js b/routes/api.js
index 4707a57..a759bf3 100644
--- a/routes/api.js
+++ b/routes/api.js
@@ -1,7 +1,7 @@
const config = require('../config.js')
const routes = require('express').Router()
const uploadController = require('../controllers/uploadController')
-const galleryController = require('../controllers/galleryController')
+const albumsController = require('../controllers/albumsController')
const tokenController = require('../controllers/tokenController')
routes.get ('/check', (req, res, next) => {
@@ -21,8 +21,8 @@ routes.get('/info', (req, res, next) => {
routes.get ('/uploads', (req, res, next) => uploadController.list(req, res))
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))
+routes.get ('/albums', (req, res, next) => albumsController.list(req, res, next))
+routes.get ('/albums/test', (req, res, next) => albumsController.test(req, res, next))
routes.get ('/token/verify', (req, res, next) => tokenController.verify(req, res))
module.exports = routes