Browse Source

Change from gallery to album

Pitu 7 years ago
parent
commit
c4b5457891
5 changed files with 58 additions and 157 deletions
  1. 32 0
      controllers/albumsController.js
  2. 0 34
      controllers/galleryController.js
  3. 5 5
      pages/panel.html
  4. 18 115
      public/js/panel.js
  5. 3 3
      routes/api.js

+ 32 - 0
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

+ 0 - 34
controllers/galleryController.js

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

+ 5 - 5
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>

+ 18 - 115
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();
+}

+ 3 - 3
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