From 63ad0db844101f0c4ae98af5878dc2c4224a112f Mon Sep 17 00:00:00 2001 From: Pine Date: Wed, 16 Sep 2026 23:18:44 +0800 Subject: [PATCH] =?UTF-8?q?feat(media):=20=E6=92=AD=E6=94=BE=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=B8=A6=E8=AE=BE=E5=A4=87=20token=20=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=EF=BC=88=E5=9B=AD=E5=8C=BA=E9=9A=94=E7=A6=BB=EF=BC=89?= =?UTF-8?q?+=20=E6=92=AD=E6=94=BE=E4=BC=98=E5=85=88=E4=BD=BF=E7=94=A8=20CD?= =?UTF-8?q?N=20=E7=9B=B4=E9=93=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - api.js getPlaylist:附 Authorization 设备 token(?tenant_id 兜底),服务端按绑定园区返回播放列表 - MediaScreen getUrl:item.url(CDN/OSS 直链)优先,其次 URL 来源,最后回退 /file 静态 --- src/pages/MediaScreen.jsx | 8 +++++--- src/utils/api.js | 8 +++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/pages/MediaScreen.jsx b/src/pages/MediaScreen.jsx index a6e06ea..e5471f7 100644 --- a/src/pages/MediaScreen.jsx +++ b/src/pages/MediaScreen.jsx @@ -61,7 +61,9 @@ export default function MediaScreen() { useEffect(() => { soundBlockedRef.current = soundBlocked; }, [soundBlocked]); const getUrl = useCallback((item) => { - // 惰性读取 API 基址:打包部署引导覆盖后媒体文件地址同步生效 + // CDN/OSS 直链优先(admin 端上传到 OSS 后返回的直链,播放不再经过服务端代理); + // 无直链时回退旧逻辑:URL 源用原地址,本地文件走 /file 静态服务 + if (item.url) return item.url; return item.source === 'url' ? item.relative_path : `${getApiBase()}/file/${item.relative_path}`; }, []); @@ -202,7 +204,7 @@ export default function MediaScreen() { const load = async () => { try { const data = await api.getPlaylist(); - const files = data.files || []; + const files = data.playlist || data.files || []; const vol = (data.volume || 80) / 100; setList(files); setVolume(vol); @@ -284,7 +286,7 @@ export default function MediaScreen() { const reloadPlaylist = useCallback(async () => { try { const data = await api.getPlaylist(); - const newList = data.files || []; + const newList = data.playlist || data.files || []; const currentItem = listRef.current[indexRef.current] || null; if (newList.length === 0) { diff --git a/src/utils/api.js b/src/utils/api.js index 44308c1..1932421 100644 --- a/src/utils/api.js +++ b/src/utils/api.js @@ -1,5 +1,6 @@ // API 基地址 —— 独立 FastAPI 后端(配置见 src/config.js,可用 window.__DPM_API__ 覆盖) import { getApiBase } from '../config'; +import { getTenantId, getDeviceToken } from './tenant'; /* 惰性读取 API 基址:允许 main.jsx 引导阶段从后端 /api/config 覆盖(打包部署时生效) */ export const API_BASE = getApiBase(); @@ -110,8 +111,13 @@ export async function deleteMedia(path) { } // ============ Playlist ============ +/** 播放列表:绑定后按本园区取(设备 token 鉴权,未绑定回退全局旧数据)。 */ export async function getPlaylist() { - const res = await fetch(`${base()}/api/playlist`); + const token = getDeviceToken(); + const tid = getTenantId(); + const res = await fetch(`${base()}/api/playlist${tid ? `?tenant_id=${encodeURIComponent(tid)}` : ''}`, { + headers: token ? { Authorization: `Bearer ${token}` } : {}, + }); return res.json(); }