-
Notifications
You must be signed in to change notification settings - Fork 2
Dev2alpha #212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dev2alpha #212
Changes from all commits
63594da
6fc1916
11c8d94
76c351e
843b9b6
a21b995
13c6b7e
08b96eb
382f6bf
90082f8
2905bf6
07f4f3d
ca04424
0100591
0303acb
290cabe
ef08d35
1cee791
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| +161 −1 | assets/session-debug.html | |
| +32 −0 | src/app/api/v1/audio.py | |
| +89 −6 | src/app/api/v1/session.py | |
| +40 −0 | src/app/models/audio_track.py | |
| +43 −1 | src/app/models/session.py | |
| +18 −1 | src/app/schemas/session_request.py | |
| +270 −24 | src/app/services/audio_preprocessor.py | |
| +5 −1 | src/app/services/session_factory.py | |
| +105 −12 | src/app/services/session_manager.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -413,15 +413,24 @@ export class UvBootstrapperService { | |
| ): Promise<boolean> { | ||
| const key = `${platform}-${arch}` | ||
|
|
||
| // 检查是否已存在 | ||
| const installation = await this.checkUvInstallation() | ||
| if (installation.exists && installation.isDownloaded) { | ||
| logger.info('uv 已存在,跳过下载', { platform, arch, path: installation.path }) | ||
| // 检查目标平台的缓存二进制 | ||
| const downloadedPath = this.getDownloadedUvPath(platform, arch) | ||
| if (downloadedPath) { | ||
| logger.info('uv 已存在,跳过下载', { platform, arch, path: downloadedPath }) | ||
| return true | ||
| } | ||
|
|
||
| // 仅当请求的平台与当前进程一致时,才额外使用缓存的系统检测结果 | ||
| if (platform === process.platform && arch === process.arch) { | ||
| const installation = await this.checkUvInstallation() | ||
| if (installation.exists && installation.isDownloaded) { | ||
| logger.info('uv 已存在,跳过下载', { platform, arch, path: installation.path }) | ||
| return true | ||
| } | ||
| } | ||
|
|
||
| // 检查是否正在下载 | ||
| if (this.downloadProgress.has(key)) { | ||
| if (this.downloadProgress.has(key) || this.downloadController.has(key)) { | ||
| logger.warn('uv 正在下载中', { platform, arch }) | ||
| return false | ||
| } | ||
|
|
@@ -466,12 +475,12 @@ export class UvBootstrapperService { | |
|
|
||
| this.downloadProgress.set(key, progress) | ||
|
|
||
| const platformDir = `${version.version}-${platform}-${arch}` | ||
| const targetDir = path.join(this.binariesDir, platformDir) | ||
| const tempDir = path.join(this.binariesDir, '.temp', key) | ||
|
|
||
|
Comment on lines
+478
to
+481
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 缺少下载件完整性校验(SHA‑256),建议增加校验并在不匹配时中止与清理 当前直接解压运行下载产物,存在供应链风险。建议若 UvVersion.sha256 提供时,下载后先校验哈希,不匹配则清理并报错。 可在“下载文件”与“解压文件”之间插入校验逻辑: // 下载文件后,添加以下校验(若提供 sha256)
if (version.sha256) {
const computed = await new Promise<string>((resolve, reject) => {
const { createHash } = require('node:crypto')
const { createReadStream } = require('node:fs')
const hash = createHash('sha256')
const rs = createReadStream(downloadPath)
rs.on('data', (c: Buffer) => hash.update(c))
rs.on('error', reject)
rs.on('end', () => resolve(hash.digest('hex')))
})
if (computed.toLowerCase() !== version.sha256.toLowerCase()) {
logger.error('uv 包校验失败,哈希不匹配', {
expected: version.sha256,
actual: computed
})
// 失败时清理临时目录并中止
this.cleanupTempDir(tempDir)
throw new Error('uv 下载包校验失败(SHA-256 不匹配)')
}
}同时可考虑:
Also applies to: 488-502, 503-566, 580-581 🤖 Prompt for AI Agents |
||
| try { | ||
| // 创建目标目录 | ||
| const platformDir = `${version.version}-${platform}-${arch}` | ||
| const targetDir = path.join(this.binariesDir, platformDir) | ||
| const tempDir = path.join(this.binariesDir, '.temp', key) | ||
|
|
||
| this.ensureDir(targetDir) | ||
| this.ensureDir(tempDir) | ||
|
|
||
|
|
@@ -550,9 +559,6 @@ export class UvBootstrapperService { | |
|
|
||
| logger.info('uv 下载完成', { platform, arch, finalPath }) | ||
|
|
||
| // 清理临时文件 | ||
| this.cleanupTempDir(tempDir) | ||
|
|
||
| // 清除缓存以便重新检测 | ||
| UvBootstrapperService.clearUvCache(platform, arch) | ||
|
|
||
|
|
@@ -571,6 +577,7 @@ export class UvBootstrapperService { | |
| } finally { | ||
| this.downloadProgress.delete(key) | ||
| this.downloadController.delete(key) | ||
| this.cleanupTempDir(tempDir) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -332,7 +332,9 @@ const api = { | |
| uptime?: number | ||
| error?: string | ||
| }> => ipcRenderer.invoke(IpcChannel.MediaServer_GetInfo), | ||
| getPort: (): Promise<number | null> => ipcRenderer.invoke(IpcChannel.MediaServer_GetPort) | ||
| getPort: (): Promise<number | null> => ipcRenderer.invoke(IpcChannel.MediaServer_GetPort), | ||
| cleanupCachesForFile: (filePath: string) => | ||
| ipcRenderer.invoke(IpcChannel.MediaServer_CleanupCachesForFile, filePath) | ||
| }, | ||
|
Comment on lines
+335
to
338
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial 为 cleanupCachesForFile 补齐强类型定义,提升调用端类型安全 建议在 packages/shared 导出 示例:
cleanupCachesForFile: (filePath: string): Promise<TranscodeCacheCleanupResult> =>
ipcRenderer.invoke(IpcChannel.MediaServer_CleanupCachesForFile, filePath)🤖 Prompt for AI Agents |
||
| fs: { | ||
| checkFileExists: (filePath: string): Promise<boolean> => | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import { loggerService } from '@logger' | ||
| import FFmpegDownloadPrompt from '@renderer/components/FFmpegDownloadPrompt' | ||
| import FileManager from '@renderer/services/FileManager' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major 🧩 Analysis chain删除流程增强方向正确,但需两点完善:避免闭包更新与替换 Emoji 图标
另外,请确认 FileManager.getFile(record.fileId) 在 renderer 层存在并返回包含 path 的对象。 为验证 FileManager.getFile 的可用性,可在仓库根运行: Also applies to: 169-181, 193-207 🏁 Script executed: #!/bin/bash
# 查找 renderer 侧 FileManager 并确认导出 getFile
fd -t f -a "FileManager.(ts|tsx|js)" src/renderer 2>/dev/null
rg -n -C2 "class\\s+FileManager|export\\s+(default\\s+)?class\\s+FileManager|export\\s+(const|function|class)\\s+FileManager" -g "src/renderer/**"
rg -n -C2 "getFile\\s*\\(" -g "src/renderer/**"Length of output: 2995 为验证 🏁 Script executed: #!/bin/bash
rg -n -C3 "setCachedVideos" -g "src/renderer/src/pages/home/HomePage.tsx"
rg -n -C3 "cachedVideos" -g "src/renderer/src/pages/home/HomePage.tsx"
rg -n "⚠️" -g "src/renderer/src/pages/home/HomePage.tsx"Length of output: 4760 优化删除流程:函数式更新 store 与替换 Emoji 图标
FileManager.getFile 已验证,无需改动。 🤖 Prompt for AI Agents |
||
| import HomePageVideoService, { type HomePageVideoItem } from '@renderer/services/HomePageVideos' | ||
| import { VideoLibraryService } from '@renderer/services/VideoLibrary' | ||
| import { useSettingsStore } from '@renderer/state/stores/settings.store' | ||
|
|
@@ -164,6 +165,21 @@ export function HomePage(): React.JSX.Element { | |
| onOk: async () => { | ||
| try { | ||
| const videoLibraryService = new VideoLibraryService() | ||
| let filePath: string | null = null | ||
|
|
||
| try { | ||
| const record = await videoLibraryService.getRecordById(video.id) | ||
| if (record?.fileId) { | ||
| const fileInfo = await FileManager.getFile(record.fileId) | ||
| filePath = fileInfo?.path ?? null | ||
| } | ||
| } catch (lookupError) { | ||
| logger.warn('获取视频文件信息失败,跳过转码缓存清理', { | ||
| error: lookupError, | ||
| videoId: video.id | ||
| }) | ||
| } | ||
|
|
||
| await videoLibraryService.deleteRecord(video.id) | ||
|
|
||
| // 从本地状态中移除该视频 | ||
|
|
@@ -173,6 +189,22 @@ export function HomePage(): React.JSX.Element { | |
| setCachedVideos(cachedVideos.filter((v) => v.id !== video.id)) | ||
|
|
||
| message.success(t('home.delete.success_message')) | ||
|
|
||
| if (filePath) { | ||
| void window.api.mediaServer | ||
| .cleanupCachesForFile(filePath) | ||
| .then((result) => { | ||
| logger.info('已清理转码缓存', { result, videoId: video.id }) | ||
| }) | ||
| .catch((cleanupError) => { | ||
| logger.warn('清理转码缓存失败', { | ||
| error: | ||
| cleanupError instanceof Error ? cleanupError.message : String(cleanupError), | ||
| filePath, | ||
| videoId: video.id | ||
| }) | ||
| }) | ||
| } | ||
| } catch (error) { | ||
| logger.error('删除视频记录失败', { error }) | ||
| message.error(t('home.delete.error_message')) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removeDirectoryIfExists 对不存在目录也返回 removed:true,语义不准确
rm(..., { force: true }) 在路径不存在时不会抛错,当前实现会误报“已删除”。建议先检测存在性,区分“未找到”与“删除失败”。
应用此修正:
📝 Committable suggestion
🤖 Prompt for AI Agents