2018-10-09 19:52:41 +00:00
|
|
|
const { permissions } = require('./../controllers/authController')
|
|
|
|
|
2018-04-05 10:52:57 +00:00
|
|
|
const init = function (db) {
|
2018-01-23 20:06:30 +00:00
|
|
|
// Create the tables we need to store galleries and files
|
2018-03-14 06:57:09 +00:00
|
|
|
db.schema.hasTable('albums').then(exists => {
|
|
|
|
if (!exists) {
|
|
|
|
db.schema.createTable('albums', function (table) {
|
|
|
|
table.increments()
|
|
|
|
table.integer('userid')
|
|
|
|
table.string('name')
|
|
|
|
table.string('identifier')
|
|
|
|
table.integer('enabled')
|
|
|
|
table.integer('timestamp')
|
2018-04-05 03:10:10 +00:00
|
|
|
table.integer('editedAt')
|
|
|
|
table.integer('zipGeneratedAt')
|
2018-04-28 17:26:39 +00:00
|
|
|
table.integer('download')
|
|
|
|
table.integer('public')
|
2018-03-14 06:57:09 +00:00
|
|
|
}).then(() => {})
|
|
|
|
}
|
|
|
|
})
|
2017-01-14 08:50:18 +00:00
|
|
|
|
2018-03-14 06:57:09 +00:00
|
|
|
db.schema.hasTable('files').then(exists => {
|
|
|
|
if (!exists) {
|
|
|
|
db.schema.createTable('files', function (table) {
|
|
|
|
table.increments()
|
|
|
|
table.integer('userid')
|
|
|
|
table.string('name')
|
|
|
|
table.string('original')
|
|
|
|
table.string('type')
|
|
|
|
table.string('size')
|
|
|
|
table.string('hash')
|
|
|
|
table.string('ip')
|
|
|
|
table.integer('albumid')
|
|
|
|
table.integer('timestamp')
|
|
|
|
}).then(() => {})
|
|
|
|
}
|
|
|
|
})
|
2017-01-14 08:50:18 +00:00
|
|
|
|
2018-03-14 06:57:09 +00:00
|
|
|
db.schema.hasTable('users').then(exists => {
|
|
|
|
if (!exists) {
|
|
|
|
db.schema.createTable('users', function (table) {
|
|
|
|
table.increments()
|
|
|
|
table.string('username')
|
|
|
|
table.string('password')
|
|
|
|
table.string('token')
|
|
|
|
table.integer('enabled')
|
|
|
|
table.integer('timestamp')
|
2018-04-28 17:26:39 +00:00
|
|
|
table.integer('fileLength')
|
2018-10-09 19:52:41 +00:00
|
|
|
table.integer('permission')
|
2018-03-14 06:57:09 +00:00
|
|
|
}).then(() => {
|
2018-04-23 19:58:44 +00:00
|
|
|
db.table('users').where({ username: 'root' }).then((user) => {
|
2018-03-28 17:40:50 +00:00
|
|
|
if (user.length > 0) { return }
|
2017-01-14 08:50:18 +00:00
|
|
|
|
2018-03-29 23:22:08 +00:00
|
|
|
require('bcrypt').hash('root', 10, function (error, hash) {
|
|
|
|
if (error) { console.error('Error generating password hash for root') }
|
2017-01-29 07:19:02 +00:00
|
|
|
|
2018-03-14 06:57:09 +00:00
|
|
|
db.table('users').insert({
|
|
|
|
username: 'root',
|
|
|
|
password: hash,
|
|
|
|
token: require('randomstring').generate(64),
|
2018-10-09 19:52:41 +00:00
|
|
|
timestamp: Math.floor(Date.now() / 1000),
|
|
|
|
permission: permissions.superadmin
|
2018-03-14 06:57:09 +00:00
|
|
|
}).then(() => {})
|
|
|
|
})
|
|
|
|
})
|
2018-01-23 20:06:30 +00:00
|
|
|
})
|
2018-03-14 06:57:09 +00:00
|
|
|
}
|
2018-01-23 20:06:30 +00:00
|
|
|
})
|
2017-01-16 07:45:29 +00:00
|
|
|
}
|
|
|
|
|
2018-01-23 20:06:30 +00:00
|
|
|
module.exports = init
|