musescore-downloader/src/file.ts

34 lines
863 B
TypeScript
Raw Normal View History

import scoreinfo from './scoreinfo'
2020-10-21 14:58:24 +00:00
import { webpackHook } from './webpack-hook'
2020-10-21 14:51:40 +00:00
const FILE_URL_MODULE_ID = 'iNJA'
type FileType = 'img' | 'mp3' | 'midi'
2020-10-21 14:51:40 +00:00
const getApiUrl = (id: number, type: FileType, index: number): string => {
// proxy
2020-10-21 14:51:40 +00:00
return `https://musescore.now.sh/api/jmuse?id=${id}&type=${type}&index=${index}`
}
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-21 14:51:40 +00:00
const fn: (id: number, index: number, cb: (url: string) => any) => string = fileUrlModule.default
2020-10-21 14:51:40 +00:00
return new Promise((resolve) => {
return fn(scoreinfo.id, index, resolve)
})
}