2020-10-18 11:21:25 +00:00
|
|
|
|
|
|
|
import scoreinfo from './scoreinfo'
|
2020-10-21 14:58:24 +00:00
|
|
|
import { webpackHook } from './webpack-hook'
|
2020-10-18 11:21:25 +00:00
|
|
|
|
2020-10-21 14:51:40 +00:00
|
|
|
const FILE_URL_MODULE_ID = 'iNJA'
|
2020-10-18 11:21:25 +00:00
|
|
|
|
|
|
|
type FileType = 'img' | 'mp3' | 'midi'
|
|
|
|
|
2020-10-21 14:51:40 +00:00
|
|
|
const getApiUrl = (id: number, type: FileType, index: number): string => {
|
2020-10-18 11:21:25 +00:00
|
|
|
// proxy
|
2020-10-21 14:51:40 +00:00
|
|
|
return `https://musescore.now.sh/api/jmuse?id=${id}&type=${type}&index=${index}`
|
2020-10-18 11:21:25 +00:00
|
|
|
}
|
|
|
|
|
2020-10-21 14:51:40 +00:00
|
|
|
export const getFileUrl = async (type: FileType, index = 0): Promise<string> => {
|
|
|
|
const fileUrlModule = webpackHook(FILE_URL_MODULE_ID, {
|
2020-10-21 14:39:28 +00:00
|
|
|
'6Ulw' (_, r, t) { // override
|
|
|
|
t.d(r, 'a', () => {
|
|
|
|
return type
|
|
|
|
})
|
|
|
|
},
|
2020-10-21 14:51:40 +00:00
|
|
|
'VSrV' (_, r, t) { // override
|
|
|
|
t.d(r, 'b', () => {
|
|
|
|
return getApiUrl
|
|
|
|
})
|
|
|
|
},
|
2020-10-21 14:39:28 +00:00
|
|
|
})
|
2020-10-18 11:21:25 +00:00
|
|
|
|
2020-10-21 14:51:40 +00:00
|
|
|
const fn: (id: number, index: number, cb: (url: string) => any) => string = fileUrlModule.default
|
2020-10-18 11:21:25 +00:00
|
|
|
|
2020-10-21 14:51:40 +00:00
|
|
|
return new Promise((resolve) => {
|
|
|
|
return fn(scoreinfo.id, index, resolve)
|
2020-10-18 11:21:25 +00:00
|
|
|
})
|
|
|
|
}
|