mirror of
https://github.com/gethomepage/homepage.git
synced 2026-01-05 23:12:08 +08:00
Fix: prevent cache collision with multiple plex widgets (#6126)
Some checks failed
Crowdin Action / Crowdin Sync (push) Has been cancelled
Docker CI / Linting Checks (push) Has been cancelled
Docker CI / Docker Build & Push (push) Has been cancelled
Repository Maintenance / Stale (push) Has been cancelled
Repository Maintenance / Lock Old Threads (push) Has been cancelled
Repository Maintenance / Close Answered Discussions (push) Has been cancelled
Repository Maintenance / Close Outdated Discussions (push) Has been cancelled
Repository Maintenance / Close Unsupported Feature Requests (push) Has been cancelled
Some checks failed
Crowdin Action / Crowdin Sync (push) Has been cancelled
Docker CI / Linting Checks (push) Has been cancelled
Docker CI / Docker Build & Push (push) Has been cancelled
Repository Maintenance / Stale (push) Has been cancelled
Repository Maintenance / Lock Old Threads (push) Has been cancelled
Repository Maintenance / Close Answered Discussions (push) Has been cancelled
Repository Maintenance / Close Outdated Discussions (push) Has been cancelled
Repository Maintenance / Close Unsupported Feature Requests (push) Has been cancelled
This commit is contained in:
@@ -65,7 +65,7 @@ async function fetchFromPlexAPI(endpoint, widget) {
|
|||||||
export default async function plexProxyHandler(req, res) {
|
export default async function plexProxyHandler(req, res) {
|
||||||
const widget = await getWidget(req);
|
const widget = await getWidget(req);
|
||||||
|
|
||||||
const { service } = req.query;
|
const { service, index } = req.query;
|
||||||
|
|
||||||
if (!widget) {
|
if (!widget) {
|
||||||
return res.status(400).json({ error: "Invalid proxy service type" });
|
return res.status(400).json({ error: "Invalid proxy service type" });
|
||||||
@@ -85,19 +85,19 @@ export default async function plexProxyHandler(req, res) {
|
|||||||
streams = apiData.MediaContainer._attributes.size;
|
streams = apiData.MediaContainer._attributes.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
let libraries = cache.get(`${librariesCacheKey}.${service}`);
|
let libraries = cache.get(`${librariesCacheKey}.${service}.${index}`);
|
||||||
if (libraries === null) {
|
if (libraries === null) {
|
||||||
logger.debug("Getting libraries from Plex API");
|
logger.debug("Getting libraries from Plex API");
|
||||||
[status, apiData] = await fetchFromPlexAPI("/library/sections", widget);
|
[status, apiData] = await fetchFromPlexAPI("/library/sections", widget);
|
||||||
if (apiData && apiData.MediaContainer) {
|
if (apiData && apiData.MediaContainer) {
|
||||||
libraries = [].concat(apiData.MediaContainer.Directory);
|
libraries = [].concat(apiData.MediaContainer.Directory);
|
||||||
cache.put(`${librariesCacheKey}.${service}`, libraries, 1000 * 60 * 60 * 6);
|
cache.put(`${librariesCacheKey}.${service}.${index}`, libraries, 1000 * 60 * 60 * 6);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let albums = cache.get(`${albumsCacheKey}.${service}`);
|
let albums = cache.get(`${albumsCacheKey}.${service}.${index}`);
|
||||||
let movies = cache.get(`${moviesCacheKey}.${service}`);
|
let movies = cache.get(`${moviesCacheKey}.${service}.${index}`);
|
||||||
let tv = cache.get(`${tvCacheKey}.${service}`);
|
let tv = cache.get(`${tvCacheKey}.${service}.${index}`);
|
||||||
if (albums === null || movies === null || tv === null) {
|
if (albums === null || movies === null || tv === null) {
|
||||||
albums = 0;
|
albums = 0;
|
||||||
movies = 0;
|
movies = 0;
|
||||||
@@ -123,9 +123,9 @@ export default async function plexProxyHandler(req, res) {
|
|||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
cache.put(`${albumsCacheKey}.${service}`, albums, 1000 * 60 * 10);
|
cache.put(`${albumsCacheKey}.${service}.${index}`, albums, 1000 * 60 * 10);
|
||||||
cache.put(`${tvCacheKey}.${service}`, tv, 1000 * 60 * 10);
|
cache.put(`${tvCacheKey}.${service}.${index}`, tv, 1000 * 60 * 10);
|
||||||
cache.put(`${moviesCacheKey}.${service}`, movies, 1000 * 60 * 10);
|
cache.put(`${moviesCacheKey}.${service}.${index}`, movies, 1000 * 60 * 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
|
|||||||
Reference in New Issue
Block a user