dptxa-proxy / src /pages /api /admin /movie /restore.js
TXAVLOG
Deploy DPTXA to Hugging Face Spaces
4bea261
Raw
History Blame Contribute Delete
1.52 kB
import { restoreLocalMovie } 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 success = await restoreLocalMovie(slug);
if (success) {
return new Response(
JSON.stringify({ message: 'Khôi phục hiển thị phim thành công!' }),
{ status: 200, headers: { 'Content-Type': 'application/json' } }
);
} else {
return new Response(
JSON.stringify({ error: 'Không tìm thấy phim này trong danh sách ẩn!' }),
{ status: 400, headers: { 'Content-Type': 'application/json' } }
);
}
} catch (error) {
return new Response(
JSON.stringify({ error: 'Gặp lỗi trong quá trình khôi phục: ' + error.message }),
{ status: 500, headers: { 'Content-Type': 'application/json' } }
);
}
}