mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-05-04 01:17:19 +02:00
Prettier-only formatting changes
This commit is contained in:
parent
cb1ebd4a17
commit
a668921e29
@ -7,7 +7,7 @@ const { asciiOnlyToLowerCase } = require('../index')
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
/**
|
/**
|
||||||
* User permissions to restrict books for explicit content & tags
|
* User permissions to restrict books for explicit content & tags
|
||||||
* @param {import('../../objects/user/User')} user
|
* @param {import('../../objects/user/User')} user
|
||||||
* @returns {{ bookWhere:Sequelize.WhereOptions, replacements:object }}
|
* @returns {{ bookWhere:Sequelize.WhereOptions, replacements:object }}
|
||||||
*/
|
*/
|
||||||
getUserPermissionBookWhereQuery(user) {
|
getUserPermissionBookWhereQuery(user) {
|
||||||
@ -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.Op.gte]: 1
|
Sequelize.where(Sequelize.literal(`(SELECT count(*) FROM json_each(tags) WHERE json_valid(tags) AND json_each.value IN (:userTagsSelected))`), {
|
||||||
}))
|
[Sequelize.Op.gte]: 1
|
||||||
|
})
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
@ -39,8 +41,8 @@ module.exports = {
|
|||||||
/**
|
/**
|
||||||
* When collapsing series and filtering by progress
|
* When collapsing series and filtering by progress
|
||||||
* different where options are required
|
* different where options are required
|
||||||
*
|
*
|
||||||
* @param {string} value
|
* @param {string} value
|
||||||
* @returns {Sequelize.WhereOptions}
|
* @returns {Sequelize.WhereOptions}
|
||||||
*/
|
*/
|
||||||
getCollapseSeriesMediaProgressFilter(value) {
|
getCollapseSeriesMediaProgressFilter(value) {
|
||||||
@ -90,8 +92,8 @@ module.exports = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get where options for Book model
|
* Get where options for Book model
|
||||||
* @param {string} group
|
* @param {string} group
|
||||||
* @param {[string]} value
|
* @param {[string]} value
|
||||||
* @returns {object} { Sequelize.WhereOptions, string[] }
|
* @returns {object} { Sequelize.WhereOptions, string[] }
|
||||||
*/
|
*/
|
||||||
getMediaGroupQuery(group, value) {
|
getMediaGroupQuery(group, value) {
|
||||||
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -232,8 +234,8 @@ module.exports = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get sequelize order
|
* Get sequelize order
|
||||||
* @param {string} sortBy
|
* @param {string} sortBy
|
||||||
* @param {boolean} sortDesc
|
* @param {boolean} sortDesc
|
||||||
* @param {boolean} collapseseries
|
* @param {boolean} collapseseries
|
||||||
* @returns {Sequelize.order}
|
* @returns {Sequelize.order}
|
||||||
*/
|
*/
|
||||||
@ -278,18 +280,14 @@ module.exports = {
|
|||||||
* When collapsing series get first book in each series
|
* When collapsing series get first book in each series
|
||||||
* to know which books to exclude from primary query.
|
* to know which books to exclude from primary query.
|
||||||
* Additionally use this query to get the number of books in each series
|
* Additionally use this query to get the number of books in each series
|
||||||
*
|
*
|
||||||
* @param {Sequelize.ModelStatic} bookFindOptions
|
* @param {Sequelize.ModelStatic} bookFindOptions
|
||||||
* @param {Sequelize.WhereOptions} seriesWhere
|
* @param {Sequelize.WhereOptions} seriesWhere
|
||||||
* @returns {object} { booksToExclude, bookSeriesToInclude }
|
* @returns {object} { booksToExclude, bookSeriesToInclude }
|
||||||
*/
|
*/
|
||||||
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)
|
||||||
@ -332,16 +328,16 @@ module.exports = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get library items for book media type using filter and sort
|
* Get library items for book media type using filter and sort
|
||||||
* @param {string} libraryId
|
* @param {string} libraryId
|
||||||
* @param {[oldUser]} user
|
* @param {[oldUser]} user
|
||||||
* @param {[string]} filterGroup
|
* @param {[string]} filterGroup
|
||||||
* @param {[string]} filterValue
|
* @param {[string]} filterValue
|
||||||
* @param {string} sortBy
|
* @param {string} sortBy
|
||||||
* @param {string} sortDesc
|
* @param {string} sortDesc
|
||||||
* @param {boolean} collapseseries
|
* @param {boolean} collapseseries
|
||||||
* @param {string[]} include
|
* @param {string[]} include
|
||||||
* @param {number} limit
|
* @param {number} limit
|
||||||
* @param {number} offset
|
* @param {number} offset
|
||||||
* @param {boolean} isHomePage for home page shelves
|
* @param {boolean} isHomePage for home page shelves
|
||||||
* @returns {object} { libraryItems:LibraryItem[], count:number }
|
* @returns {object} { libraryItems:LibraryItem[], count:number }
|
||||||
*/
|
*/
|
||||||
@ -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,
|
||||||
@ -633,11 +621,11 @@ module.exports = {
|
|||||||
* 2. Has no books in progress
|
* 2. Has no books in progress
|
||||||
* 3. Has at least 1 unfinished book
|
* 3. Has at least 1 unfinished book
|
||||||
* TODO: Reduce queries
|
* TODO: Reduce queries
|
||||||
* @param {import('../../objects/Library')} library
|
* @param {import('../../objects/Library')} library
|
||||||
* @param {import('../../objects/user/User')} user
|
* @param {import('../../objects/user/User')} user
|
||||||
* @param {string[]} include
|
* @param {string[]} include
|
||||||
* @param {number} limit
|
* @param {number} limit
|
||||||
* @param {number} offset
|
* @param {number} offset
|
||||||
* @returns {{ libraryItems:import('../../models/LibraryItem')[], count:number }}
|
* @returns {{ libraryItems:import('../../models/LibraryItem')[], count:number }}
|
||||||
*/
|
*/
|
||||||
async getContinueSeriesLibraryItems(library, user, include, limit, offset) {
|
async getContinueSeriesLibraryItems(library, user, include, limit, offset) {
|
||||||
@ -655,15 +643,13 @@ 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) {
|
||||||
const maxSequenceQuery = `(SELECT CAST(max(bs.sequence) as FLOAT) FROM bookSeries bs, mediaProgresses mp WHERE mp.mediaItemId = bs.bookId AND mp.isFinished = 1 AND mp.userId = :userId AND bs.seriesId = series.id)`
|
const maxSequenceQuery = `(SELECT CAST(max(bs.sequence) as FLOAT) FROM bookSeries bs, mediaProgresses mp WHERE mp.mediaItemId = bs.bookId AND mp.isFinished = 1 AND mp.userId = :userId AND bs.seriesId = series.id)`
|
||||||
includeAttributes.push([Sequelize.literal(`${maxSequenceQuery}`), 'maxSequence'])
|
includeAttributes.push([Sequelize.literal(`${maxSequenceQuery}`), 'maxSequence'])
|
||||||
|
|
||||||
booksNotFinishedQuery = booksNotFinishedQuery + ` AND CAST(bs.sequence as FLOAT) > ${maxSequenceQuery}`
|
booksNotFinishedQuery = booksNotFinishedQuery + ` AND CAST(bs.sequence as FLOAT) > ${maxSequenceQuery}`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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,44 +715,44 @@ 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
|
||||||
if (!s.bookSeries.length) return null // this is only possible if user has restricted books in series
|
.map((s) => {
|
||||||
|
if (!s.bookSeries.length) return null // this is only possible if user has restricted books in series
|
||||||
|
|
||||||
let bookIndex = 0
|
let bookIndex = 0
|
||||||
// if the library setting is toggled, only show later entries in series, otherwise skip
|
// if the library setting is toggled, only show later entries in series, otherwise skip
|
||||||
if (library.settings.onlyShowLaterBooksInContinueSeries) {
|
if (library.settings.onlyShowLaterBooksInContinueSeries) {
|
||||||
bookIndex = s.bookSeries.findIndex(function (b) {
|
bookIndex = s.bookSeries.findIndex(function (b) {
|
||||||
return parseFloat(b.dataValues.sequence) > s.dataValues.maxSequence
|
return parseFloat(b.dataValues.sequence) > s.dataValues.maxSequence
|
||||||
})
|
})
|
||||||
if (bookIndex === -1) {
|
if (bookIndex === -1) {
|
||||||
// no later books than maxSequence
|
// no later books than maxSequence
|
||||||
return null
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const libraryItem = s.bookSeries[bookIndex].book.libraryItem.toJSON()
|
const libraryItem = s.bookSeries[bookIndex].book.libraryItem.toJSON()
|
||||||
const book = s.bookSeries[bookIndex].book.toJSON()
|
const book = s.bookSeries[bookIndex].book.toJSON()
|
||||||
delete book.libraryItem
|
delete book.libraryItem
|
||||||
libraryItem.series = {
|
libraryItem.series = {
|
||||||
id: s.id,
|
id: s.id,
|
||||||
name: s.name,
|
name: s.name,
|
||||||
sequence: s.bookSeries[bookIndex].sequence
|
sequence: s.bookSeries[bookIndex].sequence
|
||||||
}
|
}
|
||||||
if (libraryItem.feeds?.length) {
|
if (libraryItem.feeds?.length) {
|
||||||
libraryItem.rssFeed = libraryItem.feeds[0]
|
libraryItem.rssFeed = libraryItem.feeds[0]
|
||||||
}
|
}
|
||||||
libraryItem.media = book
|
libraryItem.media = book
|
||||||
return libraryItem
|
return libraryItem
|
||||||
}).filter(s => s)
|
})
|
||||||
|
.filter((s) => s)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
libraryItems,
|
libraryItems,
|
||||||
@ -780,10 +764,10 @@ module.exports = {
|
|||||||
* Get book library items for the "Discover" shelf
|
* Get book library items for the "Discover" shelf
|
||||||
* Random selection of books that are not started
|
* Random selection of books that are not started
|
||||||
* - only includes the first book of a not-started series
|
* - only includes the first book of a not-started series
|
||||||
* @param {string} libraryId
|
* @param {string} libraryId
|
||||||
* @param {oldUser} user
|
* @param {oldUser} user
|
||||||
* @param {string[]} include
|
* @param {string[]} include
|
||||||
* @param {number} limit
|
* @param {number} limit
|
||||||
* @returns {object} {libraryItems:LibraryItem, count:number}
|
* @returns {object} {libraryItems:LibraryItem, count:number}
|
||||||
*/
|
*/
|
||||||
async getDiscoverLibraryItems(libraryId, user, include, limit) {
|
async getDiscoverLibraryItems(libraryId, user, include, limit) {
|
||||||
@ -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 = []
|
||||||
@ -913,7 +895,7 @@ module.exports = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get book library items in a collection
|
* Get book library items in a collection
|
||||||
* @param {oldCollection} collection
|
* @param {oldCollection} collection
|
||||||
* @returns {Promise<LibraryItem[]>}
|
* @returns {Promise<LibraryItem[]>}
|
||||||
*/
|
*/
|
||||||
async getLibraryItemsForCollection(collection) {
|
async getLibraryItemsForCollection(collection) {
|
||||||
@ -957,22 +939,22 @@ module.exports = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get library items for series
|
* Get library items for series
|
||||||
* @param {import('../../objects/entities/Series')} oldSeries
|
* @param {import('../../objects/entities/Series')} oldSeries
|
||||||
* @param {import('../../objects/user/User')} [oldUser]
|
* @param {import('../../objects/user/User')} [oldUser]
|
||||||
* @returns {Promise<import('../../objects/LibraryItem')[]>}
|
* @returns {Promise<import('../../objects/LibraryItem')[]>}
|
||||||
*/
|
*/
|
||||||
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))
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search books, authors, series
|
* Search books, authors, series
|
||||||
* @param {import('../../objects/user/User')} oldUser
|
* @param {import('../../objects/user/User')} oldUser
|
||||||
* @param {import('../../objects/Library')} oldLibrary
|
* @param {import('../../objects/Library')} oldLibrary
|
||||||
* @param {string} query
|
* @param {string} query
|
||||||
* @param {number} limit
|
* @param {number} limit
|
||||||
* @param {number} offset
|
* @param {number} offset
|
||||||
* @returns {{book:object[], narrators:object[], authors:object[], tags:object[], series:object[]}}
|
* @returns {{book:object[], narrators:object[], authors:object[], tags:object[], series:object[]}}
|
||||||
*/
|
*/
|
||||||
async search(oldUser, oldLibrary, query, limit, offset) {
|
async search(oldUser, oldLibrary, query, limit, offset) {
|
||||||
@ -1151,7 +1133,7 @@ module.exports = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Genres with num books
|
* Genres with num books
|
||||||
* @param {string} libraryId
|
* @param {string} libraryId
|
||||||
* @returns {{genre:string, count:number}[]}
|
* @returns {{genre:string, count:number}[]}
|
||||||
*/
|
*/
|
||||||
async getGenresWithCount(libraryId) {
|
async getGenresWithCount(libraryId) {
|
||||||
@ -1173,7 +1155,7 @@ module.exports = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get stats for book library
|
* Get stats for book library
|
||||||
* @param {string} libraryId
|
* @param {string} libraryId
|
||||||
* @returns {Promise<{ totalSize:number, totalDuration:number, numAudioFiles:number, totalItems:number}>}
|
* @returns {Promise<{ totalSize:number, totalDuration:number, numAudioFiles:number, totalItems:number}>}
|
||||||
*/
|
*/
|
||||||
async getBookLibraryStats(libraryId) {
|
async getBookLibraryStats(libraryId) {
|
||||||
@ -1187,8 +1169,8 @@ module.exports = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get longest books in library
|
* Get longest books in library
|
||||||
* @param {string} libraryId
|
* @param {string} libraryId
|
||||||
* @param {number} limit
|
* @param {number} limit
|
||||||
* @returns {Promise<{ id:string, title:string, duration:number }[]>}
|
* @returns {Promise<{ id:string, title:string, duration:number }[]>}
|
||||||
*/
|
*/
|
||||||
async getLongestBooks(libraryId, limit) {
|
async getLongestBooks(libraryId, limit) {
|
||||||
@ -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,
|
||||||
@ -1214,4 +1194,4 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user