-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4910ee5
commit 11d86b8
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
Special Thanks to MubiLop with YeetYourFiles.lol for powering | ||
the Community Spotlight File Uploader! | ||
https://yeetyourfiles.lol/ | ||
*/ | ||
|
||
async function uploadFiles(mediaObj, id) { | ||
let mediaPaths = []; | ||
const allMedia = Object.values(mediaObj); | ||
for (let i = 0; i < allMedia.length; i++) { | ||
const json = await uploadFile(allMedia[i].d, id, i); | ||
if (json) mediaPaths.push({ t: allMedia[i].t, id: json.fileId, url: json.fileUrl }); | ||
} | ||
return mediaPaths; | ||
} | ||
|
||
async function uploadFile(base64, id, i) { | ||
const fileName = `CSpotlight-Media-${id}${i}}.txt`; | ||
|
||
const byteChars = atob(base64); | ||
const byteNums = new Array(byteChars.length); | ||
for (let i = 0; i < byteChars.length; i++) { byteNums[i] = byteChars.charCodeAt(i) } | ||
const byteArray = new Uint8Array(byteNums); | ||
const blob = new Blob([byteArray], { type: "text/plain" }); | ||
|
||
const formData = new FormData(); | ||
formData.append("file", blob, fileName); | ||
return fetch("https://yeetyourfiles.lol/api/upload", { method: "POST", body: formData }) | ||
.then(response => response.json()) | ||
.then(data => { | ||
return JSON.stringify(data); | ||
}) | ||
.catch(e => { | ||
console.warn("POST ERROR:", e); | ||
return undefined; | ||
}); | ||
} |