fix: auth magics
This commit is contained in:
parent
0e96b9dc08
commit
06b7bda575
1 changed files with 30 additions and 9 deletions
39
src/file.ts
39
src/file.ts
|
@ -5,24 +5,45 @@ import { onPackLoad, webpackContext } from './webpack-hook'
|
|||
|
||||
type FileType = 'img' | 'mp3' | 'midi'
|
||||
|
||||
const AUTH_REG = /,(function\(\)\{var \w=Array.prototype.slice.*?)\)\[/
|
||||
enum PACK_ID {
|
||||
img = 'F/w+',
|
||||
midi = 'yihj',
|
||||
mp3 = '2oYV',
|
||||
}
|
||||
const AUTH_REG = /,((\d+\.\..+?)?function\(\)\{var \w=Array.prototype.slice.*?)\)(\[|\.then)/
|
||||
const PACK_ID_REG = /\((\{.*?"\})\[\w\]\|\|\w\)/
|
||||
const packIdPromise: Promise<Record<FileType, (string | number)>> = webpackContext.then((ctx) => {
|
||||
const ids = {
|
||||
img: '9',
|
||||
midi: '',
|
||||
mp3: '',
|
||||
}
|
||||
|
||||
try {
|
||||
const fn = ctx.e.toString()
|
||||
const packsData = fn.match(PACK_ID_REG)[1] as string
|
||||
// eslint-disable-next-line no-new-func, @typescript-eslint/no-implied-eval
|
||||
const packs = Function(`return (${packsData})`)() as { [id: string]: string }
|
||||
|
||||
Object.entries(packs).forEach(([id, name]) => {
|
||||
if (name.includes('audio') && !ids['mp3']) ids['mp3'] = id
|
||||
if (name.includes('piano_roll') && !ids['midi']) ids['midi'] = id
|
||||
})
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
|
||||
return ids
|
||||
})
|
||||
|
||||
/**
|
||||
* I know this is super hacky.
|
||||
*/
|
||||
const magicHookConstr = (type: FileType) => {
|
||||
const magicHookConstr = async (type: FileType) => {
|
||||
const packId = await packIdPromise
|
||||
|
||||
// request pack
|
||||
// eslint-disable-next-line no-void, @typescript-eslint/no-unsafe-return
|
||||
void webpackContext.then((ctx) => ctx.e(PACK_ID[type]))
|
||||
void webpackContext.then((ctx) => ctx.e(packId[type]))
|
||||
|
||||
return new Promise<string>((resolve) => {
|
||||
onPackLoad((pack) => {
|
||||
if (pack[0].includes(PACK_ID[type])) {
|
||||
if (pack[0].includes(packId[type]) || pack[0].includes(+packId[type])) {
|
||||
Object.values(pack[1]).forEach((mod) => {
|
||||
const m = mod.toString().match(AUTH_REG)
|
||||
if (m) {
|
||||
|
|
Loading…
Reference in a new issue