--- import AdminLayout from '../../../layouts/AdminLayout.astro'; import { getNewestMovies, searchMovies, formatImageUrl } from '../../../lib/api.js'; import { getLocalMovies, getDeletedMovies } from '../../../lib/localDb.js'; // Kiểm tra phiên đăng nhập và quyền Admin được thực hiện tự động trong AdminLayout const page = parseInt(Astro.url.searchParams.get('page') || '1'); const keyword = Astro.url.searchParams.get('keyword') || ''; const tab = Astro.url.searchParams.get('tab') || 'all'; // all, local, deleted // Đọc database cục bộ const localMovies = await getLocalMovies(); const deletedSlugs = await getDeletedMovies(); let items = []; let pagination = { currentPage: page, totalPages: 1, totalItems: 0 }; if (tab === 'local') { // Chỉ lấy phim tự tạo hoặc đã chỉnh sửa lưu trong movies.json const allLocal = Object.values(localMovies); items = allLocal.map(m => ({ _id: m.movie.id || m.movie.slug, name: m.movie.name, slug: m.movie.slug, origin_name: m.movie.origin_name, thumb_url: m.movie.thumb_url, poster_url: m.movie.poster_url, year: m.movie.year, quality: m.movie.quality || 'FHD', lang: m.movie.lang || 'Vietsub', episode_current: m.movie.episode_current || 'Tập 1', isLocal: m.movie.isLocal, hasLocalEdits: !m.movie.isLocal })); // Lọc tìm kiếm trên tập local if (keyword) { const k = keyword.toLowerCase(); items = items.filter(item => item.name?.toLowerCase().includes(k) || item.origin_name?.toLowerCase().includes(k) || item.slug?.includes(k) ); } pagination = { currentPage: 1, totalPages: 1, totalItems: items.length }; } else if (tab === 'deleted') { // Chỉ lấy danh sách các phim đã bị ẩn items = deletedSlugs.map(slug => { const local = localMovies[slug]; return { _id: slug, slug, name: local?.movie?.name || `Phim từ API (${slug})`, origin_name: local?.movie?.origin_name || 'Đã ẩn', thumb_url: local?.movie?.thumb_url || '', year: local?.movie?.year || '', isDeleted: true }; }); if (keyword) { const k = keyword.toLowerCase(); items = items.filter(item => item.name?.toLowerCase().includes(k) || item.slug?.includes(k) ); } pagination = { currentPage: 1, totalPages: 1, totalItems: items.length }; } else { // Tab 'all': Lấy từ API và trộn dữ liệu cục bộ qua api.js if (keyword) { const result = await searchMovies(keyword, page, { grouped: false }); items = result.items || []; pagination = result.pagination || pagination; } else { const result = await getNewestMovies(page, { grouped: false }); items = result.items || []; pagination = result.pagination || pagination; } } // Thống kê số lượng const countLocalCustom = Object.values(localMovies).filter(m => m.movie.isLocal).length; const countLocalEdits = Object.values(localMovies).filter(m => !m.movie.isLocal).length; const countDeleted = deletedSlugs.length; const stats = [ { label: 'Phim tự tạo', value: countLocalCustom, icon: 'fas fa-plus-circle', color: 'text-emerald-500' }, { label: 'Phim đã sửa', value: countLocalEdits, icon: 'fas fa-edit', color: 'text-amber-500' }, { label: 'Phim đã ẩn', value: countDeleted, icon: 'fas fa-eye-slash', color: 'text-red-500' }, ]; ---

Quản lý phim

Chỉnh sửa, thêm bớt tập phim, ẩn hiện phim và cập nhật nguồn video hàng loạt.

{stats.map(stat => (

{stat.label}

{stat.value}

))}
{keyword && ( )}
{items.length === 0 ? ( ) : ( items.map(item => { const isLocal = item.isLocal; const hasLocalEdits = localMovies[item.slug] && !isLocal; const isDeleted = item.isDeleted; const thumb = item.thumb_url ? formatImageUrl(item.thumb_url) : '/no-cover.jpg'; const require_login = localMovies[item.slug]?.movie?.require_login === true || localMovies[item.slug]?.movie?.only_login === true; return ( ); }) )}
Phim Năm / Loại Trạng thái Nguồn gốc Hành động
Không tìm thấy phim nào phù hợp!
{item.name} {require_login && ( Login )}
{item.origin_name} {item.slug}
{item.year || 'N/A'} {item.type || 'N/A'}
{item.episode_current || 'N/A'}
{isLocal ? ( Nội bộ ) : hasLocalEdits ? ( Đã sửa ) : isDeleted ? ( Đã ẩn ) : ( API Gốc )}
{!isDeleted && ( )} {isDeleted ? ( ) : ( )} {hasLocalEdits && ( )}
{tab === 'all' && pagination.totalPages > 1 && (
Trang {pagination.currentPage} / {pagination.totalPages}
{pagination.currentPage > 1 && ( Trang trước )} {[-2, -1, 0, 1, 2].map(offset => { const pageNum = pagination.currentPage + offset; if (pageNum > 0 && pagination.totalPages >= pageNum) { return ( {pageNum} ); } return null; })} {pagination.currentPage < pagination.totalPages && ( Trang tiếp )}
)}
0
{/* Set nhanh trạng thái */}
Trạng thái:
{/* Ẩn / Hiện */}
{/* Yêu cầu đăng nhập */}
{/* Xóa vĩnh viễn */} {/* Đặt lại gốc (chỉ hiển thị ở tab tương thích) */} {tab === 'local' && ( )}