From 2975e5771657c8b7ff01afce2af7307b4819ff68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com> Date: Wed, 11 Sep 2024 16:28:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E4=B8=8B=E8=BD=BD=E7=9A=84=20pac.txt?= =?UTF-8?q?=20=E6=96=87=E4=BB=B6=E6=97=B6=E9=97=B4=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E5=85=B6=E6=9C=80=E8=BF=91=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/lib/proxy/middleware/overwall.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/packages/mitmproxy/src/lib/proxy/middleware/overwall.js b/packages/mitmproxy/src/lib/proxy/middleware/overwall.js index 24373d4..450b710 100644 --- a/packages/mitmproxy/src/lib/proxy/middleware/overwall.js +++ b/packages/mitmproxy/src/lib/proxy/middleware/overwall.js @@ -37,11 +37,43 @@ function getTmpPacFilePath () { return path.join(getUserBasePath(), '/pac.txt') } +function loadPacLastModifiedTime (pacTxt) { + const matched = pacTxt.match(/(?<=! Last Modified: )[^\n]+/g) + if (matched && matched.length > 0) { + try { + return new Date(matched[0]) + } catch (ignore) { + return null + } + } +} + // 保存 pac 内容到 `~/pac.txt` 文件中 function savePacFile (pacTxt) { const pacFilePath = getTmpPacFilePath() fs.writeFileSync(pacFilePath, pacTxt) log.info('保存 pac.txt 文件成功:', pacFilePath) + + // 尝试解析和修改 pac.txt 文件时间 + const lastModifiedTime = loadPacLastModifiedTime(pacTxt) + if (lastModifiedTime) { + fs.stat(pacFilePath, (err, stats) => { + if (err) { + log.error('修改 pac.txt 文件时间失败:', err) + return + } + + // 修改文件的访问时间和修改时间为当前时间 + fs.utimes(pacFilePath, lastModifiedTime, lastModifiedTime, (utimesErr) => { + if (utimesErr) { + log.error('修改 pac.txt 文件时间失败:', utimesErr) + } else { + log.info(`${pacFilePath} 文件时间已被修改其最近更新时间 '${lastModifiedTime}'`) + } + }) + }) + } + return pacFilePath }