Skip to content

Commit

Permalink
Update startup.js
Browse files Browse the repository at this point in the history
  • Loading branch information
SharkPool-SP authored Dec 22, 2024
1 parent 8a50623 commit 5b91fbe
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions scripts/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,22 @@ function generateDate() {
return `${d.getMonth() + 1}/${d.getDate()}/${d.getFullYear()} ${hr}:${min}`;
}

function constructPost() {
async function constructPost() {
const id = generateID(), date = generateDate();

// compress data
const fixedTags = btoa(uploadData.tags.join(","));
const fixedName = btoa(uploadData.name);
const fixedUrl = btoa(uploadData.url);

// send media to file servers
let fixedMedia = await uploadFiles(uploadData.media, id);
fixedMedia = JSON.stringify(fixedMedia);

let url = "https://script.google.com/macros/s/AKfycbwb49wDXQjOBxtGfjg-bpyMXckewOntlqIyqZejA8MkEUu7I7juDctKLbMXrf6IBjUc-w/exec?gid=0";
url += `&upload-id=${encodeURIComponent(generateID())}&date=${encodeURIComponent(generateDate())}`;
url += `&product-name=${encodeURIComponent(uploadData.name)}&product-url=${encodeURIComponent(uploadData.url)}`;
url += `&tags=${encodeURIComponent(JSON.stringify(uploadData.tags))}&media=${encodeURIComponent(JSON.stringify(Object.values(uploadData.media)))}`;
url += `&upload-id=${encodeURIComponent(id)}&date=${encodeURIComponent(date)}`;
url += `&product-name=${encodeURIComponent(fixedName)}&product-url=${encodeURIComponent(fixedUrl)}`;
url += `&tags=${encodeURIComponent(fixedTags)}&media=${encodeURIComponent(fixedMedia)}`;
url += `&opt-ping-id=${uploadData.optID || "0"}`;
return url;
}
Expand Down Expand Up @@ -413,7 +424,7 @@ function compressSVG(svg) {
.replace(/>\s+</g, "><").replace(/\s+$/g, "").trim();
}

document.querySelector("form").addEventListener("submit", (e) => {
document.querySelector("form").addEventListener("submit", async (e) => {
e.preventDefault();
if (Object.keys(uploadData.media).length === 0) {
const fileInp = document.querySelectorAll(`input[type="file"]`)[1];
Expand All @@ -428,8 +439,7 @@ document.querySelector("form").addEventListener("submit", (e) => {

console.log("Submitting Promotion...");
const loadScreen = showLoadingGUI();
const urlData = constructPost();
// TODO use free file hoster like catbox to send media to
const urlData = await constructPost();
fetch(urlData)
.then((r) => {
console.log("Promotion Submitted!");
Expand Down

0 comments on commit 5b91fbe

Please sign in to comment.