mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-05 19:40:09 +00:00
Added generation of random token
This commit is contained in:
parent
9688c5ee52
commit
7b72c3e560
@ -9,9 +9,6 @@ module.exports = {
|
|||||||
// Your base domain where the app is running. Remember to finish it with '/'
|
// 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: 'YOURSUPERSECRETTOKEN',
|
|
||||||
|
|
||||||
// Port on which to run the server
|
// Port on which to run the server
|
||||||
port: 9999,
|
port: 9999,
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
let init = function(db){
|
let init = function(db, config){
|
||||||
|
|
||||||
// Create the tables we need to store galleries and files
|
// Create the tables we need to store galleries and files
|
||||||
db.schema.createTableIfNotExists('gallery', function (table) {
|
db.schema.createTableIfNotExists('gallery', function (table) {
|
||||||
@ -19,6 +19,43 @@ let init = function(db){
|
|||||||
table.timestamps()
|
table.timestamps()
|
||||||
}).then(() => {})
|
}).then(() => {})
|
||||||
|
|
||||||
|
db.schema.createTableIfNotExists('tokens', function (table) {
|
||||||
|
table.string('name')
|
||||||
|
table.string('value')
|
||||||
|
table.timestamps()
|
||||||
|
}).then(() => {
|
||||||
|
|
||||||
|
// == Generate a 1 time token == //
|
||||||
|
db.table('tokens').then((tokens) => {
|
||||||
|
if(tokens.length === 0){
|
||||||
|
|
||||||
|
// This is the first launch of the app
|
||||||
|
let clientToken = require('randomstring').generate()
|
||||||
|
let adminToken = require('randomstring').generate()
|
||||||
|
|
||||||
|
db.table('tokens').insert(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
name: 'client',
|
||||||
|
value: clientToken
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'admin',
|
||||||
|
value: adminToken
|
||||||
|
}
|
||||||
|
]
|
||||||
|
).then(() => {
|
||||||
|
console.log('Your client token is: ' + clientToken)
|
||||||
|
console.log('Your admin token is: ' + adminToken)
|
||||||
|
config.clientToken = clientToken
|
||||||
|
config.adminToken = adminToken
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = init
|
module.exports = init
|
@ -6,7 +6,7 @@ const db = require('knex')(config.database)
|
|||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const safe = express()
|
const safe = express()
|
||||||
|
|
||||||
require('./database/db.js')(db)
|
require('./database/db.js')(db, config)
|
||||||
|
|
||||||
fs.existsSync('./' + config.uploads.folder) || fs.mkdirSync('./' + config.uploads.folder)
|
fs.existsSync('./' + config.uploads.folder) || fs.mkdirSync('./' + config.uploads.folder)
|
||||||
fs.existsSync('./' + config.logsFolder) || fs.mkdirSync('./' + config.logsFolder)
|
fs.existsSync('./' + config.logsFolder) || fs.mkdirSync('./' + config.logsFolder)
|
||||||
@ -32,7 +32,4 @@ safe.use(function (err, req, res, next) {
|
|||||||
res.status(500).end()
|
res.status(500).end()
|
||||||
})
|
})
|
||||||
|
|
||||||
safe.listen(config.port, () => console.log(`loli-safe started on port ${config.port}`))
|
safe.listen(config.port, () => console.log(`loli-safe started on port ${config.port}`))
|
||||||
|
|
||||||
if(config.TOKEN !== '') console.log('Use the following token as the \'auth\' header in your requests to the API: ' + config.TOKEN)
|
|
||||||
else console.log('Running lolisafe in public mode. No token required.')
|
|
Loading…
Reference in New Issue
Block a user