mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-17 13:48:02 +00:00
feat: updates
This commit is contained in:
parent
9a52681687
commit
840a5b8e9b
104 changed files with 1645 additions and 13494 deletions
|
|
@ -4,7 +4,7 @@ import duration from 'dayjs/plugin/duration'
|
|||
import { CacheAPIs } from '@/shared/CacheAPIs'
|
||||
import { average } from 'color.js'
|
||||
import { colord } from 'colord'
|
||||
import { supportedLanguages } from '../i18n/i18n'
|
||||
import { SupportedLanguage } from '../i18n/i18n'
|
||||
|
||||
/**
|
||||
* @description 调整网易云和苹果音乐封面图片大小
|
||||
|
|
@ -73,7 +73,7 @@ export function formatDate(
|
|||
*/
|
||||
export function formatDuration(
|
||||
milliseconds: number,
|
||||
locale: typeof supportedLanguages[number] = 'zh-CN',
|
||||
locale: SupportedLanguage = 'zh-CN',
|
||||
format: 'hh:mm:ss' | 'hh[hr] mm[min]' = 'hh:mm:ss'
|
||||
): string {
|
||||
dayjs.extend(duration)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import toast from 'react-hot-toast'
|
|||
import { scrobble } from '@/web/api/user'
|
||||
import { fetchArtistWithReactQuery } from '../api/hooks/useArtist'
|
||||
import { appName } from './const'
|
||||
import { FetchAudioSourceResponse } from '@/shared/api/Track'
|
||||
|
||||
type TrackID = number
|
||||
export enum TrackListSourceType {
|
||||
|
|
@ -218,14 +219,23 @@ export class Player {
|
|||
* @param {TrackID} trackID
|
||||
*/
|
||||
private async _fetchAudioSource(trackID: TrackID) {
|
||||
const response = await fetchAudioSourceWithReactQuery({ id: trackID })
|
||||
let audio = response.data?.[0]?.url
|
||||
if (audio && audio.includes('126.net')) {
|
||||
audio = audio.replace('http://', 'https://')
|
||||
}
|
||||
return {
|
||||
audio,
|
||||
id: trackID,
|
||||
try {
|
||||
console.log(`[player] fetchAudioSourceWithReactQuery `, trackID)
|
||||
const response = await fetchAudioSourceWithReactQuery({ id: trackID })
|
||||
console.log(`[player] fetchAudioSourceWithReactQuery `, response)
|
||||
let audio = response.data?.[0]?.url
|
||||
if (audio && audio.includes('126.net')) {
|
||||
audio = audio.replace('http://', 'https://')
|
||||
}
|
||||
return {
|
||||
audio,
|
||||
id: trackID,
|
||||
}
|
||||
} catch {
|
||||
return {
|
||||
audio: null,
|
||||
id: trackID,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -274,7 +284,7 @@ export class Player {
|
|||
onend: () => this._howlerOnEndCallback(),
|
||||
})
|
||||
_howler = howler
|
||||
window.howler = howler
|
||||
;(window as any).howler = howler
|
||||
if (autoplay) {
|
||||
this.play()
|
||||
this.state = State.Playing
|
||||
|
|
@ -297,11 +307,12 @@ export class Player {
|
|||
}
|
||||
}
|
||||
|
||||
private _cacheAudio(audio: string) {
|
||||
private async _cacheAudio(audio: string) {
|
||||
if (audio.includes(appName.toLowerCase()) || !window.ipcRenderer) return
|
||||
const id = Number(new URL(audio).searchParams.get('dash-id'))
|
||||
if (isNaN(id) || !id) return
|
||||
cacheAudio(id, audio)
|
||||
const response = await fetchAudioSourceWithReactQuery({ id })
|
||||
cacheAudio(id, audio, response?.data?.[0]?.br)
|
||||
}
|
||||
|
||||
private async _nextFMTrack() {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,7 @@
|
|||
import axios, {
|
||||
AxiosError,
|
||||
AxiosInstance,
|
||||
AxiosRequestConfig,
|
||||
AxiosResponse,
|
||||
} from 'axios'
|
||||
import axios, { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'
|
||||
import { logout } from '../api/hooks/useUser'
|
||||
|
||||
const baseURL = String(
|
||||
import.meta.env.DEV ? '/netease' : import.meta.env.VITE_APP_NETEASE_API_URL
|
||||
)
|
||||
const baseURL = String(import.meta.env.DEV ? '/netease' : import.meta.env.VITE_APP_NETEASE_API_URL)
|
||||
|
||||
const service: AxiosInstance = axios.create({
|
||||
baseURL,
|
||||
|
|
@ -25,6 +19,12 @@ service.interceptors.response.use(
|
|||
return res
|
||||
},
|
||||
(error: AxiosError) => {
|
||||
const { response } = error
|
||||
const data = response?.data as any
|
||||
if (data?.code === 301 && data?.message === '未登录') {
|
||||
console.log('未登录')
|
||||
logout()
|
||||
}
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue