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