From 3d6ce4cbf4e1bc32fe2f0a2d741acb33249d9a94 Mon Sep 17 00:00:00 2001 From: xion Date: Wed, 12 Mar 2025 00:49:53 +0800 Subject: [PATCH] fix: add decodeURIComponent --- src/module/get-user-app.ts | 8 ++++++-- src/module/index.ts | 6 ++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/module/get-user-app.ts b/src/module/get-user-app.ts index fb99b85..a99a786 100644 --- a/src/module/get-user-app.ts +++ b/src/module/get-user-app.ts @@ -223,14 +223,18 @@ export class UserApp { }); } await redis.set(key, JSON.stringify(value)); - await redis.set('user:app:exist:' + app + ':' + user, 'index.html||etag||false', 'EX', 60 * 60 * 24 * 7); // 7天 const files = value.data.files; const data = {}; - + let indexHtml = path.join(fileStore, user, app, 'index.html') + '||etag||false'; // 将文件名和路径添加到 `data` 对象中 files.forEach((file) => { data[file.name] = file.path; + if (file.name === 'index.html') { + indexHtml = file.path; + } }); + await redis.set('user:app:exist:' + app + ':' + user, indexHtml, 'EX', 60 * 60 * 24 * 7); // 7天 + await redis.hset('user:app:set:' + app + ':' + user, data); this.setLoaded('running', 'loaded'); }; diff --git a/src/module/index.ts b/src/module/index.ts index 51829ed..8029e6f 100644 --- a/src/module/index.ts +++ b/src/module/index.ts @@ -200,13 +200,14 @@ export const handleRequest = async (req: http.IncomingMessage, res: http.ServerR } else { appFileUrl = (url + '').replace(`/${user}/${app}/`, ''); } - + appFileUrl = decodeURIComponent(appFileUrl); // Decode URL components const appFile = await userApp.getFile(appFileUrl); if (isExist.proxy) { let proxyUrl = appFile || isExist.indexFilePath; if (!proxyUrl.startsWith('http')) { return createNotFoundPage('Invalid proxy url'); } + console.log('proxyUrl', appFileUrl, proxyUrl); let protocol = proxyUrl.startsWith('https') ? https : http; // 代理 const proxyReq = protocol.request(proxyUrl, (proxyRes) => { @@ -231,7 +232,8 @@ export const handleRequest = async (req: http.IncomingMessage, res: http.ServerR // userApp.clearCacheData() return; } - console.log('appFile', appFile, appFileUrl); + console.log('appFile', appFile, appFileUrl, isExist); + // console.log('isExist', isExist); if (!appFile) { const [indexFilePath, etag] = indexFile.split('||'); const contentType = getContentType(indexFilePath);