diff --git a/src/IntroDownloader.svelte b/src/IntroDownloader.svelte
index cc29fe7..2552262 100644
--- a/src/IntroDownloader.svelte
+++ b/src/IntroDownloader.svelte
@@ -2,12 +2,15 @@
import { intros, member } from './store.ts';
import { member_can, Permission } from './permissions.ts';
import { onMount } from 'svelte';
+ import { uploadIntro } from './api.js';
let enteredUrl = '';
let enteredTitle = '';
+ let selectedFile = null;
let selectedGuild = null;
let canDownloadAny = false;
let downloadPromise = null;
+ let uploadPromise = null;
let allowedGuildList = [];
$: allowedGuildList = $member.guilds
@@ -26,6 +29,18 @@
}
};
+
+ const upload = () => {
+ // TODO: limit to 1 file
+ if (!!selectedGuild) {
+ uploadPromise = (async () => {
+ await uploadIntro(selectedGuild.id, enteredTitle, selectedFile[0], $member.token);
+ await intros.fetchIntros($member.guilds);
+ })();
+ } else {
+
+ }
+ }
{#if canDownloadAny}
@@ -53,6 +68,29 @@
{/if}
+
+
Upload New Intro
+ {#if !!uploadPromise}
+ {#await uploadPromise}
+
uploading...
+ {:then result}
+
Uploaded
+
+ {:catch err}
+
{err}
+
+ {/await}
+ {:else}
+
+
+
+
+ {/if}
+
{/if}
@@ -60,11 +98,13 @@
div {
display: flex;
width: 85%;
+ height: 85%;
flex-direction: column;
align-items: center;
background-color: #2a2a4a;
padding: 1.5em;
box-shadow: 1px 3px 4px 1px #1f1f36;
+ margin: 0.5em;
}
h3 {
diff --git a/src/api.js b/src/api.js
index 080365b..fe28c8c 100644
--- a/src/api.js
+++ b/src/api.js
@@ -1,6 +1,6 @@
import { env } from '$env/dynamic/public';
-export const apiCall = async (method, endpoint, token) => {
+export const apiCall = async (method, endpoint, token, body) => {
const headers = (() => {
if (!!token) {
return { 'token': token };
@@ -12,7 +12,7 @@ export const apiCall = async (method, endpoint, token) => {
return (await
fetch(
`${env.PUBLIC_API_URL}/${endpoint}`,
- { method: method, headers: headers })
+ { method: method, headers: headers, body: body })
);
};
@@ -44,3 +44,7 @@ export const removeIntro = async (guild, channel, selectedIntros, token) => {
await apiCall('POST', `intros/${guild}/${channel}/${intro}/remove`, token);
}
};
+
+export const uploadIntro = async (guild, name, file, token) => {
+ await apiCall('POST', `intros/${guild}/upload?name=${encodeURIComponent(name)}`, token, file);
+}
diff --git a/src/app.html b/src/app.html
index d6926b0..07fa285 100644
--- a/src/app.html
+++ b/src/app.html
@@ -4,6 +4,7 @@
+ MemeJoin - Dashboard
%sveltekit.head%