From c472ec06e58345a75ab60f0986445b983572e80a Mon Sep 17 00:00:00 2001 From: lqtmcstudio Date: Wed, 4 Feb 2026 11:16:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E4=B8=8D=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=B0=86=E7=BD=91=E7=BB=9C=E8=B5=84=E6=BA=90(?= =?UTF-8?q?=E9=9F=B3=E9=A2=91)=E7=BC=93=E5=AD=98=E5=88=B0=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ dist-electron/main.js | 20 ++++++++++++++++---- electron/main.ts | 4 +++- electron/proxyServer.ts | 19 ++++++++++++++++++- 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index a547bf3..fa87b47 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,5 @@ dist-ssr *.njsproj *.sln *.sw? +core/mpv.exe +.gitignore diff --git a/dist-electron/main.js b/dist-electron/main.js index 826d38b..2792ed2 100644 --- a/dist-electron/main.js +++ b/dist-electron/main.js @@ -357,9 +357,6 @@ async function proxyAndCache(req, res, targetUrl, cacheFilePath) { const range = parseRangeHeader(requestedRange, downloadState.totalSize); if (range && range.end < downloadState.currentSize) { console.log(`[Proxy] Serving range from in-progress cache`); - ({ - totalSize: downloadState.totalSize - }); const { start, end } = range; const chunksize = end - start + 1; res.writeHead(206, { @@ -487,7 +484,21 @@ async function proxyAndCache(req, res, targetUrl, cacheFilePath) { } }); } -function startProxyServer() { +let persistCacheEnabled = true; +function cleanupCache() { + if (!persistCacheEnabled && CACHE_DIR && fs.existsSync(CACHE_DIR)) { + console.log(`[Proxy] Cleaning up cache directory: ${CACHE_DIR}`); + try { + fs.rmSync(CACHE_DIR, { recursive: true, force: true }); + console.log("[Proxy] Cache cleanup complete"); + } catch (e) { + console.error("[Proxy] Failed to cleanup cache:", e); + } + } +} +function startProxyServer(persistCache = true) { + persistCacheEnabled = persistCache; + console.log(`[Proxy] Persist cache: ${persistCache}`); const server = http.createServer(async (req, res) => { res.setHeader("Access-Control-Allow-Origin", "*"); res.setHeader("Access-Control-Allow-Methods", "GET, HEAD, OPTIONS"); @@ -642,6 +653,7 @@ app.on("window-all-closed", () => { } }); app.on("will-quit", () => { + cleanupCache(); if (mpv) { mpv.destroy(); } diff --git a/electron/main.ts b/electron/main.ts index bae28a2..a1dd2ff 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -4,7 +4,7 @@ import { fileURLToPath } from 'node:url' import path from 'node:path' import fs from 'node:fs' import { MpvController } from './mpvController' -import { startProxyServer } from './proxyServer' +import { startProxyServer, cleanupCache } from './proxyServer' import { PluginSystem } from '../src/main/pluginSystem.ts' // @ts-ignore const require = createRequire(import.meta.url) @@ -99,6 +99,7 @@ app.on('window-all-closed', () => { }) app.on('will-quit', () => { + cleanupCache() if (mpv) { mpv.destroy() } @@ -132,6 +133,7 @@ app.on('activate', () => { } }) +// Test app.whenReady().then(() => { // Ensure plugins directory exists const pluginsPath = path.join(app.getPath('userData'), 'plugins') diff --git a/electron/proxyServer.ts b/electron/proxyServer.ts index 26cd372..1fd5804 100644 --- a/electron/proxyServer.ts +++ b/electron/proxyServer.ts @@ -397,7 +397,24 @@ async function proxyAndCache( }); } -export function startProxyServer() { +let persistCacheEnabled = true; + +export function cleanupCache() { + if (!persistCacheEnabled && CACHE_DIR && fs.existsSync(CACHE_DIR)) { + console.log(`[Proxy] Cleaning up cache directory: ${CACHE_DIR}`); + try { + fs.rmSync(CACHE_DIR, { recursive: true, force: true }); + console.log('[Proxy] Cache cleanup complete'); + } catch (e) { + console.error('[Proxy] Failed to cleanup cache:', e); + } + } +} + +export function startProxyServer(persistCache: boolean = true) { + persistCacheEnabled = persistCache; + console.log(`[Proxy] Persist cache: ${persistCache}`); + const server = http.createServer(async (req, res) => { res.setHeader('Access-Control-Allow-Origin', '*'); res.setHeader('Access-Control-Allow-Methods', 'GET, HEAD, OPTIONS');