Skip to content

Commit

Permalink
We can now video and file upload woooo
Browse files Browse the repository at this point in the history
  • Loading branch information
LarveyOfficial committed May 3, 2023
1 parent c5656b5 commit 365560c
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions src/pages/panel/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,28 +87,17 @@ export function Home() {
};

const handleFormUpload = (e: any) => {
console.log(formUpload);
setFormUpload(e.target.files[0]);
setFormUploading(true);
};

const uploadToImgur = async () => {
const uploadToSpace = async () => {
const formData = new FormData();
const auth = "Client-ID " + process.env.NEXT_PUBLIC_IMGURID;
const auth = "" + process.env.NEXT_PUBLIC_TIXTEAPI;

if (formUpload) {
console.log(formUpload);
if ((formUpload as any)["type"].includes("video")) {
formData.append("video", formUpload!);
formData.append("disable_audio", "1");
} else if ((formUpload as any)["type"].includes("image")) {
formData.append("image", formUpload!);
} else {
return "failed";
}
formData.append("type", "file");

const res = await fetch("https://api.imgur.com/3/image/", {
formData.append("file", formUpload!);
const res = await fetch("https://api.tixte.com/v1/upload?random=true", {
method: "POST",
headers: {
Authorization: auth,
Expand All @@ -120,8 +109,7 @@ export function Home() {
if (data.success == false) {
return "failed";
}
console.log(data);
return data.data.link;
return data.data.direct_url;
} else {
return "failed";
}
Expand All @@ -132,7 +120,7 @@ export function Home() {
let data;
event.preventDefault();
if (formUploading) {
const newUrl = await uploadToImgur();
const newUrl = await uploadToSpace();
if (newUrl == "failed") {
setFormSuccessCode(403);
return;
Expand Down Expand Up @@ -192,6 +180,15 @@ export function Home() {
url: "",
});
setFormSuccessCode(200);
setFormUploading(false);
setFormUpload("" as any);
var oldInput = document.getElementById("formUploadFile");
var newInput = document.createElement("input");
newInput.type = "file";
newInput.id = oldInput!.id;
newInput.className = oldInput!.className;
newInput.onchange = handleFormUpload;
oldInput!.parentNode!.replaceChild(newInput, oldInput!);
await delay(2000);
setFormSuccessCode(418);
} else {
Expand Down

0 comments on commit 365560c

Please sign in to comment.