mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-19 17:51:33 +00:00
2dd724f88f
* Switched standard to eslint with eslint-config-standard (and 4 more eslint plugins needed by standard). * Added "curly" eslint rule with "all" option. I like it. * Refactored all JS files to apply the new "curly" eslint rule. * Renewed axios.min.js, dropzone.min.js and sweetalert.min.js. Re-minified and added a small comment stating their version and copyright statement. * Some buttons in dashboard will now show loading icon whenever they're waiting for response from the server. * Updated README.md and .gitignore.
65 lines
1.8 KiB
JavaScript
65 lines
1.8 KiB
JavaScript
let init = function (db) {
|
|
// Create the tables we need to store galleries and files
|
|
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')
|
|
table.dateTime('editedAt')
|
|
table.dateTime('zipGeneratedAt')
|
|
}).then(() => {})
|
|
}
|
|
})
|
|
|
|
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(() => {})
|
|
}
|
|
})
|
|
|
|
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')
|
|
}).then(() => {
|
|
db.table('users').where({username: 'root'}).then((user) => {
|
|
if (user.length > 0) { return }
|
|
|
|
require('bcrypt').hash('root', 10, function (err, hash) {
|
|
if (err) { console.error('Error generating password hash for root') }
|
|
|
|
db.table('users').insert({
|
|
username: 'root',
|
|
password: hash,
|
|
token: require('randomstring').generate(64),
|
|
timestamp: Math.floor(Date.now() / 1000)
|
|
}).then(() => {})
|
|
})
|
|
})
|
|
})
|
|
}
|
|
})
|
|
}
|
|
|
|
module.exports = init
|