From e15d0be1e1fa0fc86e96f0afe4f273b2bd15d1c9 Mon Sep 17 00:00:00 2001 From: xion Date: Thu, 10 Apr 2025 01:00:37 +0800 Subject: [PATCH] temp --- src/module/config.ts | 9 +++++++++ src/module/html/stat/index.ts | 13 +++++++++++-- src/module/index.ts | 6 ++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/module/config.ts b/src/module/config.ts index 996ca9f..902b84e 100644 --- a/src/module/config.ts +++ b/src/module/config.ts @@ -39,6 +39,12 @@ type ConfigType = { */ allowedOrigin: string[]; }; + stat: { + /** + * 统计网站ID + */ + websiteId: string; + }; }; // export const config = useConfig(); @@ -61,4 +67,7 @@ export const config: ConfigType = { resources: envConfig.PROXY_RESOURCES, allowedOrigin: (envConfig.PROXY_ALLOWED_ORIGINS as string)?.split(',') || [], }, + stat: { + websiteId: envConfig.DATA_WEBSITE_ID, + }, }; diff --git a/src/module/html/stat/index.ts b/src/module/html/stat/index.ts index 4348719..9869cde 100644 --- a/src/module/html/stat/index.ts +++ b/src/module/html/stat/index.ts @@ -1,8 +1,17 @@ +import { config } from '../../config.ts'; + /** * 添加统计脚本 * @param html * @returns */ -export const addStat = (html: string) => { - return html.replace('', ``); +export const addStat = (html: string, addStat = true) => { + if (!addStat) { + return html; + } + const { websiteId } = config.stat || {}; + if (!websiteId) { + return html; + } + return html.replace('', ``); }; diff --git a/src/module/index.ts b/src/module/index.ts index c7a6ee3..4ccd450 100644 --- a/src/module/index.ts +++ b/src/module/index.ts @@ -296,8 +296,10 @@ export const handleRequest = async (req: http.IncomingMessage, res: http.ServerR const filePath = path.join(fileStore, indexFilePath); if (!userApp.fileCheck(filePath)) { // 动态删除文件 - res.writeHead(500, { 'Content-Type': 'text/html; charset=utf-8' }); - res.write('App Cache expired, Please refresh\n'); + // res.writeHead(500, { 'Content-Type': 'text/html; charset=utf-8' }); + // res.write('App Cache expired, Please refresh\n'); + res.writeHead(500, { 'Content-Type': 'text/html; charset=utf-8', tips: 'App Cache expired, Please refresh' }); + res.write(createRefreshHtml(user, app)); res.end(); await userApp.clearCacheData(); return;