import { resetLocalMovie } 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 resetLocalMovie(slug); if (success) { return new Response( JSON.stringify({ message: 'Đã xóa bỏ các thay đổi cục bộ, đưa phim về trạng thái gốc từ API!' }), { status: 200, headers: { 'Content-Type': 'application/json' } } ); } else { return new Response( JSON.stringify({ error: 'Phim này không có thay đổi cục bộ nào để đặt lại!' }), { status: 400, headers: { 'Content-Type': 'application/json' } } ); } } catch (error) { return new Response( JSON.stringify({ error: 'Gặp lỗi trong quá trình đặt lại: ' + error.message }), { status: 500, headers: { 'Content-Type': 'application/json' } } ); } }