mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-31 07:11:33 +00:00
Updates and merged changes from 'master'
* Removing files from an album will now update the state of the said album. Which means, the Download Album as zip feature will properly make a new zip instead of re-using the old one which would obviously still have the said files. * "migration.js" will no longer try to create column if it already exists. * Changed type of all columns that used to be DATETIME to INTEGER. Apparently SQLite would have stored them as INTEGER anyways, so you don't have to change anything else.
This commit is contained in:
commit
aea89ecbd4
@ -248,6 +248,8 @@ albumsController.addFiles = async (req, res, next) => {
|
||||
if (typeof albumid !== 'number') { albumid = parseInt(albumid) }
|
||||
if (isNaN(albumid) || (albumid < 0)) { albumid = null }
|
||||
|
||||
const albumIds = []
|
||||
|
||||
if (albumid !== null) {
|
||||
const album = await db.table('albums')
|
||||
.where({
|
||||
@ -262,6 +264,8 @@ albumsController.addFiles = async (req, res, next) => {
|
||||
description: 'Album doesn\'t exist or it doesn\'t belong to the user.'
|
||||
})
|
||||
}
|
||||
|
||||
albumIds.push(albumid)
|
||||
}
|
||||
|
||||
const files = await db.table('files')
|
||||
@ -275,6 +279,10 @@ albumsController.addFiles = async (req, res, next) => {
|
||||
const failedIds = ids.filter(id => !files.find(file => file.id === id))
|
||||
|
||||
await Promise.all(files.map(file => {
|
||||
if (file.albumid && !albumIds.includes(file.albumid)) {
|
||||
albumIds.push(file.albumid)
|
||||
}
|
||||
|
||||
return db.table('files')
|
||||
.where('id', file.id)
|
||||
.update('albumid', albumid)
|
||||
@ -285,11 +293,11 @@ albumsController.addFiles = async (req, res, next) => {
|
||||
}))
|
||||
|
||||
if (failedIds.length < ids.length) {
|
||||
if (albumid !== null) {
|
||||
await db.table('albums')
|
||||
await Promise.all(albumIds.map(albumid => {
|
||||
return db.table('albums')
|
||||
.where('id', albumid)
|
||||
.update('editedAt', Math.floor(Date.now() / 1000))
|
||||
}
|
||||
}))
|
||||
return res.json({
|
||||
success: true,
|
||||
failedIds
|
||||
|
@ -9,8 +9,8 @@ let init = function (db) {
|
||||
table.string('identifier')
|
||||
table.integer('enabled')
|
||||
table.integer('timestamp')
|
||||
table.dateTime('editedAt')
|
||||
table.dateTime('zipGeneratedAt')
|
||||
table.integer('editedAt')
|
||||
table.integer('zipGeneratedAt')
|
||||
}).then(() => {})
|
||||
}
|
||||
})
|
||||
|
@ -1,12 +1,31 @@
|
||||
const config = require('../config.js')
|
||||
const db = require('knex')(config.database)
|
||||
|
||||
const map = {
|
||||
albums: {
|
||||
editedAt: 'integer',
|
||||
zipGeneratedAt: 'integer'
|
||||
},
|
||||
users: {
|
||||
enabled: 'integer',
|
||||
fileLength: 'integer'
|
||||
}
|
||||
}
|
||||
|
||||
const migration = {}
|
||||
migration.start = async () => {
|
||||
await db.schema.table('albums', t => t.dateTime('editedAt')).catch(error => console.warn(error.message))
|
||||
await db.schema.table('albums', t => t.dateTime('zipGeneratedAt')).catch(error => console.warn(error.message))
|
||||
await db.schema.table('users', t => t.dateTime('enabled')).catch(error => console.warn(error.message))
|
||||
await db.schema.table('users', t => t.dateTime('fileLength')).catch(error => console.warn(error.message))
|
||||
const tables = Object.keys(map)
|
||||
await Promise.all(tables.map(table => {
|
||||
const columns = Object.keys(map[table])
|
||||
return Promise.all(columns.map(async column => {
|
||||
if (await db.schema.hasColumn(table, column)) { return }
|
||||
const columnType = map[table][column]
|
||||
return db.schema.table(table, t => { t[columnType](column) })
|
||||
.then(() => console.log(`Added column "${column}" to table "${table}".`))
|
||||
.catch(console.error)
|
||||
}))
|
||||
}))
|
||||
|
||||
console.log('Migration finished! Now start lolisafe normally')
|
||||
process.exit(0)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user