feat(media): 播放列表带设备 token 请求(园区隔离)+ 播放优先使用 CDN 直链

- api.js getPlaylist:附 Authorization 设备 token(?tenant_id 兜底),服务端按绑定园区返回播放列表
- MediaScreen getUrl:item.url(CDN/OSS 直链)优先,其次 URL 来源,最后回退 /file 静态
This commit is contained in:
Pine
2026-09-16 23:18:44 +08:00
parent 87e57ea486
commit 63ad0db844
2 changed files with 12 additions and 4 deletions
+5 -3
View File
@@ -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) {
+7 -1
View File
@@ -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();
}