From dd3405237c1b91ceaa5c876cc06bcfc1ddc099cd Mon Sep 17 00:00:00 2001 From: Prince527 Date: Sat, 2 Mar 2024 11:20:39 -0400 Subject: [PATCH] Update index.js --- index.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 4927054..78d22cf 100644 --- a/index.js +++ b/index.js @@ -118,7 +118,15 @@ function checkAuth(req, res, next) { } next(); -}; +} + +function createArray(array, size, offset) { + if (offset < 0 || offset >= array.length) return []; + if (size <= 0 || size > array.length - offset) return []; + + const newArray = array.slice(offset, offset + size); + return newArray; +} app.use(cors({ origin: "*" })); app.use(require("./logs")); @@ -299,10 +307,7 @@ app.get("/rest/getAlbumList2.view", async(req, res) => { let albums = await (await fetch(`${config.music}/getall/albums?start=${offset || '0'}&limit=${size || '50'}&sortby=created_date&reverse=1`)).json(); - if (type === "starred") { - albums.items = (await (await fetch(`${config.music}/albums/favorite?limit=0`)).json()).albums; - // albums = { items: albums.albums } - } + if (type === "starred") albums.items = createArray((await (await fetch(`${config.music}/albums/favorite?limit=0`)).json()).albums, size, offset); let output = albums.items.map(item => ({ id: item.item?.albumhash || item.albumhash,