Skip to content

Commit 4a2b74b

Browse files
🐞 fix: 修复被错误移除的cloneDeep和lint问题 (#767)
1 parent 9eb2fbe commit 4a2b74b

File tree

10 files changed

+67
-39
lines changed

10 files changed

+67
-39
lines changed

electron/main/ipc/ipc-lyric.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ const initLyricIpc = (): void => {
4040
// 立即禁用 forward
4141
setLyricMouseEvents(false);
4242
// 防抖恢复:300ms 内无新事件则恢复
43-
restoreTimer && clearTimeout(restoreTimer);
43+
if (restoreTimer) clearTimeout(restoreTimer);
4444
restoreTimer = setTimeout(() => setLyricMouseEvents(true), 300);
4545
};
4646

4747
// 主窗口移动/调整大小结束:立即恢复 forward(仅 Windows/macOS 支持)
4848
const onMoveOrResizeEnd = () => {
4949
if (!isLocked) return;
50-
restoreTimer && clearTimeout(restoreTimer);
50+
if (restoreTimer) clearTimeout(restoreTimer);
5151
setLyricMouseEvents(true);
5252
};
5353

@@ -91,7 +91,7 @@ const initLyricIpc = (): void => {
9191
}
9292

9393
// 清理定时器
94-
restoreTimer && clearTimeout(restoreTimer);
94+
if (restoreTimer) clearTimeout(restoreTimer);
9595
restoreTimer = null;
9696
};
9797

electron/main/ipc/ipc-mpv.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const initMpvIpc = (): void => {
1212
const command = process.platform === "win32" ? "where.exe mpv" : "which mpv";
1313
execSync(command, { encoding: "utf-8" });
1414
return { installed: true };
15-
} catch (e) {
15+
} catch {
1616
return { installed: false };
1717
}
1818
});

electron/main/services/CacheService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export class CacheService {
195195
if (existsSync(dbPath)) dbTotal += (await stat(dbPath)).size;
196196
if (existsSync(dbPath + "-wal")) dbTotal += (await stat(dbPath + "-wal")).size;
197197
if (existsSync(dbPath + "-shm")) dbTotal += (await stat(dbPath + "-shm")).size;
198-
} catch (e) {
198+
} catch {
199199
// ignore
200200
}
201201

@@ -342,7 +342,7 @@ export class CacheService {
342342
try {
343343
const now = new Date();
344344
await utimes(target, now, now);
345-
} catch (e) {
345+
} catch {
346346
// 忽略 utimes 失败
347347
}
348348

electron/main/services/MpvService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export class MpvService {
147147
});
148148
});
149149
return;
150-
} catch (e) {
150+
} catch {
151151
await new Promise((r) => setTimeout(r, 500));
152152
}
153153
}

