fix(route/apple/podcast): adapt to new serialized-server-data structure (#21387)
Apple Podcasts changed the `#serialized-server-data` element from a
direct array to an object wrapper `{ data: [...], userTokenHash }`.
This broke the route with:
TypeError: Cannot read properties of undefined (reading 'data')
Changes:
- Handle both old (array) and new (object with `data` key) formats
using `Array.isArray()` check for backward compatibility
- Add defensive optional chaining on the `channel` relationship
access chain to prevent crashes when episodes lack channel data
Fixes the same underlying issue reported by yt-dlp (yt-dlp/yt-dlp#15926).
Made-with: Cursor
Co-authored-by: xbankeradmin <admin@xbanker.ai>
This commit is contained in:
parent
7b92b63c90
commit
85b5444d07
|
|
@ -43,8 +43,9 @@ async function handler(ctx) {
|
|||
|
||||
const $ = load(response);
|
||||
|
||||
const serializedServerData = JSON.parse($('#serialized-server-data').text());
|
||||
const header = serializedServerData[0].data.shelves.find((item) => item.contentType === 'showHeaderRegular').items[0];
|
||||
const rawServerData = JSON.parse($('#serialized-server-data').text());
|
||||
const serverData = (Array.isArray(rawServerData) ? rawServerData : rawServerData.data)[0].data;
|
||||
const header = serverData.shelves.find((item) => item.contentType === 'showHeaderRegular').items[0];
|
||||
|
||||
const bearerToken = await cache.tryGet(
|
||||
'apple:podcast:bearer',
|
||||
|
|
@ -93,7 +94,7 @@ async function handler(ctx) {
|
|||
};
|
||||
});
|
||||
|
||||
const channel = episodeReponse.data.find((d) => d.type === 'podcast-episodes').relationships.channel.data.find((d) => d.type === 'podcast-channels')?.attributes;
|
||||
const channel = episodeReponse.data.find((d) => d.type === 'podcast-episodes')?.relationships?.channel?.data?.find((d) => d.type === 'podcast-channels')?.attributes;
|
||||
|
||||
return {
|
||||
title: channel?.name ?? header.title,
|
||||
|
|
|
|||
Loading…
Reference in New Issue