1- import axios , { CancelTokenSource } from "axios" ;
21import { songs , currentSong } from "./controller" ;
32import { print } from "./helper" ;
3+ import ajax from "./modules/ajax" ;
44import { container as el } from "./player" ;
55
66let audio : HTMLAudioElement , mainEl : HTMLHeadingElement , subEl : HTMLHeadingElement ;
@@ -14,9 +14,9 @@ window.addEventListener("penguininitialized", () => {
1414 } ) ;
1515} ) ;
1616
17- let axiosToken : CancelTokenSource , retryTimeout : number ;
17+ let lyricReq : AjaxPromise , retryTimeout : any ;
1818
19- let lrc : Array < LyricLine > , tLrc : Array < LyricLine > , lrcOffset = 0 , tLrcOffset = 0 , lastMain : string , lastSub : string , lrcTimeout : number , subLrcTimeout : number ;
19+ let lrc : Array < LyricLine > , tLrc : Array < LyricLine > , lrcOffset = 0 , tLrcOffset = 0 , lastMain : string , lastSub : string , lrcTimeout : any , subLrcTimeout : any ;
2020
2121function findLrcPos ( lrc : Array < LyricLine > , time : number , offset = 0 ) : number {
2222 for ( let i = offset ; i < lrc . length ; i ++ ) {
@@ -63,19 +63,16 @@ export function getLyric(song: Song) {
6363 lrc = tLrc = null ;
6464 lrcOffset = tLrcOffset = 0 ;
6565 clearTimeout ( retryTimeout ) ;
66- if ( axiosToken ) { axiosToken . cancel ( "Fetch new lyric" ) ; }
67- axiosToken = axios . CancelToken . source ( ) ;
68- axios . get ( `https://gcm.tenmahw.com/resolve/lyric?id=${ song . id } ` , { cancelToken : axiosToken . token } ) . then ( ( result ) => {
66+ if ( lyricReq ) { lyricReq . cancel ( ) ; }
67+ lyricReq = ajax ( `https://gcm.tenmahw.com/resolve/lyric?id=${ song . id } ` ) . then ( ( result ) => {
6968 if ( result . data . lyric == null ) {
7069 print ( `No lyric for ${ songs [ currentSong ] . name } ` ) ;
7170 } else {
7271 lrc = result . data . lyric . lrc ;
7372 tLrc = result . data . lyric . tlrc ;
7473 }
75- } ) . catch ( ( err ) => {
76- if ( ! axios . isCancel ( err ) ) {
77- print ( "Cannot fetch lyric" ) ;
78- retryTimeout = setTimeout ( getLyric , 5000 , song ) ;
79- }
74+ } ) . catch ( ( ) => {
75+ print ( "Cannot fetch lyric" ) ;
76+ retryTimeout = setTimeout ( getLyric , 5000 , song ) ;
8077 } ) ;
8178}
0 commit comments