fix: get file url
This commit is contained in:
parent
d31678d3e6
commit
d2956ad9d5
2 changed files with 36 additions and 33 deletions
65
src/file.ts
65
src/file.ts
|
@ -1,11 +1,10 @@
|
||||||
/* eslint-disable no-extend-native */
|
/* eslint-disable no-extend-native */
|
||||||
|
|
||||||
import scoreinfo from './scoreinfo'
|
import scoreinfo from './scoreinfo'
|
||||||
import { webpackHook, webpackGlobalOverride, ALL } from './webpack-hook'
|
import { webpackHook, webpackGlobalOverride } from './webpack-hook'
|
||||||
|
|
||||||
const FILE_URL_MODULE_ID = 'iNJA'
|
const AUTH_MODULE_ID = 'UeBv'
|
||||||
const ARG_NUMBER = 4
|
const MAGIC_ARG_INDEX = 1
|
||||||
const MAGIC_ARG_INDEX = 3
|
|
||||||
|
|
||||||
type FileType = 'img' | 'mp3' | 'midi'
|
type FileType = 'img' | 'mp3' | 'midi'
|
||||||
|
|
||||||
|
@ -14,35 +13,23 @@ type FileType = 'img' | 'mp3' | 'midi'
|
||||||
*/
|
*/
|
||||||
let magic: Promise<string> | string = new Promise((resolve) => {
|
let magic: Promise<string> | string = new Promise((resolve) => {
|
||||||
// todo: hook module by what it does, not what it is called
|
// todo: hook module by what it does, not what it is called
|
||||||
webpackGlobalOverride(ALL, (_, r, t) => { // override
|
webpackGlobalOverride(AUTH_MODULE_ID, (n, r, t) => { // override
|
||||||
const fn = r.a
|
const fn = n.exports
|
||||||
if (typeof fn === 'function' && fn.length === ARG_NUMBER) {
|
n.exports = (...args) => {
|
||||||
t.d(r, 'a', () => {
|
if (magic instanceof Promise) {
|
||||||
return (...args) => {
|
magic = args[MAGIC_ARG_INDEX]
|
||||||
if (magic instanceof Promise) {
|
resolve(magic)
|
||||||
if (args.every(a => typeof a === 'number' || typeof a === 'string')) {
|
}
|
||||||
magic = args[MAGIC_ARG_INDEX]
|
return fn(...args) as string
|
||||||
resolve(magic)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return fn(...args) as string
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
export const getFileUrl = async (type: FileType, index = 0): Promise<string> => {
|
const getApiUrl = (type: FileType, index: number): string => {
|
||||||
const fileUrlModule = webpackHook(FILE_URL_MODULE_ID, {
|
return `/api/jmuse?id=${scoreinfo.id}&type=${type}&index=${index}`
|
||||||
'6Ulw' (_, r, t) { // override
|
}
|
||||||
t.d(r, 'a', () => {
|
|
||||||
return type
|
|
||||||
})
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const fn: (_, id: number, index: number, cb: (url: string) => any, magic: string) => string = fileUrlModule.a
|
|
||||||
|
|
||||||
|
const getApiAuth = async (type: FileType, index: number): Promise<string> => {
|
||||||
if (magic instanceof Promise) {
|
if (magic instanceof Promise) {
|
||||||
// force to retrieve the MAGIC
|
// force to retrieve the MAGIC
|
||||||
const el = document.querySelectorAll('.SD7H- > button')[3] as HTMLButtonElement
|
const el = document.querySelectorAll('.SD7H- > button')[3] as HTMLButtonElement
|
||||||
|
@ -50,7 +37,23 @@ export const getFileUrl = async (type: FileType, index = 0): Promise<string> =>
|
||||||
magic = await magic
|
magic = await magic
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
const str = String(scoreinfo.id) + type + String(index)
|
||||||
return fn(undefined, scoreinfo.id, index, resolve, magic as string)
|
|
||||||
})
|
const fn: (str: string, magic: string) => string = webpackHook(AUTH_MODULE_ID)
|
||||||
|
|
||||||
|
return fn(str, magic)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getFileUrl = async (type: FileType, index = 0): Promise<string> => {
|
||||||
|
const url = getApiUrl(type, index)
|
||||||
|
const auth = await getApiAuth(type, index)
|
||||||
|
|
||||||
|
const r = await fetch(url, {
|
||||||
|
headers: {
|
||||||
|
Authorization: auth,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const { info } = await r.json()
|
||||||
|
return info.url as string
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
import { hookNative } from './anti-detection'
|
import { hookNative } from './anti-detection'
|
||||||
|
|
||||||
const CHUNK_PUSH_FN = 'function a(a){'
|
const CHUNK_PUSH_FN = /^function [^r]\(\w\){/
|
||||||
|
|
||||||
interface Module {
|
interface Module {
|
||||||
(module, exports, __webpack_require__): void;
|
(module, exports, __webpack_require__): void;
|
||||||
|
@ -88,7 +88,7 @@ export const webpackGlobalOverride = (() => {
|
||||||
get () { return jsonp },
|
get () { return jsonp },
|
||||||
set (v: WebpackJson) {
|
set (v: WebpackJson) {
|
||||||
jsonp = v
|
jsonp = v
|
||||||
if (!hooked && v.push.toString().includes(CHUNK_PUSH_FN)) {
|
if (!hooked && v.push.toString().match(CHUNK_PUSH_FN)) {
|
||||||
hooked = true
|
hooked = true
|
||||||
hookNative(v, 'push', (_fn) => {
|
hookNative(v, 'push', (_fn) => {
|
||||||
return function (pack) {
|
return function (pack) {
|
||||||
|
|
Loading…
Reference in a new issue