import { txasupabase } from '../../../lib/txasupabase.js'; export async function GET({ 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 settings = await txasupabase.getSettings(); return new Response(JSON.stringify(settings), { status: 200, headers: { 'Content-Type': 'application/json' } }); } catch (error) { return new Response(JSON.stringify({ error: 'Lỗi máy chủ: ' + error.message }), { status: 500, headers: { 'Content-Type': 'application/json' } }); } } 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 settingsObj = await request.json(); await txasupabase.saveSettings(settingsObj); return new Response(JSON.stringify({ message: 'Lưu cài đặt thành công!' }), { status: 200, headers: { 'Content-Type': 'application/json' } }); } catch (error) { return new Response(JSON.stringify({ error: 'Lỗi máy chủ: ' + error.message }), { status: 500, headers: { 'Content-Type': 'application/json' } }); } }