mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-14 16:36:21 +00:00
02e2e402c3
As the title says, this commit is a massive overhaul. I've rewritten/restrucuted almost everything in the controller scripts. Because of that, there's a considerable possibility that I've broken something somewhere. Notable changes: Added temporary uploads. Removed file name length changer from dashboard, in favor of an equivalent in homepage config tab. This allows non-registered users to also set file name length. A bunch of other undocmented stuff. I don't know, I'm too tired to remember them all.
70 lines
2.1 KiB
JavaScript
70 lines
2.1 KiB
JavaScript
const logger = require('./../logger')
|
|
const perms = require('./../controllers/permissionController')
|
|
const randomstring = require('randomstring')
|
|
|
|
const init = function (db) {
|
|
// Create the tables we need to store galleries and files
|
|
db.schema.hasTable('albums').then(exists => {
|
|
if (exists) return
|
|
db.schema.createTable('albums', function (table) {
|
|
table.increments()
|
|
table.integer('userid')
|
|
table.string('name')
|
|
table.string('identifier')
|
|
table.integer('enabled')
|
|
table.integer('timestamp')
|
|
table.integer('editedAt')
|
|
table.integer('zipGeneratedAt')
|
|
table.integer('download')
|
|
table.integer('public')
|
|
table.string('description')
|
|
}).then(() => {})
|
|
})
|
|
|
|
db.schema.hasTable('files').then(exists => {
|
|
if (exists) return
|
|
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')
|
|
table.integer('expirydate')
|
|
}).then(() => {})
|
|
})
|
|
|
|
db.schema.hasTable('users').then(exists => {
|
|
if (exists) return
|
|
db.schema.createTable('users', function (table) {
|
|
table.increments()
|
|
table.string('username')
|
|
table.string('password')
|
|
table.string('token')
|
|
table.integer('enabled')
|
|
table.integer('timestamp')
|
|
table.integer('permission')
|
|
}).then(() => {
|
|
db.table('users').where({ username: 'root' }).then((user) => {
|
|
if (user.length > 0) return
|
|
require('bcrypt').hash('root', 10, function (error, hash) {
|
|
if (error) logger.error('Error generating password hash for root')
|
|
db.table('users').insert({
|
|
username: 'root',
|
|
password: hash,
|
|
token: randomstring.generate(64),
|
|
timestamp: Math.floor(Date.now() / 1000),
|
|
permission: perms.permissions.superadmin
|
|
}).then(() => {})
|
|
})
|
|
})
|
|
})
|
|
})
|
|
}
|
|
|
|
module.exports = init
|