fix: auth magic

This commit is contained in:
Xmader 2020-11-12 13:29:10 -05:00
parent 8beb23ae69
commit e50f0e3e8e
No known key found for this signature in database
GPG Key ID: A20B97FB9EB730E4
1 changed files with 13 additions and 11 deletions

View File

@ -1,10 +1,10 @@
/* eslint-disable no-extend-native */ /* eslint-disable no-extend-native */
import scoreinfo from './scoreinfo' import scoreinfo from './scoreinfo'
import { webpackHook, webpackGlobalOverride } from './webpack-hook' import { webpackHook, webpackGlobalOverride, ALL } from './webpack-hook'
const FILE_URL_MODULE_ID = 'iNJA' const FILE_URL_MODULE_ID = 'iNJA'
const AUTH_MODULE_ID = 'F08J' const ARG_NUMBER = 4
const MAGIC_ARG_INDEX = 3 const MAGIC_ARG_INDEX = 3
type FileType = 'img' | 'mp3' | 'midi' type FileType = 'img' | 'mp3' | 'midi'
@ -14,17 +14,19 @@ 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(AUTH_MODULE_ID, (_, r, t) => { // override webpackGlobalOverride(ALL, (_, r, t) => { // override
const fn = r.a const fn = r.a
t.d(r, 'a', () => { if (typeof fn === 'function' && fn.length === ARG_NUMBER) {
return (...args) => { t.d(r, 'a', () => {
if (magic instanceof Promise) { return (...args) => {
magic = args[MAGIC_ARG_INDEX] if (magic instanceof Promise) {
resolve(magic) magic = args[MAGIC_ARG_INDEX]
resolve(magic)
}
return fn(...args) as string
} }
return fn(...args) as string })
} }
})
}) })
}) })