From 95126a85d8de24ef4d7e2a0f4200abdf5a1c168f Mon Sep 17 00:00:00 2001 From: AoXuan Date: Wed, 13 Aug 2025 20:00:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=85=81=E8=AE=B8http=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD&=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=A4=9A=E4=B8=AA?= =?UTF-8?q?=E9=95=9C=E5=83=8F=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 AutoMode 组件中添加了多个 gh-proxy 镜像选项 - 在 BackendStep 组件中增加了新的镜像选择项 - 修改了 downloadService 中的下载逻辑,支持 http 和 https - 更新了 gitService 和 pythonService 中的下载 URL - 在 Home 组件中添加了动态问候语 --- frontend/electron/services/downloadService.ts | 77 ++++--- frontend/electron/services/gitService.ts | 2 +- frontend/electron/services/pythonService.ts | 2 +- .../components/initialization/AutoMode.vue | 5 + .../components/initialization/BackendStep.vue | 7 +- frontend/src/router/index.ts | 36 +-- frontend/src/views/Home.vue | 208 +++++++++--------- 7 files changed, 182 insertions(+), 155 deletions(-) diff --git a/frontend/electron/services/downloadService.ts b/frontend/electron/services/downloadService.ts index 7fca276..c40759d 100644 --- a/frontend/electron/services/downloadService.ts +++ b/frontend/electron/services/downloadService.ts @@ -1,6 +1,7 @@ import * as https from 'https' import * as fs from 'fs' import { BrowserWindow } from 'electron' +import * as http from 'http' let mainWindow: BrowserWindow | null = null @@ -8,51 +9,55 @@ export function setMainWindow(window: BrowserWindow) { mainWindow = window } -// 下载文件的通用函数 export function downloadFile(url: string, outputPath: string): Promise { return new Promise((resolve, reject) => { console.log(`开始下载文件: ${url}`) console.log(`保存路径: ${outputPath}`) - + const file = fs.createWriteStream(outputPath) - - https.get(url, (response) => { - const totalSize = parseInt(response.headers['content-length'] || '0', 10) - let downloadedSize = 0 + // 创建HTTP客户端,兼容https和http + const client = url.startsWith('https') ? https : http - console.log(`文件大小: ${totalSize} bytes`) - response.pipe(file) + client + .get(url, response => { + const totalSize = parseInt(response.headers['content-length'] || '0', 10) + let downloadedSize = 0 - response.on('data', (chunk) => { - downloadedSize += chunk.length - const progress = Math.round((downloadedSize / totalSize) * 100) - - console.log(`下载进度: ${progress}% (${downloadedSize}/${totalSize})`) - - if (mainWindow) { - mainWindow.webContents.send('download-progress', { - progress, - status: 'downloading', - message: `下载中... ${progress}%` - }) - } + console.log(`文件大小: ${totalSize} bytes`) + + response.pipe(file) + + response.on('data', chunk => { + downloadedSize += chunk.length + const progress = totalSize ? Math.round((downloadedSize / totalSize) * 100) : 0 + + console.log(`下载进度: ${progress}% (${downloadedSize}/${totalSize})`) + + if (mainWindow) { + mainWindow.webContents.send('download-progress', { + progress, + status: 'downloading', + message: `下载中... ${progress}%`, + }) + } + }) + + file.on('finish', () => { + file.close() + console.log(`文件下载完成: ${outputPath}`) + resolve() + }) + + file.on('error', err => { + console.error(`文件写入错误: ${err.message}`) + fs.unlink(outputPath, () => {}) // 删除不完整的文件 + reject(err) + }) }) - - file.on('finish', () => { - file.close() - console.log(`文件下载完成: ${outputPath}`) - resolve() - }) - - file.on('error', (err) => { - console.error(`文件写入错误: ${err.message}`) - fs.unlink(outputPath, () => {}) // 删除不完整的文件 + .on('error', err => { + console.error(`下载错误: ${err.message}`) reject(err) }) - }).on('error', (err) => { - console.error(`下载错误: ${err.message}`) - reject(err) - }) }) -} \ No newline at end of file +} diff --git a/frontend/electron/services/gitService.ts b/frontend/electron/services/gitService.ts index e06e181..91953cc 100644 --- a/frontend/electron/services/gitService.ts +++ b/frontend/electron/services/gitService.ts @@ -11,7 +11,7 @@ export function setMainWindow(window: BrowserWindow) { mainWindow = window } -const gitDownloadUrl = 'https://alist-automaa.fearr.xyz/d/AUTO_MAA/git.zip' +const gitDownloadUrl = 'http://221.236.27.82:10197/d/AUTO_MAA/git.zip' // 递归复制目录,包括文件和隐藏文件 function copyDirSync(src: string, dest: string) { diff --git a/frontend/electron/services/pythonService.ts b/frontend/electron/services/pythonService.ts index 17ee9ed..e0e3454 100644 --- a/frontend/electron/services/pythonService.ts +++ b/frontend/electron/services/pythonService.ts @@ -64,7 +64,7 @@ async function installPip(pythonPath: string, appRoot: string): Promise { console.log('pip未安装,开始安装...') const getPipPath = path.join(pythonPath, 'get-pip.py') - const getPipUrl = 'https://alist-automaa.fearr.xyz/d/AUTO_MAA/get-pip.py' + const getPipUrl = 'http://221.236.27.82:10197/d/AUTO_MAA/get-pip.py' console.log(`Python可执行文件路径: ${pythonExe}`) console.log(`get-pip.py下载URL: ${getPipUrl}`) diff --git a/frontend/src/components/initialization/AutoMode.vue b/frontend/src/components/initialization/AutoMode.vue index 96c1034..1f9a667 100644 --- a/frontend/src/components/initialization/AutoMode.vue +++ b/frontend/src/components/initialization/AutoMode.vue @@ -170,7 +170,12 @@ function getGitMirrorUrl(mirrorKey: string): string { const mirrors = { github: 'https://github.com/DLmaster361/AUTO_MAA.git', ghfast: 'https://ghfast.top/https://github.com/DLmaster361/AUTO_MAA.git', + ghproxy_cloudflare: 'https://gh-proxy.com/https://github.com/DLmaster361/AUTO_MAA.git.git', + ghproxy_hongkong: 'https://hk.gh-proxy.com/https://github.com/DLmaster361/AUTO_MAA.git.git', + ghproxy_fastly: 'https://cdn.gh-proxy.com/https://github.com/DLmaster361/AUTO_MAA.git.git', + ghproxy_edgeone: 'https://edgeone.gh-proxy.com/https://github.com/DLmaster361/AUTO_MAA.git.git' } + return mirrors[mirrorKey as keyof typeof mirrors] || mirrors.github } diff --git a/frontend/src/components/initialization/BackendStep.vue b/frontend/src/components/initialization/BackendStep.vue index 438a15e..7bafc3c 100644 --- a/frontend/src/components/initialization/BackendStep.vue +++ b/frontend/src/components/initialization/BackendStep.vue @@ -52,9 +52,14 @@ defineProps<{ const gitMirrors = ref([ { key: 'github', name: 'GitHub 官方', url: 'https://github.com/DLmaster361/AUTO_MAA.git', speed: null }, - { key: 'ghfast', name: 'ghfast 镜像', url: 'https://ghfast.top/https://github.com/DLmaster361/AUTO_MAA.git', speed: null } + { key: 'ghfast', name: 'ghfast 镜像', url: 'https://ghfast.top/https://github.com/DLmaster361/AUTO_MAA.git', speed: null }, + { key: 'ghproxy_cloudflare', name: 'gh-proxy Cloudflare 全球加速', url: 'https://gh-proxy.com/https://github.com/DLmaster361/AUTO_MAA.git.git', speed: null }, + { key: 'ghproxy_hongkong', name: 'gh-proxy 香港节点(大陆优化)', url: 'https://hk.gh-proxy.com/https://github.com/DLmaster361/AUTO_MAA.git.git', speed: null }, + { key: 'ghproxy_fastly', name: 'gh-proxy Fastly CDN', url: 'https://cdn.gh-proxy.com/https://github.com/DLmaster361/AUTO_MAA.git.git', speed: null }, + { key: 'ghproxy_edgeone', name: 'gh-proxy EdgeOne 全球加速', url: 'https://edgeone.gh-proxy.com/https://github.com/DLmaster361/AUTO_MAA.git.git', speed: null } ]) + const selectedGitMirror = ref('github') const testingGitSpeed = ref(false) diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index 5aadc2e..0daeb61 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -90,23 +90,23 @@ const router = createRouter({ }) -// // 添加路由守卫,确保在生产环境中也能正确进入初始化页面 -// router.beforeEach(async (to, from, next) => { -// console.log('路由守卫:', { to: to.path, from: from.path }) -// -// // 如果访问的不是初始化页面,且没有初始化标记,则重定向到初始化页面 -// if (to.path !== '/initialization') { -// const initialized = await isAppInitialized() -// console.log('检查初始化状态:', initialized) -// -// if (!initialized) { -// console.log('应用未初始化,重定向到初始化页面') -// next('/initialization') -// return -// } -// } -// -// next() -// }) +// 添加路由守卫,确保在生产环境中也能正确进入初始化页面 +router.beforeEach(async (to, from, next) => { + console.log('路由守卫:', { to: to.path, from: from.path }) + + // 如果访问的不是初始化页面,且没有初始化标记,则重定向到初始化页面 + if (to.path !== '/initialization') { + const initialized = await isAppInitialized() + console.log('检查初始化状态:', initialized) + + if (!initialized) { + console.log('应用未初始化,重定向到初始化页面') + next('/initialization') + return + } + } + + next() +}) export default router diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vue index 46e4c4a..cafe266 100644 --- a/frontend/src/views/Home.vue +++ b/frontend/src/views/Home.vue @@ -1,101 +1,101 @@