Update Dockerfile for sqlite3, update models for cascade delete, fix backup schedule

This commit is contained in:
advplyr 2023-07-09 11:39:15 -05:00
parent 254ba1f089
commit f73a0cce72
20 changed files with 67 additions and 31 deletions

View File

@ -14,7 +14,10 @@ RUN apk update && \
apk add --no-cache --update \
curl \
tzdata \
ffmpeg
ffmpeg \
make \
python3 \
g++
COPY --from=tone /usr/local/bin/tone /usr/local/bin/
COPY --from=build /client/dist /client/dist
@ -23,6 +26,8 @@ COPY server server
RUN npm ci --only=production
RUN apk del make python3 g++
EXPOSE 80
HEALTHCHECK \
--interval=30s \

View File

@ -756,6 +756,8 @@ export default {
this.store.commit('globals/setConfirmPrompt', payload)
},
removeSeriesFromContinueListening() {
if (!this.series) return
const axios = this.$axios || this.$nuxt.$axios
this.processing = true
axios

View File

@ -236,7 +236,7 @@ class Database {
if (newCollection) {
const collectionBooks = []
oldCollection.books.forEach((libraryItemId) => {
const libraryItem = this.libraryItems.filter(li => li.id === libraryItemId)
const libraryItem = this.libraryItems.find(li => li.id === libraryItemId)
if (libraryItem) {
collectionBooks.push({
collectionId: newCollection.id,

View File

@ -230,10 +230,10 @@ class Server {
async initializeServer(req, res) {
Logger.info(`[Server] Initializing new server`)
const newRoot = req.body.newRoot
let rootPash = newRoot.password ? await this.auth.hashPass(newRoot.password) : ''
const rootUsername = newRoot.username || 'root'
const rootPash = newRoot.password ? await this.auth.hashPass(newRoot.password) : ''
if (!rootPash) Logger.warn(`[Server] Creating root user with no password`)
let rootToken = await this.auth.generateAccessToken({ userId: 'root', username: newRoot.username })
await Database.createRootUser(newRoot.username, rootPash, rootToken)
await Database.createRootUser(rootUsername, rootPash, this.auth)
res.sendStatus(200)
}

View File

@ -43,7 +43,8 @@ class LibraryController {
}
const library = new Library()
newLibraryPayload.displayOrder = Database.libraries.length + 1
newLibraryPayload.displayOrder = Database.libraries.map(li => li.displayOrder).sort((a, b) => a - b).pop() + 1
library.setData(newLibraryPayload)
await Database.createLibrary(library)

View File

@ -112,19 +112,19 @@ class MiscController {
Logger.error('User other than admin attempting to update server settings', req.user)
return res.sendStatus(403)
}
var settingsUpdate = req.body
const settingsUpdate = req.body
if (!settingsUpdate || !isObject(settingsUpdate)) {
return res.status(500).send('Invalid settings update object')
}
var madeUpdates = Database.serverSettings.update(settingsUpdate)
const madeUpdates = Database.serverSettings.update(settingsUpdate)
if (madeUpdates) {
await Database.updateServerSettings()
// If backup schedule is updated - update backup manager
if (settingsUpdate.backupSchedule !== undefined) {
this.backupManager.updateCronSchedule()
}
await Database.updateServerSettings()
}
return res.json({
success: true,

View File

@ -1,4 +1,5 @@
const nodemailer = require('nodemailer')
const Database = require('../Database')
const Logger = require("../Logger")
class EmailManager {

View File

@ -52,6 +52,7 @@ class PlaybackSessionManager {
}
}
await Database.createDevice(deviceInfo)
return deviceInfo
}
@ -221,9 +222,6 @@ class PlaybackSessionManager {
newPlaybackSession.audioTracks = audioTracks
}
// Will save on the first sync
user.currentSessionId = newPlaybackSession.id
this.sessions.push(newPlaybackSession)
SocketAuthority.adminEmitter('user_stream_update', user.toJSONForPublic(this.sessions, Database.libraryItems))

View File

@ -77,7 +77,9 @@ module.exports = (sequelize) => {
})
const { library } = sequelize.models
library.hasMany(Author)
library.hasMany(Author, {
onDelete: 'CASCADE'
})
Author.belongsTo(library)
return Author

View File

@ -32,10 +32,14 @@ module.exports = (sequelize) => {
book.belongsToMany(collection, { through: CollectionBook })
collection.belongsToMany(book, { through: CollectionBook })
book.hasMany(CollectionBook)
book.hasMany(CollectionBook, {
onDelete: 'CASCADE'
})
CollectionBook.belongsTo(book)
collection.hasMany(CollectionBook)
collection.hasMany(CollectionBook, {
onDelete: 'CASCADE'
})
CollectionBook.belongsTo(collection)
return CollectionBook

View File

@ -32,7 +32,9 @@ module.exports = (sequelize) => {
static async getOldDeviceByDeviceId(deviceId) {
const device = await this.findOne({
deviceId
where: {
deviceId
}
})
if (!device) return null
return device.getOldDevice()
@ -105,7 +107,9 @@ module.exports = (sequelize) => {
const { user } = sequelize.models
user.hasMany(Device)
user.hasMany(Device, {
onDelete: 'CASCADE'
})
Device.belongsTo(user)
return Device

View File

@ -73,7 +73,9 @@ module.exports = (sequelize) => {
const { feed } = sequelize.models
feed.hasMany(FeedEpisode)
feed.hasMany(FeedEpisode, {
onDelete: 'CASCADE'
})
FeedEpisode.belongsTo(feed)
return FeedEpisode

View File

@ -39,18 +39,19 @@ module.exports = (sequelize) => {
* @param {object} oldLibrary
* @returns {Library|null}
*/
static createFromOld(oldLibrary) {
static async createFromOld(oldLibrary) {
const library = this.getFromOld(oldLibrary)
library.libraryFolders = oldLibrary.folders.map(folder => {
return {
id: folder.id,
path: folder.fullPath,
libraryId: library.id
path: folder.fullPath
}
})
return this.create(library).catch((error) => {
return this.create(library, {
include: sequelize.models.libraryFolder
}).catch((error) => {
Logger.error(`[Library] Failed to create library ${library.id}`, error)
return null
})

View File

@ -16,7 +16,9 @@ module.exports = (sequelize) => {
})
const { library } = sequelize.models
library.hasMany(LibraryFolder)
library.hasMany(LibraryFolder, {
onDelete: 'CASCADE'
})
LibraryFolder.belongsTo(library)
return LibraryFolder

View File

@ -134,7 +134,9 @@ module.exports = (sequelize) => {
}
})
user.hasMany(MediaProgress)
user.hasMany(MediaProgress, {
onDelete: 'CASCADE'
})
MediaProgress.belongsTo(user)
return MediaProgress

View File

@ -75,7 +75,9 @@ module.exports = (sequelize) => {
}
})
playlist.hasMany(PlaylistMediaItem)
playlist.hasMany(PlaylistMediaItem, {
onDelete: 'CASCADE'
})
PlaylistMediaItem.belongsTo(playlist)
return PlaylistMediaItem

View File

@ -71,7 +71,9 @@ module.exports = (sequelize) => {
})
const { library } = sequelize.models
library.hasMany(Series)
library.hasMany(Series, {
onDelete: 'CASCADE'
})
Series.belongsTo(library)
return Series

View File

@ -89,9 +89,13 @@ module.exports = (sequelize) => {
})
}
static async createRootUser(username, pash, token) {
static async createRootUser(username, pash, auth) {
const userId = uuidv4()
const token = await auth.generateAccessToken({ userId, username })
const newRoot = new oldUser({
id: uuidv4(),
id: userId,
type: 'root',
username,
pash,

View File

@ -90,7 +90,7 @@ class DeviceInfo {
setData(ip, ua, clientDeviceInfo, serverVersion, userId) {
this.id = uuidv4()
this.userId = userId
this.deviceId = clientDeviceInfo?.deviceId || null
this.deviceId = clientDeviceInfo?.deviceId || this.id
this.ipAddress = ip || null
this.browserName = ua?.browser.name || null

View File

@ -432,7 +432,11 @@ function migrateUsers(oldUsers) {
function migrateSessions(oldSessions) {
for (const oldSession of oldSessions) {
const userId = oldDbIdMap.users[oldSession.userId] || null // Can be null
const userId = oldDbIdMap.users[oldSession.userId]
if (!userId) {
Logger.debug(`[dbMigration] Not migrating playback session ${oldSession.id} because user was not found`)
continue
}
//
// Migrate Device