mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-06 01:11:35 +00:00
Adjust discover/search changes for API compatibility
This commit is contained in:
parent
f1a2e56054
commit
c0319ebbac
2 changed files with 18 additions and 19 deletions
|
|
@ -890,14 +890,12 @@ module.exports = {
|
||||||
|
|
||||||
const discoverWhere = [
|
const discoverWhere = [
|
||||||
{
|
{
|
||||||
[Sequelize.Op.and]: [
|
'$mediaProgresses.isFinished$': {
|
||||||
Sequelize.where(
|
[Sequelize.Op.or]: [null, 0]
|
||||||
Sequelize.literal(
|
},
|
||||||
`(SELECT COUNT(*) FROM mediaProgresses mp WHERE mp.mediaItemId = book.id AND mp.userId = :userId AND (mp.isFinished = 1 OR mp.currentTime > 0))`
|
'$mediaProgresses.currentTime$': {
|
||||||
),
|
[Sequelize.Op.or]: [null, 0]
|
||||||
0
|
},
|
||||||
)
|
|
||||||
],
|
|
||||||
[Sequelize.Op.or]: [
|
[Sequelize.Op.or]: [
|
||||||
Sequelize.where(Sequelize.literal(`(SELECT COUNT(*) FROM bookSeries bs where bs.bookId = book.id)`), 0),
|
Sequelize.where(Sequelize.literal(`(SELECT COUNT(*) FROM bookSeries bs where bs.bookId = book.id)`), 0),
|
||||||
{
|
{
|
||||||
|
|
@ -916,16 +914,20 @@ module.exports = {
|
||||||
where: {
|
where: {
|
||||||
libraryId
|
libraryId
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
model: Database.mediaProgressModel,
|
||||||
|
where: {
|
||||||
|
userId: user.id
|
||||||
|
},
|
||||||
|
required: false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
// Step 2a: Count with lightweight includes only
|
// Step 2a: Count with lightweight includes only
|
||||||
const count = await Database.bookModel.count({
|
const count = await Database.bookModel.count({
|
||||||
where: discoverWhere,
|
where: discoverWhere,
|
||||||
replacements: {
|
replacements: userPermissionBookWhere.replacements,
|
||||||
userId: user.id,
|
|
||||||
...userPermissionBookWhere.replacements
|
|
||||||
},
|
|
||||||
include: baseDiscoverInclude,
|
include: baseDiscoverInclude,
|
||||||
distinct: true,
|
distinct: true,
|
||||||
col: 'id',
|
col: 'id',
|
||||||
|
|
@ -936,10 +938,7 @@ module.exports = {
|
||||||
const randomSelection = await Database.bookModel.findAll({
|
const randomSelection = await Database.bookModel.findAll({
|
||||||
attributes: ['id'],
|
attributes: ['id'],
|
||||||
where: discoverWhere,
|
where: discoverWhere,
|
||||||
replacements: {
|
replacements: userPermissionBookWhere.replacements,
|
||||||
userId: user.id,
|
|
||||||
...userPermissionBookWhere.replacements
|
|
||||||
},
|
|
||||||
include: baseDiscoverInclude,
|
include: baseDiscoverInclude,
|
||||||
subQuery: false,
|
subQuery: false,
|
||||||
distinct: true,
|
distinct: true,
|
||||||
|
|
@ -1167,7 +1166,7 @@ module.exports = {
|
||||||
|
|
||||||
libraryItem.media = book
|
libraryItem.media = book
|
||||||
itemMatches.push({
|
itemMatches.push({
|
||||||
libraryItem: libraryItem.toOldJSONMinified()
|
libraryItem: libraryItem.toOldJSONExpanded()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -410,7 +410,7 @@ module.exports = {
|
||||||
libraryItem.media = podcast
|
libraryItem.media = podcast
|
||||||
libraryItem.media.podcastEpisodes = []
|
libraryItem.media.podcastEpisodes = []
|
||||||
itemMatches.push({
|
itemMatches.push({
|
||||||
libraryItem: libraryItem.toOldJSONMinified()
|
libraryItem: libraryItem.toOldJSONExpanded()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -444,7 +444,7 @@ module.exports = {
|
||||||
libraryItem.media = episode.podcast
|
libraryItem.media = episode.podcast
|
||||||
libraryItem.media.podcastEpisodes = []
|
libraryItem.media.podcastEpisodes = []
|
||||||
const oldPodcastEpisodeJson = episode.toOldJSONExpanded(libraryItem.id)
|
const oldPodcastEpisodeJson = episode.toOldJSONExpanded(libraryItem.id)
|
||||||
const libraryItemJson = libraryItem.toOldJSONMinified()
|
const libraryItemJson = libraryItem.toOldJSONExpanded()
|
||||||
libraryItemJson.recentEpisode = oldPodcastEpisodeJson
|
libraryItemJson.recentEpisode = oldPodcastEpisodeJson
|
||||||
episodeMatches.push({
|
episodeMatches.push({
|
||||||
libraryItem: libraryItemJson
|
libraryItem: libraryItemJson
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue