|
@@ -1,5 +1,5 @@
|
|
|
|
|
|
-let init = function(db){
|
|
|
+let init = function(db, config){
|
|
|
|
|
|
// Create the tables we need to store galleries and files
|
|
|
db.schema.createTableIfNotExists('gallery', function (table) {
|
|
@@ -19,6 +19,43 @@ let init = function(db){
|
|
|
table.timestamps()
|
|
|
}).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
|