filesafe/database/db.js
Bobby Wibowo e5f5fb1038
Updates
* You can now disable using icons in home's footer links by setting "home_icons" to false in _globals.njk.

* Renamed "meta" block to "opengraph" in _layout.njk, since the block only represents opengraph tags anyways.

* Moved noscript warning to its own file at views/_partial/noscript.njk. It's also now being included in dashboard and auth pages.

* No-JS uploader will no longer use icons in its footer links. It will also no longer load fontello.css.

* Updated static files' version string in _globals.njk.

* Some other tweaks, mainly to get no-icons mode to work properly.
2018-04-24 02:58:44 +07:00

65 lines
1.8 KiB
JavaScript

const 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.integer('editedAt')
table.integer('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 (error, hash) {
if (error) { 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