electron/server/qqmusic/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ async function initSession(): Promise<void> {
7777
};
7878
serverLog.log("🔑 QQ 音乐会话初始化成功");
7979
}
80-
} catch (error) {
80+
} catch {
8181
serverLog.warn("⚠️ QQ 音乐会话初始化失败,将使用默认参数");
8282
}
8383
}
@@ -212,7 +212,9 @@ async function getQQMusicLyric(
212212
// lyric 就是 LRC 格式
213213
try {
214214
result.lrc = decryptQrc(lyric);
215-
} catch {}
215+
} catch {
216+
// LRC 解密失败,忽略
217+
}
216218
} else {
217219
// 单独请求 LRC 格式歌词
218220
try {
@@ -490,7 +492,8 @@ export const initQQMusicAPI = async (fastify: FastifyInstance) => {
490492
);
491493

492494
// 返回歌曲信息和歌词
493-
const { code: _, ...lyrics } = lyricResult;
495+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
496+
const { code: _code, ...lyrics } = lyricResult;
494497
return reply.send({
495498
code: 200,
496499
song: {

electron/server/qqmusic/qrc.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,25 @@ export function decryptQrc(encryptedQrc: string): string {
3434
try {
3535
decompressed = inflateSync(decryptedBuffer);
3636
return decompressed.toString("utf8");
37-
} catch {}
37+
} catch {
38+
// zlib inflate 失败,尝试其他格式
39+
}
3840

3941
// 尝试 2: raw inflate (无 header)
4042
try {
4143
decompressed = inflateRawSync(decryptedBuffer);
4244
return decompressed.toString("utf8");
43-
} catch {}
45+
} catch {
46+
// raw inflate 失败,尝试其他格式
47+
}
4448

4549
// 尝试 3: gzip unzip
4650
try {
4751
decompressed = unzipSync(decryptedBuffer);
4852
return decompressed.toString("utf8");
49-
} catch {}
53+
} catch {
54+
// gzip unzip 失败,尝试其他格式
55+
}
5056

5157
// 尝试 4: 可能数据本身就不是压缩的
5258
const str = decryptedBuffer.toString("utf8");

src/api/lastfm.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ lastfmClient.interceptors.response.use(
3434
const { status, data } = response;
3535

3636
switch (status) {
37-
case 403:
37+
case 403: {
3838
const code = data?.error;
3939
if (code === 9 || code === 4 || code === 26) {
4040
window.$message.error("Last.fm 认证失败,需要重新授权,已断开与 Last.fm 的连接!");
@@ -43,6 +43,7 @@ lastfmClient.interceptors.response.use(
4343
window.$message.error("Last.fm 认证失败,可能需要重新授权");
4444
}
4545
break;
46+
}
4647
case 401:
4748
window.$message.error("Last.fm 未授权,已断开与 Last.fm 的连接!");
4849
disconnect();

src/components/Player/PlayerLyric/AMLyric.vue

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ import { useMusicStore, useSettingStore, useStatusStore } from "@/stores";
5555
import { getLyricLanguage } from "@/utils/format";
5656
import { usePlayerController } from "@/core/player/PlayerController";
5757
58+
// 此处cloneDeep 删除会暴毙 不要动
59+
60+
import { cloneDeep } from "lodash-es";
5861
import { lyricLangFontStyle } from "@/utils/lyricFontConfig";
5962
6063
defineProps({
@@ -72,37 +75,51 @@ const player = usePlayerController();
7275
const lyricPlayerRef = ref<any | null>(null);
7376
7477
// 当前歌词
75-
const amLyricsData = computed<LyricLine[]>(() => {
78+
const amLyricsData = computed(() => {
7679
const { songLyric } = musicStore;
7780
if (!songLyric) return [];
81+
7882
// 优先使用逐字歌词(YRC/TTML)
7983
const useYrc = songLyric.yrcData?.length && settingStore.showYrc;
8084
const lyrics = useYrc ? songLyric.yrcData : songLyric.lrcData;
85+
8186
// 简单检查歌词有效性
8287
if (!Array.isArray(lyrics) || lyrics.length === 0) return [];
83-
const { showTran, showRoma, showWordsRoma, swapTranRoma, lyricAlignRight } = settingStore;
84-
// 单次遍历处理,移除 cloneDeep 以提升性能
85-
return lyrics.map((line) => {
86-
const newLine = { ...line };
87-
// 不需要显示的字段
88-
if (!showTran) newLine.translatedLyric = "";
89-
if (!showRoma) newLine.romanLyric = "";
90-
// 逐字音译显示
91-
if (!showWordsRoma && newLine.words) {
92-
newLine.words = newLine.words.map((word) => ({ ...word, romanWord: "" }));
93-
}
94-
// 调换翻译与音译位置
95-
if (swapTranRoma) {
96-
const temp = newLine.translatedLyric;
97-
newLine.translatedLyric = newLine.romanLyric;
98-
newLine.romanLyric = temp;
99-
}
100-
// 如果开启了歌词靠右,反转 isDuet
101-
if (lyricAlignRight) {
102-
newLine.isDuet = !newLine.isDuet;
103-
}
104-
return newLine;
105-
}) as LyricLine[];
88+
89+
const clonedLyrics = cloneDeep(lyrics) as LyricLine[];
90+
91+
// 检查是否要不显示某一部分并删去
92+
const showTran = settingStore.showTran;
93+
const showRoma = settingStore.showRoma;
94+
const showWordsRoma = settingStore.showWordsRoma;
95+
96+
if (!showTran || !showRoma || !showWordsRoma) {
97+
clonedLyrics.forEach((line) => {
98+
if (!showTran) line.translatedLyric = "";
99+
if (!showRoma) line.romanLyric = "";
100+
if (!showWordsRoma) line.words.forEach((word) => (word.romanWord = ""));
101+
});
102+
}
103+
104+
105+
106+
// 调换翻译与音译位置
107+
if (settingStore.swapTranRoma) {
108+
clonedLyrics.forEach((line) => {
109+
const temp = line.translatedLyric;
110+
line.translatedLyric = line.romanLyric;
111+
line.romanLyric = temp;
112+
});
113+
}
114+
115+
// 如果开启了歌词靠右,反转 isDuet
116+
if (settingStore.lyricAlignRight) {
117+
clonedLyrics.forEach((line) => {
118+
line.isDuet = !line.isDuet;
119+
});
120+
}
121+
122+
return clonedLyrics;
106123
});
107124
108125
// 是否有对唱行

src/core/audio-player/ffmpeg-engine/FFmpegAudioPlayer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ export class FFmpegAudioPlayer extends BaseAudioPlayer {
284284
* 设置音频输出设备
285285
* @param _deviceId 设备 ID(不支持,依赖基类的 AudioContext.setSinkId)
286286
*/
287+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
287288
protected async doSetSinkId(_deviceId: string) {
288289
console.warn("[FFmpegAudioPlayer] doSetSinkId is not supported");
289290
}

src/utils/lyricParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type LyricWord = { word: string; startTime: number; endTime: number; romanWord:
1919
const META_TAG_REGEX = /^\[[a-z]+:/i;
2020
const TIME_TAG_REGEX = /\[(\d{2}):(\d{2})\.(\d{2,3})\]/g;
2121
const ENHANCED_TIME_TAG_REGEX = /<(\d{2}):(\d{2})\.(\d{2,3})>/;
22-
const WORD_BY_WORD_REGEX = /\[(\d{2}):(\d{2})\.(\d{2,3})\]([^\[\]]*)/g;
22+
const WORD_BY_WORD_REGEX = /\[(\d{2}):(\d{2})\.(\d{2,3})\]([^[\]]*)/g;
2323
const ENHANCED_WORD_REGEX = /<(\d{2}):(\d{2})\.(\d{2,3})>([^<]*)/g;
2424
const LINE_TIME_REGEX = /^\[(\d{2}):(\d{2})\.(\d{2,3})\]/;
2525

0 commit comments

Comments
 (0)