mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-15 00:46:22 +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.
58 lines
1.6 KiB
JavaScript
58 lines
1.6 KiB
JavaScript
const config = require('./../config')
|
|
const db = require('knex')(config.database)
|
|
const perms = require('./../controllers/permissionController')
|
|
|
|
const map = {
|
|
files: {
|
|
expirydate: 'integer'
|
|
},
|
|
albums: {
|
|
editedAt: 'integer',
|
|
zipGeneratedAt: 'integer',
|
|
download: 'integer',
|
|
public: 'integer',
|
|
description: 'string'
|
|
},
|
|
users: {
|
|
enabled: 'integer',
|
|
permission: 'integer'
|
|
}
|
|
}
|
|
|
|
;(async () => {
|
|
const tableNames = Object.keys(map)
|
|
for (const tableName of tableNames) {
|
|
const columnNames = Object.keys(map[tableName])
|
|
for (const columnName of columnNames) {
|
|
if (await db.schema.hasColumn(tableName, columnName))
|
|
continue
|
|
|
|
const columnType = map[tableName][columnName]
|
|
await db.schema.table(tableName, table => {
|
|
table[columnType](columnName)
|
|
})
|
|
console.log(`OK: ${tableName} <- ${columnName} (${columnType})`)
|
|
}
|
|
}
|
|
|
|
await db.table('users')
|
|
.where('username', 'root')
|
|
.first()
|
|
.update({
|
|
permission: perms.permissions.superadmin
|
|
})
|
|
.then(result => {
|
|
// NOTE: permissionController.js actually has a hard-coded check for "root" account so that
|
|
// it will always have "superadmin" permission regardless of its permission value in database
|
|
if (!result) return console.log('Unable to update root\'s permission into superadmin.')
|
|
console.log(`Updated root's permission to ${perms.permissions.superadmin} (superadmin).`)
|
|
})
|
|
|
|
console.log('Migration finished! Now you may start lolisafe normally.')
|
|
})()
|
|
.then(() => process.exit(0))
|
|
.catch(error => {
|
|
console.error(error)
|
|
process.exit(1)
|
|
})
|