Files
MoonTVPlus/src/app/api/emby/views/route.ts
2026-01-23 16:41:49 +08:00

54 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* eslint-disable @typescript-eslint/no-explicit-any */
import { NextRequest, NextResponse } from 'next/server';
import { getCachedEmbyViews, setCachedEmbyViews } from '@/lib/emby-cache';
import { embyManager } from '@/lib/emby-manager';
export const runtime = 'nodejs';
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url);
const embyKey = searchParams.get('embyKey') || undefined;
// 检查缓存按embyKey缓存
const cacheKey = embyKey || 'default';
const cached = getCachedEmbyViews(cacheKey);
if (cached) {
return NextResponse.json(cached);
}
// 获取Emby客户端
const client = await embyManager.getClient(embyKey);
// 获取媒体库列表
const views = await client.getUserViews();
// 过滤出电影和电视剧媒体库
const filteredViews = views.filter(
(view) => view.CollectionType === 'movies' || view.CollectionType === 'tvshows'
);
const response = {
success: true,
views: filteredViews.map((view) => ({
id: view.Id,
name: view.Name,
type: view.CollectionType,
})),
};
// 缓存结果
setCachedEmbyViews(cacheKey, response);
return NextResponse.json(response);
} catch (error) {
console.error('获取 Emby 媒体库列表失败:', error);
return NextResponse.json({
error: '获取 Emby 媒体库列表失败: ' + (error as Error).message,
views: [],
});
}
}