Spaces:
Sleeping
Sleeping
| import { deleteLocalMovie } from '../../../../lib/localDb.js'; | |
| export async function POST({ request, cookies }) { | |
| const token = cookies.get('auth_token')?.value; | |
| let user = null; | |
| if (token) { | |
| try { | |
| user = JSON.parse(Buffer.from(token, 'base64').toString('utf-8')); | |
| } catch (e) {} | |
| } | |
| if (!user || user.role !== 'admin') { | |
| return new Response( | |
| JSON.stringify({ error: 'Từ chối truy cập! Yêu cầu quyền quản trị viên.' }), | |
| { status: 403, headers: { 'Content-Type': 'application/json' } } | |
| ); | |
| } | |
| try { | |
| const { slug } = await request.json(); | |
| if (!slug) { | |
| return new Response( | |
| JSON.stringify({ error: 'Thiếu thông số slug phim!' }), | |
| { status: 400, headers: { 'Content-Type': 'application/json' } } | |
| ); | |
| } | |
| const result = await deleteLocalMovie(slug); | |
| const msg = result.isLocalOnly | |
| ? 'Đã xóa hoàn toàn phim nội bộ ra khỏi hệ thống!' | |
| : 'Đã ẩn phim này khỏi trang chủ và công cụ tìm kiếm!'; | |
| return new Response( | |
| JSON.stringify({ message: msg }), | |
| { status: 200, headers: { 'Content-Type': 'application/json' } } | |
| ); | |
| } catch (error) { | |
| return new Response( | |
| JSON.stringify({ error: 'Gặp lỗi trong quá trình xóa: ' + error.message }), | |
| { status: 500, headers: { 'Content-Type': 'application/json' } } | |
| ); | |
| } | |
| } | |