fix: get file url

This commit is contained in:
Xmader 2020-10-21 10:51:40 -04:00
parent 8165dd3787
commit 6f60cd8b38
1 changed files with 14 additions and 19 deletions

View File

@ -2,13 +2,13 @@
import scoreinfo from './scoreinfo' import scoreinfo from './scoreinfo'
const AUTH_MODULE_ID = 'FNf8' const FILE_URL_MODULE_ID = 'iNJA'
type FileType = 'img' | 'mp3' | 'midi' type FileType = 'img' | 'mp3' | 'midi'
const getApiUrl = (type: FileType, index: number): string => { const getApiUrl = (id: number, type: FileType, index: number): string => {
// proxy // proxy
return `https://musescore.now.sh/api/jmuse?id=${scoreinfo.id}&type=${type}&index=${index}` return `https://musescore.now.sh/api/jmuse?id=${id}&type=${type}&index=${index}`
} }
interface Module { interface Module {
@ -53,28 +53,23 @@ const webpackHook = (moduleId: string, moduleOverrides: { [id: string]: Module }
return t(moduleId) return t(moduleId)
} }
const getApiAuth = (type: FileType, index: number): string => { export const getFileUrl = async (type: FileType, index = 0): Promise<string> => {
const authModule = webpackHook(AUTH_MODULE_ID, { const fileUrlModule = webpackHook(FILE_URL_MODULE_ID, {
'6Ulw' (_, r, t) { // override '6Ulw' (_, r, t) { // override
t.d(r, 'a', () => { t.d(r, 'a', () => {
return type return type
}) })
}, },
}) 'VSrV' (_, r, t) { // override
const fn: (id: number, type: string, index: number) => string = authModule.a() t.d(r, 'b', () => {
return fn(scoreinfo.id, type, index) return getApiUrl
} })
export const getFileUrl = async (type: FileType, index = 0): Promise<string> => {
const url = getApiUrl(type, index)
const auth = getApiAuth(type, index)
const r = await fetch(url, {
headers: {
Authorization: auth,
}, },
}) })
const { info } = await r.json() const fn: (id: number, index: number, cb: (url: string) => any) => string = fileUrlModule.default
return info.url as string
return new Promise((resolve) => {
return fn(scoreinfo.id, index, resolve)
})
} }