Spaces:
Sleeping
Sleeping
Download src/pages/api/admin/movie/delete.js from TXAVLOG/dptxa-proxy: direct link, hf CLI and curl.
- Browser
- Download file 1.41 kB
-
https://huggingface.co/spaces/TXAVLOG/dptxa-proxy/resolve/main/src/pages/api/admin/movie/delete.js
- Command line
-
hf download hf://spaces/TXAVLOG/dptxa-proxy/src/pages/api/admin/movie/delete.js
-
curl -L -o delete.js https://huggingface.co/spaces/TXAVLOG/dptxa-proxy/resolve/main/src/pages/api/admin/movie/delete.js
1.41 kB
| 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' } } | |
| ); | |
| } | |
| } | |