mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-12 12:21:34 +00:00
Limit playlists to return only 4 items when getting list of ALL playlists (otherwise, return the entire playlist)
This commit is contained in:
parent
6fa49e0aab
commit
36f46072fd
2 changed files with 45 additions and 1 deletions
|
|
@ -513,7 +513,7 @@ class LibraryController {
|
||||||
*/
|
*/
|
||||||
async getUserPlaylistsForLibrary(req, res) {
|
async getUserPlaylistsForLibrary(req, res) {
|
||||||
let playlistsForUser = await Database.playlistModel.getPlaylistsForUserAndLibrary(req.user.id, req.library.id)
|
let playlistsForUser = await Database.playlistModel.getPlaylistsForUserAndLibrary(req.user.id, req.library.id)
|
||||||
playlistsForUser = await Promise.all(playlistsForUser.map(async (p) => p.getOldJsonExpanded()))
|
playlistsForUser = await Promise.all(playlistsForUser.map(async (p) => p.getLimitedOldJsonExpanded()))
|
||||||
|
|
||||||
const payload = {
|
const payload = {
|
||||||
results: [],
|
results: [],
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,50 @@ class Playlist extends Model {
|
||||||
return playlistExpanded
|
return playlistExpanded
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get old playlist toJSONExpanded, limiting each playlist to the first 4 items.
|
||||||
|
* @param {[string[]]} include
|
||||||
|
* @returns {Promise<object>} oldPlaylist.toJSONExpanded
|
||||||
|
*/
|
||||||
|
async getLimitedOldJsonExpanded(include) {
|
||||||
|
this.playlistMediaItems =
|
||||||
|
(await this.getPlaylistMediaItems({
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: this.sequelize.models.book,
|
||||||
|
include: this.sequelize.models.libraryItem
|
||||||
|
},
|
||||||
|
{
|
||||||
|
model: this.sequelize.models.podcastEpisode,
|
||||||
|
include: {
|
||||||
|
model: this.sequelize.models.podcast,
|
||||||
|
include: this.sequelize.models.libraryItem
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
limit: 4,
|
||||||
|
order: [['order', 'ASC']]
|
||||||
|
})) || []
|
||||||
|
|
||||||
|
const oldPlaylist = this.sequelize.models.playlist.getOldPlaylist(this)
|
||||||
|
const libraryItemIds = oldPlaylist.items.map((i) => i.libraryItemId)
|
||||||
|
|
||||||
|
let libraryItems = await this.sequelize.models.libraryItem.getAllOldLibraryItems({
|
||||||
|
id: libraryItemIds
|
||||||
|
})
|
||||||
|
|
||||||
|
const playlistExpanded = oldPlaylist.toJSONExpanded(libraryItems)
|
||||||
|
|
||||||
|
if (include?.includes('rssfeed')) {
|
||||||
|
const feeds = await this.getFeeds()
|
||||||
|
if (feeds?.length) {
|
||||||
|
playlistExpanded.rssFeed = this.sequelize.models.feed.getOldFeed(feeds[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return playlistExpanded
|
||||||
|
}
|
||||||
|
|
||||||
static createFromOld(oldPlaylist) {
|
static createFromOld(oldPlaylist) {
|
||||||
const playlist = this.getFromOld(oldPlaylist)
|
const playlist = this.getFromOld(oldPlaylist)
|
||||||
return this.create(playlist)
|
return this.create(playlist)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue