Skip to content

Commit 337bb28

Browse files
committed
fix: 前端内存泄漏与 CLI 健壮性
- ImportMusicModal:watch + revokeObjectURL 防内存泄漏\n- MusicList:fetch 加 res.ok 检查\n- InfoCommand:数组越界保护\n- DebugCommand:异常返回 1 而非 throw 崩溃
1 parent 80d89c9 commit 337bb28

4 files changed

Lines changed: 25 additions & 4 deletions

File tree

ChuChartManager.CLI/Commands/DebugCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public override int Execute(CommandContext context)
3030
if (exception != null)
3131
{
3232
Console.Error.WriteLine($"发生错误: {exception}");
33-
throw exception;
33+
return 1;
3434
}
3535
return 0;
3636
}

ChuChartManager.CLI/Commands/InfoCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public override int Execute(CommandContext context, Settings settings)
6262

6363
for (int i = 0; i < 6; i++)
6464
{
65-
var f = music.Fumens[i];
65+
var f = i < music.Fumens.Length ? music.Fumens[i] : null;
6666
if (f == null)
6767
{
6868
table.AddRow(DiffNames[i], "-", "-", "否");

ChuChartManager/Front/src/views/ImportMusicModal.vue

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { ref, computed, onMounted } from 'vue'
2+
import { ref, computed, watch, onMounted, onUnmounted } from 'vue'
33
import { useI18n } from 'vue-i18n'
44
import { Button, TextInput, NumberInput, Select, Modal, addToast } from '@munet/ui'
55
import { getGenreMap, getSources, importMusicCheck, importMusicExecute } from '@/api'
@@ -31,7 +31,27 @@ const genreMap = ref<Record<number, string>>({})
3131
const sources = ref<string[]>([])
3232
3333
const showForm = computed(() => step.value === 'form' || step.value === 'executing')
34-
const coverUrl = computed(() => coverFile.value ? URL.createObjectURL(coverFile.value) : '')
34+
const coverUrl = ref('')
35+
36+
let currentCoverUrl: string | null = null
37+
watch(coverFile, (file) => {
38+
if (currentCoverUrl) {
39+
URL.revokeObjectURL(currentCoverUrl)
40+
currentCoverUrl = null
41+
}
42+
if (file) {
43+
currentCoverUrl = URL.createObjectURL(file)
44+
coverUrl.value = currentCoverUrl
45+
} else {
46+
coverUrl.value = ''
47+
}
48+
})
49+
50+
onUnmounted(() => {
51+
if (currentCoverUrl) {
52+
URL.revokeObjectURL(currentCoverUrl)
53+
}
54+
})
3555
3656
const genreOptions = computed(() =>
3757
Object.entries(genreMap.value).map(([id, name]) => ({ label: name, value: Number(id) }))

ChuChartManager/Front/src/views/MusicList.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ async function exportToFolder(url: string) {
220220
221221
try {
222222
const res = await fetch(url)
223+
if (!res.ok) throw new Error(`HTTP ${res.status}: ${res.statusText}`)
223224
const zipReader = new ZipReader(res.body!)
224225
try {
225226
const entries = zipReader.getEntriesGenerator()

0 commit comments

Comments
 (0)