filesafe/database/db.js
Bobby Wibowo da86f605c6
Updates [!! run database/migration.js !!]
Added description column into albums.
So yeah, now albums can have description.
It'll only be shown in the album's edit popup and public link.

HTML chars will now be escaped from album's name and description.

Removed message warning about CDN cache from album's public link.
A shortened version will be shown as the download button's tooltip.

Darkened color of textarea's placeholder.

Bumped v1 version string.
2018-12-13 16:09:46 +07:00

73 lines
2.1 KiB
JavaScript

const perms = require('./../controllers/permissionController')
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')
table.integer('download')
table.integer('public')
table.string('description')
}).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')
table.integer('fileLength')
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) { 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),
permission: perms.permissions.superadmin
}).then(() => {})
})
})
})
}
})
}
module.exports = init