fix: map real app feed and signed media responses
This commit is contained in:
1 parent
1e1e3cd434
commit
1b6ca4c339
4 files changed
+11
-5
No files matched your search
@@ -1,14 +1,19 @@
|
||||
// Author: fruit.com.cn
|
||||
const FALLBACK_IMAGE = '/assets/hero.jpg';
|
||||
const MEDIA_BASE_URL = (import.meta.env.VITE_MEDIA_BASE_URL || '').replace(/\/$/, '');
|
||||
const getText = (value, lang = 'id') => (typeof value === 'string' ? value : value?.[lang] || value?.en || value?.id || value?.zh || '');
|
||||
const getImage = (item) => item.coverUrl || item.cover || item.posterUrl || item.imageUrl || FALLBACK_IMAGE;
|
||||
const resolveMedia = (value) => value ? (/^https?:\/\//.test(value) ? value : `${MEDIA_BASE_URL}${value}`) : FALLBACK_IMAGE;
|
||||
const getImage = (item) => resolveMedia(item.coverLandscape || item.coverUrl || item.cover || item.posterUrl || item.imageUrl);
|
||||
|
||||
export function normalizeDrama(item, lang = 'id') {
|
||||
const id = String(item.id ?? item.dramaId ?? item.code ?? '');
|
||||
return { id, title: getText(item.locales || item.title, lang) || item.name || 'YMB Drama', channel: getText(item.channelLocales || item.channel, lang) || item.creatorName || 'YMB Originals', genre: getText(item.categoryLocales || item.genre, lang), image: getImage(item), duration: item.duration || '', views: item.views || item.viewCount || '', episodes: item.episodes || item.episodeList || [] };
|
||||
const episodes = item.episodes || item.episodeList || (item.preview ? [item.preview] : []);
|
||||
return { id, title: getText(item.titleLocales || item.locales || item.title, lang) || item.name || 'YMB Drama', channel: getText(item.channelLocales || item.channel, lang) || item.creatorName || 'YMB Originals', genre: getText(item.categoryLocales || item.genre, lang) || getText(item.types?.[0], lang), image: getImage(item), duration: item.duration || item.preview?.duration || '', views: item.views || item.viewCount || '', episodes, preview: item.preview ? { ...item.preview, playUrl: resolveMedia(item.preview.playUrl) } : null };
|
||||
}
|
||||
|
||||
export function normalizePage(payload) {
|
||||
if (Array.isArray(payload)) return { total: payload.length, list: payload };
|
||||
return { total: payload?.total || 0, list: payload?.list || payload?.records || [] };
|
||||
}
|
||||
|
||||
export function resolvePlaybackUrl(value) { return resolveMedia(value); }
|
||||
Reference in new issue
Block a user