This commit is contained in:
kanadeko 2017-01-15 03:15:08 -03:00
parent 763a43f996
commit 0c6912d2c3
9 changed files with 55 additions and 79 deletions

View File

@ -6,7 +6,7 @@ module.exports = {
Ideally the only options you should change are port and basedomain. 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/', basedomain: 'https://i.kanacchi.moe/',
// Token to use on the api. Leave blank for public // Token to use on the api. Leave blank for public

View File

@ -35,7 +35,7 @@
<div class="columns"> <div class="columns">
<div class="column"></div> <div class="column"></div>
<div class="column"><a href="/dashboard" class="is-danger">Dashboard</a></div> <div class="column"><a id='panel' href="/panel" target="_blank" class="is-danger">Dashboard</a></div>
<div class="column"></div> <div class="column"></div>
</div> </div>

View File

@ -20,7 +20,7 @@
General General
</p> </p>
<ul class="menu-list"> <ul class="menu-list">
<li><a>Frontpage</a></li> <li><a href="/">Frontpage</a></li>
<li><a>Uploads</a></li> <li><a>Uploads</a></li>
</ul> </ul>
<p class="menu-label"> <p class="menu-label">
@ -46,7 +46,7 @@
</ul> </ul>
</aside> </aside>
</div> </div>
<div class="column has-text-centered"> <div class="column has-text-centered" id='page'>
<img src="/images/logo.png"> <img src="/images/logo.png">
</div> </div>
</div> </div>

View File

@ -50,7 +50,7 @@ div#dropzone:hover {
color: #fff; color: #fff;
} }
div#uploads, p#tokenContainer { display: none; } div#uploads, p#tokenContainer, a#panel { display: none; }
img.logo { height: 200px; margin-top: 20px; } img.logo { height: 200px; margin-top: 20px; }
.dz-preview .dz-details { display: flex; } .dz-preview .dz-details { display: flex; }

BIN
public/js/.DS_Store vendored Normal file

Binary file not shown.

0
public/js/panel.js Normal file
View File

View File

@ -1,15 +1,33 @@
window.onload = function () { window.onload = function () {
var USINGTOKEN;
var maxSize = '512'; var maxSize = '512';
if(!localStorage.token){ // First check to see if the service is using token or not
document.getElementById('tokenContainer').style.display = 'flex' var xhr = new XMLHttpRequest();
document.getElementById("tokenSubmit").addEventListener("click", function(){ xhr.onreadystatechange = function() {
getInfo(document.getElementById("token").value) if (xhr.readyState == XMLHttpRequest.DONE) {
}); USINGTOKEN = JSON.parse(xhr.responseText).token;
}else{ prepareTokenThing();
getInfo(localStorage.token); }
}
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(){ function prepareDropzone(){
@ -73,15 +91,20 @@ window.onload = function () {
document.getElementById('btnGithub').style.display = 'none'; document.getElementById('btnGithub').style.display = 'none';
document.getElementById('tokenContainer').style.display = 'none'; document.getElementById('tokenContainer').style.display = 'none';
document.getElementById('uploadContainer').appendChild(div); document.getElementById('uploadContainer').appendChild(div);
document.getElementById('panel').style.display = 'block';
if(xhr.responseText.maxFileSize) maxSize = xhr.responseText.maxFileSize;
if(xhr.responseText.maxFileSize) maxSize = JSON.parse(xhr.responseText).maxFileSize;
if(token) localStorage.token = token; if(token) localStorage.token = token;
prepareDropzone(); prepareDropzone();
} }
} }
} }
xhr.open('GET', '/api/info', true); xhr.open('GET', '/api/info', true);
xhr.setRequestHeader('auth', token);
if(token !== undefined)
xhr.setRequestHeader('auth', token);
xhr.send(null); xhr.send(null);
} }
}; };

View File

@ -3,6 +3,12 @@ const routes = require('express').Router()
const uploadController = require('../controllers/uploadController') const uploadController = require('../controllers/uploadController')
const galleryController = require('../controllers/galleryController') 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) => { routes.get ('/info', (req, res, next) => {
if(config.TOKEN !== '') if(config.TOKEN !== '')

View File

@ -2,88 +2,35 @@ const config = require('../config.js')
const routes = require('express').Router() const routes = require('express').Router()
const path = require('path') const path = require('path')
routes.get('/', (req, res) => { let options = {
root: 'pages/',
let options = { dotfiles: 'deny',
root: 'pages/', headers: {
dotfiles: 'deny', 'x-timestamp': Date.now(),
headers: { 'x-sent': true
'x-timestamp': Date.now(),
'x-sent': true
}
} }
}
routes.get('/', (req, res) => {
res.sendFile('home.html', options, function (err) { res.sendFile('home.html', options, function (err) {
if (err) { if (err) {
console.log(err) console.log(err)
res.status(err.status).end() res.status(err.status).end()
} else {
console.log('Sent: home.html')
} }
}) })
}) })
routes.get('/admin', 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
}
}
res.sendFile('index.html', options, function (err) { res.sendFile('panel.html', options, function (err) {
if (err) { if (err) {
console.log(err) console.log(err)
res.status(err.status).end() 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.sendFile('pages/home.html')
})
*/
module.exports = routes module.exports = routes