2017-01-14 08:50:18 +00:00
|
|
|
|
2017-01-16 07:37:42 +00:00
|
|
|
let init = function(db, config){
|
2017-01-14 08:50:18 +00:00
|
|
|
|
|
|
|
// Create the tables we need to store galleries and files
|
2017-01-17 22:05:00 +00:00
|
|
|
db.schema.createTableIfNotExists('albums', function (table) {
|
2017-01-14 08:50:18 +00:00
|
|
|
table.increments()
|
|
|
|
table.string('name')
|
2017-01-18 05:40:14 +00:00
|
|
|
table.integer('timestamp')
|
2017-01-14 08:50:18 +00:00
|
|
|
}).then(() => {})
|
|
|
|
|
|
|
|
db.schema.createTableIfNotExists('files', function (table) {
|
|
|
|
table.increments()
|
2017-01-16 08:22:19 +00:00
|
|
|
table.string('name')
|
2017-01-16 07:21:46 +00:00
|
|
|
table.string('original')
|
|
|
|
table.string('type')
|
|
|
|
table.string('size')
|
|
|
|
table.string('ip')
|
2017-01-17 22:05:00 +00:00
|
|
|
table.integer('albumid')
|
2017-01-18 05:40:14 +00:00
|
|
|
table.integer('timestamp')
|
2017-01-14 08:50:18 +00:00
|
|
|
}).then(() => {})
|
|
|
|
|
2017-01-16 07:37:42 +00:00
|
|
|
db.schema.createTableIfNotExists('tokens', function (table) {
|
|
|
|
table.string('name')
|
|
|
|
table.string('value')
|
2017-01-18 05:40:14 +00:00
|
|
|
table.integer('timestamp')
|
2017-01-16 07:37:42 +00:00
|
|
|
}).then(() => {
|
|
|
|
|
|
|
|
// == Generate a 1 time token == //
|
|
|
|
db.table('tokens').then((tokens) => {
|
2017-01-16 07:45:29 +00:00
|
|
|
if(tokens.length !== 0) return printAndSave(config, tokens[0].value, tokens[1].value)
|
|
|
|
|
|
|
|
// This is the first launch of the app
|
|
|
|
let clientToken = require('randomstring').generate()
|
|
|
|
let adminToken = require('randomstring').generate()
|
2017-01-18 05:40:14 +00:00
|
|
|
let now = Math.floor(Date.now() / 1000)
|
2017-01-16 07:45:29 +00:00
|
|
|
|
|
|
|
db.table('tokens').insert(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
name: 'client',
|
2017-01-18 05:40:14 +00:00
|
|
|
value: clientToken,
|
|
|
|
timestamp: now
|
2017-01-16 07:45:29 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'admin',
|
2017-01-18 05:40:14 +00:00
|
|
|
value: adminToken,
|
|
|
|
timestamp: now
|
2017-01-16 07:45:29 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
).then(() => {
|
|
|
|
printAndSave(config, clientToken, adminToken)
|
|
|
|
})
|
|
|
|
|
2017-01-16 07:37:42 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
2017-01-14 08:50:18 +00:00
|
|
|
}
|
|
|
|
|
2017-01-16 07:45:29 +00:00
|
|
|
function printAndSave(config, clientToken, adminToken){
|
|
|
|
console.log('Your client token is: ' + clientToken)
|
|
|
|
console.log('Your admin token is: ' + adminToken)
|
|
|
|
config.clientToken = clientToken
|
|
|
|
config.adminToken = adminToken
|
|
|
|
}
|
|
|
|
|
2017-01-14 08:50:18 +00:00
|
|
|
module.exports = init
|