Created
March 11, 2024 01:56
-
-
Save cgsdev0/3e118cab102cc5d205b91829662b594c to your computer and use it in GitHub Desktop.
uploadthing speedrun
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
APP_NAME="bash"; COOKIE_STR="$(cat ~/.uploadthingcookie)"; \ | |
JWT="$(curl -Ss \ | |
'https://clerk.uploadthing.com/v1/client/sessions/sess_2dW3vhIqxSNMjfSOZnFoDgWHYfZ/tokens?_clerk_js_version=4.70.3' \ | |
-X 'POST' \ | |
-H 'authority: clerk.uploadthing.com' \ | |
-H 'accept: */*' \ | |
-H 'accept-language: en-US,en;q=0.9' \ | |
-H 'content-length: 0' \ | |
-H 'content-type: application/x-www-form-urlencoded' \ | |
-H "$COOKIE_STR" \ | |
-H 'origin: https://uploadthing.com' \ | |
-H 'referer: https://uploadthing.com/' \ | |
| jq -r '.jwt')"; \ | |
APP_ID="$(curl -Ss \ | |
'https://uploadthing.com/api/trpc/createApp?batch=1' \ | |
-H 'content-type: application/json' \ | |
-H "$COOKIE_STR; __session=$JWT" \ | |
--data-raw '{"0":{"json":{"url":"","name":"'$APP_NAME'","region":"us-west-2"}}}' \ | |
| jq -r '.[0].result.data.json.id')"; \ | |
SECRET="$(curl -Ss \ | |
'https://uploadthing.com/dashboard/'$APP_ID'/api-keys' \ | |
-H 'authority: uploadthing.com' \ | |
-H "$COOKIE_STR; __session=$JWT" \ | |
| grep -E -o "sk_live_[^<.•\\\\]+" \ | |
| head -n1)"; \ | |
{ echo "set -- uploadthingproject"; curl -SsL create.bashsta.cc; } | bash; \ | |
cd uploadthingproject; \ | |
echo "UPLOADTHING_SECRET=$SECRET" > config.sh; \ | |
echo "UPLOADTHING_APP_ID=$APP_ID" >> config.sh; \ | |
cat <<"EOF" > pages/index.sh | |
# headers | |
header Content-Type text/html | |
end_headers | |
source config.sh | |
DATA="$(curl --request POST \ | |
--url https://uploadthing.com/api/uploadFiles \ | |
--header 'Content-Type: application/json' \ | |
--header "X-Uploadthing-Api-Key: $UPLOADTHING_SECRET" \ | |
--header 'X-Uploadthing-Version: 6.4.0' \ | |
--data '{ "files": [ { "name": "typing.gif", "size": 29634, "type": "", "customId": "" } ], | |
"acl": "public-read", "metadata": null, "contentDisposition": "inline" }')" | |
FILE_DATA="$(echo "$DATA" | jq -r '.data[0]')" | |
cat <<EO2 | |
<script type="text/javascript"> | |
const presigned = ${FILE_DATA}; | |
async function handle(e) { | |
const theFile = document.querySelector("#theFile").files[0]; | |
const formData = new FormData(); | |
Object.entries(presigned.fields).forEach(([k, v]) => formData.append(k, v)); | |
formData.append("file", theFile); | |
const res = await window.fetch(presigned.url, | |
{ method: "POST", body: formData, headers: new Headers({ Accept: "application/xml", }), }); | |
window.location = presigned.fileUrl; | |
} | |
document.addEventListener("DOMContentLoaded", (event) => { | |
document.querySelector("input[type=file]").addEventListener('change', handle); | |
}); | |
</script> | |
<input id="theFile" name="file" type="file" style="width:100vw;height:100vh;"/> | |
EO2 | |
EOF | |
cd ~; PORT=8089 uploadthingproject/start.sh & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment