Merge branch 'master' into v3

This commit is contained in:
advplyr committed 2026-11-19 17:39:40 -06:00
commit ab05d7fb5f
7 files changed
+460 -32

No files matched your search

+23 -3
View File
@@ -11,11 +11,24 @@ const CoverManager = require('../managers/CoverManager')
const AuthorFinder = require('../finders/AuthorFinder')
const { reqSupportsWebp, isValidASIN, clampPositiveInt } = require('../utils/index')
const htmlSanitizer = require('../utils/htmlSanitizer')
const naturalSort = createNewSortInstance({
comparer: new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }).compare
})
/**
* @param {string} description
* @returns {string|null}
*/
function sanitizeAuthorDescription(description) {
const sanitizedDescription = htmlSanitizer.sanitize(description)
if (sanitizedDescription !== description) {
Logger.debug(`[AuthorController] Sanitized description from "${description}" to "${sanitizedDescription}"`)
}
return sanitizedDescription || null
}
/**
* @typedef RequestUserObject
* @property {import('../models/User')} user
@@ -101,6 +114,10 @@ class AuthorController {
payload[key] = req.body[key]
}
}
if (payload.description) {
payload.description = sanitizeAuthorDescription(payload.description)
}
if (!Object.keys(payload).length) {
Logger.error(`[AuthorController] Invalid request payload. No valid keys found`, req.body)
return res.status(400).send('Invalid request payload. No valid keys found')
@@ -364,9 +381,12 @@ class AuthorController {
}
}
if (authorData.description && req.author.description !== authorData.description) {
req.author.description = authorData.description
hasUpdates = true
if (authorData.description) {
const description = sanitizeAuthorDescription(authorData.description)
if (req.author.description !== description) {
req.author.description = description
hasUpdates = true
}
}
if (hasUpdates) {
+12 -7
View File
@@ -247,12 +247,17 @@ class CollectionController {
return res.status(400).send('Book already in collection')
}
// Create collectionBook record
await Database.collectionBookModel.create({
collectionId: req.collection.id,
bookId: libraryItem.mediaId,
order: collectionBooks.length + 1
})
// Create collectionBook record. A second add can pass the check above and hit the unique pair.
try {
await Database.collectionBookModel.create({
collectionId: req.collection.id,
bookId: libraryItem.mediaId,
order: collectionBooks.length + 1
})
} catch (error) {
if (error.name !== 'SequelizeUniqueConstraintError') throw error
return res.status(400).send('Book already in collection')
}
const jsonExpanded = await req.collection.getOldJsonExpanded(req.user)
if (jsonExpanded) SocketAuthority.clientEmitter(req.user.id, 'collection_updated', jsonExpanded)
res.json(jsonExpanded)
@@ -358,7 +363,7 @@ class CollectionController {
let jsonExpanded = null
if (hasUpdated) {
await Database.collectionBookModel.bulkCreate(collectionBooksToAdd)
await Database.collectionBookModel.bulkCreate(collectionBooksToAdd, { ignoreDuplicates: true })
jsonExpanded = await req.collection.getOldJsonExpanded(req.user)
if (jsonExpanded) SocketAuthority.clientEmitter(req.user.id, 'collection_updated', jsonExpanded)