Change from gallery to album

This commit is contained in:
Pitu 2017-01-17 18:55:35 -03:00
parent e466f85a4e
commit c4b5457891
5 changed files with 63 additions and 162 deletions

View File

@ -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

View File

@ -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

View File

@ -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>

View File

@ -106,126 +106,29 @@ panel.getUploads = function(){
xhr.send(null);
}
panel.getGalleries = function(){
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
var json = JSON.parse(xhr.responseText);
if(json.success === false)
return alert(json.description);
localStorage.admintoken = token;
panel.token = token;
return panel.prepareDashboard();
}
}
xhr.open('GET', '/api/galleries', true);
xhr.setRequestHeader('auth', panel.token);
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);
}
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);
}
}
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();
});
}
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();
}
*/

View File

@ -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