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

View File

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

View File

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

View File

@ -230,10 +230,10 @@ class Server {
async initializeServer(req, res) { async initializeServer(req, res) {
Logger.info(`[Server] Initializing new server`) Logger.info(`[Server] Initializing new server`)
const newRoot = req.body.newRoot 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`) 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(rootUsername, rootPash, this.auth)
await Database.createRootUser(newRoot.username, rootPash, rootToken)
res.sendStatus(200) res.sendStatus(200)
} }

View File

@ -43,7 +43,8 @@ class LibraryController {
} }
const library = new Library() 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) library.setData(newLibraryPayload)
await Database.createLibrary(library) 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) Logger.error('User other than admin attempting to update server settings', req.user)
return res.sendStatus(403) return res.sendStatus(403)
} }
var settingsUpdate = req.body const settingsUpdate = req.body
if (!settingsUpdate || !isObject(settingsUpdate)) { if (!settingsUpdate || !isObject(settingsUpdate)) {
return res.status(500).send('Invalid settings update object') return res.status(500).send('Invalid settings update object')
} }
var madeUpdates = Database.serverSettings.update(settingsUpdate) const madeUpdates = Database.serverSettings.update(settingsUpdate)
if (madeUpdates) { if (madeUpdates) {
await Database.updateServerSettings()
// If backup schedule is updated - update backup manager // If backup schedule is updated - update backup manager
if (settingsUpdate.backupSchedule !== undefined) { if (settingsUpdate.backupSchedule !== undefined) {
this.backupManager.updateCronSchedule() this.backupManager.updateCronSchedule()
} }
await Database.updateServerSettings()
} }
return res.json({ return res.json({
success: true, success: true,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -71,7 +71,9 @@ module.exports = (sequelize) => {
}) })
const { library } = sequelize.models const { library } = sequelize.models
library.hasMany(Series) library.hasMany(Series, {
onDelete: 'CASCADE'
})
Series.belongsTo(library) Series.belongsTo(library)
return Series 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({ const newRoot = new oldUser({
id: uuidv4(), id: userId,
type: 'root', type: 'root',
username, username,
pash, pash,

View File

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

View File

@ -432,7 +432,11 @@ function migrateUsers(oldUsers) {
function migrateSessions(oldSessions) { function migrateSessions(oldSessions) {
for (const oldSession of 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 // Migrate Device