From f93d58abd1253e29b48c71c100e8c8417a9beb71 Mon Sep 17 00:00:00 2001 From: hl128k Date: Sun, 21 Jul 2024 22:47:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions/userConfig.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 functions/userConfig.js diff --git a/functions/userConfig.js b/functions/userConfig.js new file mode 100644 index 00000000..5c625c30 --- /dev/null +++ b/functions/userConfig.js @@ -0,0 +1,23 @@ +export async function onRequestPost(context) { + const { request, env, params, waitUntil, next, data } = context; + const userConfig = env.USER_CONFIG; + + // 检查 USER_CONFIG 是否为空或未定义 + if (!userConfig) { + return new Response(JSON.stringify({}), { status: 200 }); + } + + try { + // 尝试解析 USER_CONFIG 为 JSON + const parsedConfig = JSON.parse(userConfig); + // 检查解析后的结果是否为对象 + if (typeof parsedConfig === 'object' && parsedConfig !== null) { + return new Response(JSON.stringify(parsedConfig), { status: 200 }); + } else { + return new Response(JSON.stringify({}), { status: 200 }); + } + } catch (error) { + // 捕捉解析错误并返回空对象 + return new Response(JSON.stringify({}), { status: 200 }); + } +}