refactor: 更新 eslint 和 prettier 配置 格式化代码

This commit is contained in:
alger
2025-07-23 23:54:35 +08:00
parent d1f5c8af84
commit c08c2cbf19
134 changed files with 3887 additions and 3301 deletions
+2 -5
View File
@@ -153,11 +153,8 @@ export const getBilibiliAudioUrl = async (bvid: string, cid: number): Promise<st
}
};
// 根据音乐名称搜索并直接返回音频URL
export const searchAndGetBilibiliAudioUrl = async (
keyword: string
): Promise<string> => {
export const searchAndGetBilibiliAudioUrl = async (keyword: string): Promise<string> => {
try {
// 搜索B站视频,取第一页第一个结果
const res = await searchBilibili({ keyword, page: 1, pagesize: 1 });
@@ -180,4 +177,4 @@ export const searchAndGetBilibiliAudioUrl = async (
console.error('根据名称搜索B站音频URL失败:', error);
throw error;
}
}
};
+25 -25
View File
@@ -1,4 +1,5 @@
import axios from 'axios';
import type { MusicSourceType } from '@/type/music';
/**
@@ -19,8 +20,8 @@ export interface ParsedMusicResult {
params: {
id: number;
type: string;
}
}
};
};
}
/**
@@ -32,8 +33,8 @@ export interface ParsedMusicResult {
* @returns 解析后的音乐URL及相关信息
*/
export const parseFromGDMusic = async (
id: number,
data: any,
id: number,
data: any,
quality: string = '999',
timeout: number = 15000
): Promise<ParsedMusicResult | null> => {
@@ -53,32 +54,31 @@ export const parseFromGDMusic = async (
console.error('GD音乐台解析:歌曲数据为空');
throw new Error('歌曲数据为空');
}
const songName = data.name || '';
let artistNames = '';
// 处理不同的艺术家字段结构
if (data.artists && Array.isArray(data.artists)) {
artistNames = data.artists.map(artist => artist.name).join(' ');
artistNames = data.artists.map((artist) => artist.name).join(' ');
} else if (data.ar && Array.isArray(data.ar)) {
artistNames = data.ar.map(artist => artist.name).join(' ');
artistNames = data.ar.map((artist) => artist.name).join(' ');
} else if (data.artist) {
artistNames = typeof data.artist === 'string' ? data.artist : '';
}
const searchQuery = `${songName} ${artistNames}`.trim();
if (!searchQuery || searchQuery.length < 2) {
console.error('GD音乐台解析:搜索查询过短', { name: songName, artists: artistNames });
throw new Error('搜索查询过短');
}
// 所有可用的音乐源 netease、joox、tidal
const allSources = ['joox', 'tidal', 'netease'
] as MusicSourceType[];
const allSources = ['joox', 'tidal', 'netease'] as MusicSourceType[];
console.log('GD音乐台开始搜索:', searchQuery);
// 依次尝试所有音源
for (const source of allSources) {
try {
@@ -109,7 +109,7 @@ export const parseFromGDMusic = async (
continue;
}
}
console.log('GD音乐台所有音源均解析失败');
return null;
})(),
@@ -142,32 +142,32 @@ const baseUrl = 'https://music-api.gdstudio.xyz/api.php';
* @returns 音乐URL结果
*/
async function searchAndGetUrl(
source: MusicSourceType,
searchQuery: string,
source: MusicSourceType,
searchQuery: string,
quality: string
): Promise<GDMusicUrlResult | null> {
// 1. 搜索歌曲
const searchUrl = `${baseUrl}?types=search&source=${source}&name=${encodeURIComponent(searchQuery)}&count=1&pages=1`;
console.log(`GD音乐台尝试音源 ${source} 搜索:`, searchUrl);
const searchResponse = await axios.get(searchUrl, { timeout: 5000 });
if (searchResponse.data && Array.isArray(searchResponse.data) && searchResponse.data.length > 0) {
const firstResult = searchResponse.data[0];
if (!firstResult || !firstResult.id) {
console.log(`GD音乐台 ${source} 搜索结果无效`);
return null;
}
const trackId = firstResult.id;
const trackSource = firstResult.source || source;
// 2. 获取歌曲URL
const songUrl = `${baseUrl}?types=url&source=${trackSource}&id=${trackId}&br=${quality}`;
console.log(`GD音乐台尝试获取 ${trackSource} 歌曲URL:`, songUrl);
const songResponse = await axios.get(songUrl, { timeout: 5000 });
if (songResponse.data && songResponse.data.url) {
return {
url: songResponse.data.url,
@@ -183,4 +183,4 @@ async function searchAndGetUrl(
console.log(`GD音乐台 ${source} 搜索结果为空`);
return null;
}
}
}
+18 -15
View File
@@ -1,13 +1,15 @@
import { cloneDeep } from 'lodash';
import { musicDB } from '@/hooks/MusicHook';
import { useSettingsStore, useUserStore } from '@/store';
import type { ILyric } from '@/type/lyric';
import type { SongResult } from '@/type/music';
import { isElectron } from '@/utils';
import request from '@/utils/request';
import requestMusic from '@/utils/request_music';
import { cloneDeep } from 'lodash';
import { parseFromGDMusic } from './gdmusic';
import type { SongResult } from '@/type/music';
import { searchAndGetBilibiliAudioUrl } from './bilibili';
import { parseFromGDMusic } from './gdmusic';
const { addData, getData, deleteData } = musicDB;
@@ -89,12 +91,13 @@ export const getMusicLrc = async (id: number) => {
*/
const getBilibiliAudio = async (data: SongResult) => {
const songName = data?.name || '';
const artistName = Array.isArray(data?.ar) && data.ar.length > 0 && data.ar[0]?.name ? data.ar[0].name : '';
const artistName =
Array.isArray(data?.ar) && data.ar.length > 0 && data.ar[0]?.name ? data.ar[0].name : '';
const albumName = data?.al && typeof data.al === 'object' && data.al?.name ? data.al.name : '';
const searchQuery = [songName, artistName, albumName].filter(Boolean).join(' ').trim();
console.log('开始搜索bilibili音频:', searchQuery);
const url = await searchAndGetBilibiliAudioUrl(searchQuery);
return {
data: {
@@ -131,7 +134,7 @@ const getGDMusicAudio = async (id: number, data: SongResult) => {
* @returns 解析结果
*/
const getUnblockMusicAudio = (id: number, data: SongResult, sources: any[]) => {
const filteredSources = sources.filter(source => source !== 'gdmusic');
const filteredSources = sources.filter((source) => source !== 'gdmusic');
console.log(`使用unblockMusic解析,音源:`, filteredSources);
return window.api.unblockMusic(id, cloneDeep(data), cloneDeep(filteredSources));
};
@@ -144,17 +147,17 @@ const getUnblockMusicAudio = (id: number, data: SongResult, sources: any[]) => {
*/
export const getParsingMusicUrl = async (id: number, data: SongResult) => {
const settingStore = useSettingsStore();
// 如果禁用了音乐解析功能,则直接返回空结果
if (!settingStore.setData.enableMusicUnblock) {
return Promise.resolve({ data: { code: 404, message: '音乐解析功能已禁用' } });
}
// 1. 确定使用的音源列表(自定义或全局)
const songId = String(id);
const savedSourceStr = localStorage.getItem(`song_source_${songId}`);
let musicSources: any[] = [];
try {
if (savedSourceStr) {
// 使用自定义音源
@@ -172,14 +175,14 @@ export const getParsingMusicUrl = async (id: number, data: SongResult) => {
console.error('解析音源设置失败,使用全局设置', e);
musicSources = settingStore.setData.enabledMusicSources || [];
}
// 2. 按优先级解析
// 2.1 Bilibili解析(优先级最高)
if (musicSources.includes('bilibili')) {
return await getBilibiliAudio(data);
}
// 2.2 GD音乐台解析
if (musicSources.includes('gdmusic')) {
const gdResult = await getGDMusicAudio(id, data);
@@ -187,12 +190,12 @@ export const getParsingMusicUrl = async (id: number, data: SongResult) => {
// GD解析失败,继续下一步
console.log('GD音乐台解析失败,尝试使用其他音源');
}
console.log('musicSources',musicSources)
console.log('musicSources', musicSources);
// 2.3 使用unblockMusic解析其他音源
if (isElectron && musicSources.length > 0) {
return getUnblockMusicAudio(id, data, musicSources);
}
// 3. 后备方案:使用API请求
console.log('无可用音源或不在Electron环境中,使用API请求');
return requestMusic.get<any>('/music', { params: { id } });
+1 -1
View File
@@ -24,4 +24,4 @@ export function getImportTaskStatus(id: string | number) {
method: 'get',
params: { id }
});
}
}
-1
View File
@@ -14,7 +14,6 @@ export function getUserPlaylist(uid: number, limit: number = 30, offset: number
// 播放历史
// /user/record?uid=32953014&type=1
export function getUserRecord(uid: number, type: number = 0) {
return request.get('/user/record', {
params: { uid, type },
noRetry: true