Prettier-only formatting changes

This commit is contained in:
mikiher 2024-05-07 18:16:32 +03:00
parent cb1ebd4a17
commit a668921e29

View File

@ -25,9 +25,11 @@ module.exports = {
if (user.permissions.selectedTagsNotAccessible) { if (user.permissions.selectedTagsNotAccessible) {
bookWhere.push(Sequelize.where(Sequelize.literal(`(SELECT count(*) FROM json_each(tags) WHERE json_valid(tags) AND json_each.value IN (:userTagsSelected))`), 0)) bookWhere.push(Sequelize.where(Sequelize.literal(`(SELECT count(*) FROM json_each(tags) WHERE json_valid(tags) AND json_each.value IN (:userTagsSelected))`), 0))
} else { } else {
bookWhere.push(Sequelize.where(Sequelize.literal(`(SELECT count(*) FROM json_each(tags) WHERE json_valid(tags) AND json_each.value IN (:userTagsSelected))`), { bookWhere.push(
Sequelize.where(Sequelize.literal(`(SELECT count(*) FROM json_each(tags) WHERE json_valid(tags) AND json_each.value IN (:userTagsSelected))`), {
[Sequelize.Op.gte]: 1 [Sequelize.Op.gte]: 1
})) })
)
} }
} }
return { return {
@ -170,7 +172,7 @@ module.exports = {
Sequelize.where(Sequelize.fn('json_array_length', Sequelize.col('audioFiles')), 0), Sequelize.where(Sequelize.fn('json_array_length', Sequelize.col('audioFiles')), 0),
{ {
'$mediaProgresses.isFinished$': true, '$mediaProgresses.isFinished$': true,
'ebookFile': { ebookFile: {
[Sequelize.Op.not]: null [Sequelize.Op.not]: null
} }
} }
@ -285,11 +287,7 @@ module.exports = {
*/ */
async getCollapseSeriesBooksToExclude(bookFindOptions, seriesWhere) { async getCollapseSeriesBooksToExclude(bookFindOptions, seriesWhere) {
const allSeries = await Database.seriesModel.findAll({ const allSeries = await Database.seriesModel.findAll({
attributes: [ attributes: ['id', 'name', [Sequelize.literal('(SELECT count(*) FROM bookSeries bs WHERE bs.seriesId = series.id)'), 'numBooks']],
'id',
'name',
[Sequelize.literal('(SELECT count(*) FROM bookSeries bs WHERE bs.seriesId = series.id)'), 'numBooks']
],
distinct: true, distinct: true,
subQuery: false, subQuery: false,
where: seriesWhere, where: seriesWhere,
@ -304,14 +302,12 @@ module.exports = {
required: true required: true
} }
], ],
order: [ order: [Sequelize.literal('CAST(`books.bookSeries.sequence` AS FLOAT) ASC NULLS LAST')]
Sequelize.literal('CAST(`books.bookSeries.sequence` AS FLOAT) ASC NULLS LAST')
]
}) })
const bookSeriesToInclude = [] const bookSeriesToInclude = []
const booksToInclude = [] const booksToInclude = []
let booksToExclude = [] let booksToExclude = []
allSeries.forEach(s => { allSeries.forEach((s) => {
let found = false let found = false
for (let book of s.books) { for (let book of s.books) {
if (!found && !booksToInclude.includes(book.id)) { if (!found && !booksToInclude.includes(book.id)) {
@ -320,7 +316,7 @@ module.exports = {
id: book.bookSeries.id, id: book.bookSeries.id,
numBooks: s.dataValues.numBooks numBooks: s.dataValues.numBooks
}) })
booksToExclude = booksToExclude.filter(bid => bid !== book.id) booksToExclude = booksToExclude.filter((bid) => bid !== book.id)
found = true found = true
} else if (!booksToExclude.includes(book.id) && !booksToInclude.includes(book.id)) { } else if (!booksToExclude.includes(book.id) && !booksToInclude.includes(book.id)) {
booksToExclude.push(book.id) booksToExclude.push(book.id)
@ -363,15 +359,11 @@ module.exports = {
let bookAttributes = null let bookAttributes = null
if (sortBy === 'media.metadata.authorNameLF') { if (sortBy === 'media.metadata.authorNameLF') {
bookAttributes = { bookAttributes = {
include: [ include: [[Sequelize.literal(`(SELECT group_concat(a.lastFirst, ", ") FROM authors AS a, bookAuthors as ba WHERE ba.authorId = a.id AND ba.bookId = book.id)`), 'author_name']]
[Sequelize.literal(`(SELECT group_concat(a.lastFirst, ", ") FROM authors AS a, bookAuthors as ba WHERE ba.authorId = a.id AND ba.bookId = book.id)`), 'author_name']
]
} }
} else if (sortBy === 'media.metadata.authorName') { } else if (sortBy === 'media.metadata.authorName') {
bookAttributes = { bookAttributes = {
include: [ include: [[Sequelize.literal(`(SELECT group_concat(a.name, ", ") FROM authors AS a, bookAuthors as ba WHERE ba.authorId = a.id AND ba.bookId = book.id)`), 'author_name']]
[Sequelize.literal(`(SELECT group_concat(a.name, ", ") FROM authors AS a, bookAuthors as ba WHERE ba.authorId = a.id AND ba.bookId = book.id)`), 'author_name']
]
} }
} }
@ -386,9 +378,7 @@ module.exports = {
model: Database.seriesModel, model: Database.seriesModel,
attributes: ['id', 'name', 'nameIgnorePrefix'] attributes: ['id', 'name', 'nameIgnorePrefix']
}, },
order: [ order: [['createdAt', 'ASC']],
['createdAt', 'ASC']
],
separate: true separate: true
} }
@ -399,9 +389,7 @@ module.exports = {
model: Database.authorModel, model: Database.authorModel,
attributes: ['id', 'name'] attributes: ['id', 'name']
}, },
order: [ order: [['createdAt', 'ASC']],
['createdAt', 'ASC']
],
separate: true separate: true
} }
@ -427,7 +415,7 @@ module.exports = {
} }
} else if (filterGroup === 'ebooks' && filterValue === 'no-supplementary') { } else if (filterGroup === 'ebooks' && filterValue === 'no-supplementary') {
libraryItemWhere['libraryFiles'] = { libraryItemWhere['libraryFiles'] = {
[Sequelize.Op.notLike]: Sequelize.literal(`\'%"isSupplementary":true%\'`), [Sequelize.Op.notLike]: Sequelize.literal(`\'%"isSupplementary":true%\'`)
} }
} else if (filterGroup === 'missing' && filterValue === 'authors') { } else if (filterGroup === 'missing' && filterValue === 'authors') {
authorInclude = { authorInclude = {
@ -496,7 +484,7 @@ module.exports = {
}) })
} else if (filterGroup === 'recent') { } else if (filterGroup === 'recent') {
libraryItemWhere['createdAt'] = { libraryItemWhere['createdAt'] = {
[Sequelize.Op.gte]: new Date(new Date() - (60 * 24 * 60 * 60 * 1000)) // 60 days ago [Sequelize.Op.gte]: new Date(new Date() - 60 * 24 * 60 * 60 * 1000) // 60 days ago
} }
} }
@ -551,9 +539,9 @@ module.exports = {
// When collapsing series and sorting by title then use the series name instead of the book title // When collapsing series and sorting by title then use the series name instead of the book title
// for this set an attribute "display_title" to use in sorting // for this set an attribute "display_title" to use in sorting
if (global.ServerSettings.sortingIgnorePrefix) { if (global.ServerSettings.sortingIgnorePrefix) {
bookAttributes.include.push([Sequelize.literal(`IFNULL((SELECT s.nameIgnorePrefix FROM bookSeries AS bs, series AS s WHERE bs.seriesId = s.id AND bs.bookId = book.id AND bs.id IN (${bookSeriesToInclude.map(v => `"${v.id}"`).join(', ')})), titleIgnorePrefix)`), 'display_title']) bookAttributes.include.push([Sequelize.literal(`IFNULL((SELECT s.nameIgnorePrefix FROM bookSeries AS bs, series AS s WHERE bs.seriesId = s.id AND bs.bookId = book.id AND bs.id IN (${bookSeriesToInclude.map((v) => `"${v.id}"`).join(', ')})), titleIgnorePrefix)`), 'display_title'])
} else { } else {
bookAttributes.include.push([Sequelize.literal(`IFNULL((SELECT s.name FROM bookSeries AS bs, series AS s WHERE bs.seriesId = s.id AND bs.bookId = book.id AND bs.id IN (${bookSeriesToInclude.map(v => `"${v.id}"`).join(', ')})), \`book\`.\`title\`)`), 'display_title']) bookAttributes.include.push([Sequelize.literal(`IFNULL((SELECT s.name FROM bookSeries AS bs, series AS s WHERE bs.seriesId = s.id AND bs.bookId = book.id AND bs.id IN (${bookSeriesToInclude.map((v) => `"${v.id}"`).join(', ')})), \`book\`.\`title\`)`), 'display_title'])
} }
} }
@ -598,9 +586,9 @@ module.exports = {
// For showing details of collapsed series // For showing details of collapsed series
if (collapseseries && book.bookSeries?.length) { if (collapseseries && book.bookSeries?.length) {
const collapsedSeries = book.bookSeries.find(bs => collapseSeriesBookSeries.some(cbs => cbs.id === bs.id)) const collapsedSeries = book.bookSeries.find((bs) => collapseSeriesBookSeries.some((cbs) => cbs.id === bs.id))
if (collapsedSeries) { if (collapsedSeries) {
const collapseSeriesObj = collapseSeriesBookSeries.find(csbs => csbs.id === collapsedSeries.id) const collapseSeriesObj = collapseSeriesBookSeries.find((csbs) => csbs.id === collapsedSeries.id)
libraryItem.collapsedSeries = { libraryItem.collapsedSeries = {
id: collapsedSeries.series.id, id: collapsedSeries.series.id,
name: collapsedSeries.series.name, name: collapsedSeries.series.name,
@ -655,9 +643,7 @@ module.exports = {
const userPermissionBookWhere = this.getUserPermissionBookWhereQuery(user) const userPermissionBookWhere = this.getUserPermissionBookWhereQuery(user)
bookWhere.push(...userPermissionBookWhere.bookWhere) bookWhere.push(...userPermissionBookWhere.bookWhere)
let includeAttributes = [ let includeAttributes = [[Sequelize.literal('(SELECT max(mp.updatedAt) FROM bookSeries bs, mediaProgresses mp WHERE mp.mediaItemId = bs.bookId AND mp.userId = :userId AND bs.seriesId = series.id)'), 'recent_progress']]
[Sequelize.literal('(SELECT max(mp.updatedAt) FROM bookSeries bs, mediaProgresses mp WHERE mp.mediaItemId = bs.bookId AND mp.userId = :userId AND bs.seriesId = series.id)'), 'recent_progress'],
]
let booksNotFinishedQuery = `SELECT count(*) FROM bookSeries bs LEFT OUTER JOIN mediaProgresses mp ON mp.mediaItemId = bs.bookId AND mp.userId = :userId WHERE bs.seriesId = series.id AND (mp.isFinished = 0 OR mp.isFinished IS NULL)` let booksNotFinishedQuery = `SELECT count(*) FROM bookSeries bs LEFT OUTER JOIN mediaProgresses mp ON mp.mediaItemId = bs.bookId AND mp.userId = :userId WHERE bs.seriesId = series.id AND (mp.isFinished = 0 OR mp.isFinished IS NULL)`
if (library.settings.onlyShowLaterBooksInContinueSeries) { if (library.settings.onlyShowLaterBooksInContinueSeries) {
@ -699,9 +685,7 @@ module.exports = {
attributes: ['bookId', 'sequence'], attributes: ['bookId', 'sequence'],
separate: true, separate: true,
subQuery: false, subQuery: false,
order: [ order: [[Sequelize.literal('CAST(sequence AS FLOAT) ASC NULLS LAST')]],
[Sequelize.literal('CAST(sequence AS FLOAT) ASC NULLS LAST')]
],
where: { where: {
'$book.mediaProgresses.isFinished$': { '$book.mediaProgresses.isFinished$': {
[Sequelize.Op.or]: [null, 0] [Sequelize.Op.or]: [null, 0]
@ -731,16 +715,15 @@ module.exports = {
] ]
} }
}, },
order: [ order: [[Sequelize.literal('recent_progress DESC')]],
[Sequelize.literal('recent_progress DESC')]
],
distinct: true, distinct: true,
subQuery: false, subQuery: false,
limit, limit,
offset offset
}) })
const libraryItems = series.map(s => { const libraryItems = series
.map((s) => {
if (!s.bookSeries.length) return null // this is only possible if user has restricted books in series if (!s.bookSeries.length) return null // this is only possible if user has restricted books in series
let bookIndex = 0 let bookIndex = 0
@ -768,7 +751,8 @@ module.exports = {
} }
libraryItem.media = book libraryItem.media = book
return libraryItem return libraryItem
}).filter(s => s) })
.filter((s) => s)
return { return {
libraryItems, libraryItems,
@ -811,9 +795,7 @@ module.exports = {
model: Database.bookModel, model: Database.bookModel,
where: userPermissionBookWhere.bookWhere where: userPermissionBookWhere.bookWhere
}, },
order: [ order: [[Sequelize.literal('CAST(sequence AS FLOAT) ASC NULLS LAST')]],
[Sequelize.literal('CAST(sequence AS FLOAT) ASC NULLS LAST')]
],
limit: 1 limit: 1
}, },
subQuery: false, subQuery: false,
@ -821,7 +803,7 @@ module.exports = {
order: Database.sequelize.random() order: Database.sequelize.random()
}) })
const booksFromSeriesToInclude = seriesNotStarted.map(se => se.bookSeries?.[0]?.bookId).filter(bid => bid) const booksFromSeriesToInclude = seriesNotStarted.map((se) => se.bookSeries?.[0]?.bookId).filter((bid) => bid)
// optional include rssFeed // optional include rssFeed
const libraryItemIncludes = [] const libraryItemIncludes = []
@ -963,7 +945,7 @@ module.exports = {
*/ */
async getLibraryItemsForSeries(oldSeries, oldUser) { async getLibraryItemsForSeries(oldSeries, oldUser) {
const { libraryItems } = await this.getFilteredLibraryItems(oldSeries.libraryId, oldUser, 'series', oldSeries.id, null, null, false, [], null, null) const { libraryItems } = await this.getFilteredLibraryItems(oldSeries.libraryId, oldUser, 'series', oldSeries.id, null, null, false, [], null, null)
return libraryItems.map(li => Database.libraryItemModel.getOldLibraryItem(li)) return libraryItems.map((li) => Database.libraryItemModel.getOldLibraryItem(li))
}, },
/** /**
@ -1201,12 +1183,10 @@ module.exports = {
libraryId libraryId
} }
}, },
order: [ order: [['duration', 'DESC']],
['duration', 'DESC']
],
limit limit
}) })
return books.map(book => { return books.map((book) => {
return { return {
id: book.libraryItem.id, id: book.libraryItem.id,
title: book.title, title: book.title,