mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-07 09:51:37 +00:00
feat: add large-library browse response contract
This commit is contained in:
parent
6b7550c25b
commit
3579341f6c
4 changed files with 146 additions and 6 deletions
|
|
@ -612,6 +612,12 @@ class LibraryController {
|
|||
total: undefined,
|
||||
limit: req.query.limit || 0,
|
||||
page: req.query.page || 0,
|
||||
cursor: req.query.cursor || null,
|
||||
pageMode: req.query.pageMode || 'paged',
|
||||
nextCursor: null,
|
||||
paginationMode: 'offset',
|
||||
isCountDeferred: false,
|
||||
countMode: 'exact-on-initial-page',
|
||||
sortBy: req.query.sort,
|
||||
sortDesc: req.query.desc === '1',
|
||||
filterBy: req.query.filter,
|
||||
|
|
@ -630,9 +636,13 @@ class LibraryController {
|
|||
const seriesId = libraryFilters.decode(payload.filterBy.split('.')[1])
|
||||
payload.results = await libraryHelpers.handleCollapseSubseries(payload, seriesId, req.user, req.library)
|
||||
} else {
|
||||
const { libraryItems, count } = await Database.libraryItemModel.getByFilterAndSort(req.library, req.user, payload)
|
||||
const { libraryItems, count, nextCursor, paginationMode, countMode, isCountDeferred } = await Database.libraryItemModel.getByFilterAndSort(req.library, req.user, payload)
|
||||
payload.results = libraryItems
|
||||
payload.total = count
|
||||
payload.nextCursor = nextCursor || null
|
||||
payload.paginationMode = paginationMode || 'offset'
|
||||
payload.countMode = countMode || 'exact-on-initial-page'
|
||||
payload.isCountDeferred = !!isCountDeferred
|
||||
}
|
||||
|
||||
res.json(payload)
|
||||
|
|
|
|||
|
|
@ -293,7 +293,11 @@ class LibraryItem extends Model {
|
|||
*/
|
||||
static async getByFilterAndSort(library, user, options) {
|
||||
let start = Date.now()
|
||||
const { libraryItems, count } = await libraryFilters.getFilteredLibraryItems(library.id, user, options)
|
||||
const { libraryItems, count, nextCursor, paginationMode, countMode, isCountDeferred } = await libraryFilters.getFilteredLibraryItems(library.id, user, {
|
||||
...options,
|
||||
cursor: options.cursor || null,
|
||||
pageMode: options.pageMode || 'paged'
|
||||
})
|
||||
Logger.debug(`Loaded ${libraryItems.length} of ${count} items for libary page in ${((Date.now() - start) / 1000).toFixed(2)}s`)
|
||||
|
||||
return {
|
||||
|
|
@ -323,7 +327,11 @@ class LibraryItem extends Model {
|
|||
|
||||
return oldLibraryItem
|
||||
}),
|
||||
count
|
||||
count,
|
||||
nextCursor,
|
||||
paginationMode,
|
||||
countMode,
|
||||
isCountDeferred
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ module.exports = {
|
|||
* @returns {Promise<{ libraryItems:import('../../models/LibraryItem')[], count:number }>}
|
||||
*/
|
||||
async getFilteredLibraryItems(libraryId, user, options) {
|
||||
const { filterBy, sortBy, sortDesc, limit, offset, collapseseries, include, mediaType } = options
|
||||
const { filterBy, sortBy, sortDesc, limit, offset, collapseseries, include, mediaType, cursor, pageMode } = options
|
||||
|
||||
let filterValue = null
|
||||
let filterGroup = null
|
||||
|
|
@ -34,9 +34,17 @@ module.exports = {
|
|||
}
|
||||
|
||||
if (mediaType === 'book') {
|
||||
return libraryItemsBookFilters.getFilteredLibraryItems(libraryId, user, filterGroup, filterValue, sortBy, sortDesc, collapseseries, include, limit, offset)
|
||||
return libraryItemsBookFilters.getFilteredLibraryItems(libraryId, user, filterGroup, filterValue, sortBy, sortDesc, collapseseries, include, limit, offset, false, {
|
||||
cursor: cursor || null,
|
||||
pageMode: pageMode || 'paged',
|
||||
collapseseries
|
||||
})
|
||||
} else {
|
||||
return libraryItemsPodcastFilters.getFilteredLibraryItems(libraryId, user, filterGroup, filterValue, sortBy, sortDesc, include, limit, offset)
|
||||
return libraryItemsPodcastFilters.getFilteredLibraryItems(libraryId, user, filterGroup, filterValue, sortBy, sortDesc, include, limit, offset, {
|
||||
cursor: cursor || null,
|
||||
pageMode: pageMode || 'paged',
|
||||
collapseseries
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue