• she/her

queer code witch - 18
discord @‍mintexists
send me asks! :3


boobs
I'm not convinced that this needs to be a link?
Yea no
it doesnt
i wonder if
**markdown** formatting *works* no it doesnt thats sad

theres an option to extract the source maps that needs a certain npm package installed, and theres an option to list all the trpc api endpoints.

a helpful file to check out for anyone interested in the api is sitemap.ts because it contains all the /api/v1 endpoints and what data they take.

also heads up i am not a lawyer, i am not telling you to use this to do anything malicious or against TOS! the only cybercrimes i commit are css crimes

sorry that the code is a bit of a mess, it was made for just me to use at first but i figured sharing anything is better than sharing nothing

// run this file with `deno run --allow-net --allow-write --allow-run main.js`
// write to files then extract with shuji
// this needs to have a specific branch of shuji installed 
// this can be done with `npm install mazamachi/shuji#add-preserve-option -g`

const extract = true
const listTRPCEndpoints = false

if (extract) {
    try {
        await Deno.remove('static', { recursive: true });
    }
    catch (e) {
        undefined
        //console.log(e)
    }
}

const rootUrl = 'https://cohost.org/'

// get the runtime.*.js url
const html = await fetch(rootUrl).then(res => res.text())
// console.log(html)
const runtimeUrlRE = /static\/runtime\.\S{20}\.js/gm
const runtimeUrl = html.match(runtimeUrlRE)[0]

const clientUrlRe = /static\/client\.\S{20}\.js/gm
const clientUrl = html.match(clientUrlRe)[0]

// console.log(runtimeUrl)

// get the webpack chunk info from runtime.*.js
// console.log(rootUrl + runtimeUrl)
const runtime = await fetch(rootUrl + runtimeUrl).then(res => res.text())
// console.log(runtime)
const webpackChunkInfoRE = /function\(\w+\){return\((.*?}).*({.*}).*\+"\.js"}/gm
const webpackChunkInfoRaw = webpackChunkInfoRE.exec(runtime)
// console.log(webpackChunkInfoRaw)
const prefixes = (new Function(`return ${webpackChunkInfoRaw[1]}`))()
const suffixes = (new Function(`return ${webpackChunkInfoRaw[2]}`))()

// combine the prefixes and suffixes to get the webpack chunk urls
const ids = Object.keys(suffixes)
const webpackChunkUrls = ids.map(id => {
    const prefix = prefixes[id] || id
    const suffix = suffixes[id]
    return `static/${prefix}.${suffix}.js`
})

webpackChunkUrls.push(clientUrl)

// get the webpack chunk contents
// const webpackChunkContents = await Promise.all(webpackChunkUrls.map(url => fetch(rootUrl + url).then(res => res.text())))

// get the sourcemap urls
const sourcemapUrls = webpackChunkUrls.map(url => url + '.map')

// get the sourcemap contents
const sourcemapContents = (await Promise.all(sourcemapUrls.map(url => fetch(rootUrl + url).then(res => res.json()))))

if (extract) {
    for (let i = 0; i < sourcemapUrls.length; i++) {
        const url = sourcemapUrls[i]
        const contentRaw = sourcemapContents[i]
        contentRaw.sources = contentRaw.sources.map(path => {
            if (path.startsWith('webpack://')) return path.split('webpack://').at(-1)
            return path
        })
        const content = JSON.stringify(contentRaw)
        // console.log(url.split("/").slice(0, -1).join(''))
        await Deno.mkdir(url.split("/").slice(0, -1).join(''), { recursive: true })
        try {
            await Deno.writeTextFile(`${url}`, content, { create: true })
        }
        catch (e) {
            console.log(e)
        }

        // const p = Deno.run({
        //     cmd: ['shuji', '-p', '-o', 'cohost', 'static'],
        //     // stdout: 'piped',
        //     // stderr: 'piped',
        // })

        // console.log(await p.status())
        // console.log(await p.output())

    }

    await Deno.remove('cohost', { recursive: true });

    const p = Deno.run({
        cmd: ['shuji', '-p', '-o', 'cohost', 'static'],
        // stdout: 'piped',
        // stderr: 'piped',
    })

    console.log(await p.status())
}

if (listTRPCEndpoints) {
    const sourceMapTextContents  = sourcemapContents.map(s => s.sourcesContent.join('\n'))

    // console.log(sourcemapContents)
    const re = /(trpc\.(\S+\.)+?use(Query|Mutation)|trpcLegacy\.use(Query|Mutation)[\S\s]*?"[\S\s]*?")/gm
    const matches = []
    for (const sourcemapContent of sourceMapTextContents) {
        let match;
        while ((match = re.exec(sourcemapContent)) !== null) {
            matches.push(match)
        }
    }

    let out = matches.map(m => m[0])
    // remove duplicates
    out = [...new Set(out)].sort()
    console.log(out)
    console.log(JSON.stringify(out, null, 2))
}

You must log in to comment.

in reply to @mintexists's post:

Pinned Tags