you can now upload the img and vids and you get a url for it ill implement seeing that img and vid latter
This commit is contained in:
parent
f1675d0c6b
commit
5f53e923d0
3 changed files with 36 additions and 3 deletions
|
@ -3,9 +3,12 @@
|
||||||
import GenerateOptionsUsingAI from "../buttons/GenerateOptionsUsingAI.svelte";
|
import GenerateOptionsUsingAI from "../buttons/GenerateOptionsUsingAI.svelte";
|
||||||
import Answers from "./answers.svelte";
|
import Answers from "./answers.svelte";
|
||||||
import { questions } from "../../logic/GameCreateData.svelte.js";
|
import { questions } from "../../logic/GameCreateData.svelte.js";
|
||||||
|
import { UpLoadFiles } from "../../logic/UpLoadFiles.js";
|
||||||
|
|
||||||
let props = $props();
|
let props = $props();
|
||||||
let index = props.index;
|
let index = props.index;
|
||||||
|
|
||||||
|
let files;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex items-center gap-3">
|
<div class="flex items-center gap-3">
|
||||||
|
@ -50,5 +53,6 @@
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
<GenerateOptionsUsingAI {index} />
|
<GenerateOptionsUsingAI {index} />
|
||||||
|
<input type="file" onchange={() => UpLoadFiles(files[0])} bind:files accept="image/*,video/*" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import { DefaultQuestions } from "$lib/config.js";
|
import { DefaultQuestions } from "$lib/config.js";
|
||||||
|
|
||||||
export let Wait = $state({
|
export let Wait = $state({ v: false });
|
||||||
v: false,
|
|
||||||
});
|
|
||||||
export let questions = $state({
|
export let questions = $state({
|
||||||
v: [
|
v: [
|
||||||
{
|
{
|
||||||
|
|
31
src/routes/kahootclone/create/logic/UpLoadFiles.js
Normal file
31
src/routes/kahootclone/create/logic/UpLoadFiles.js
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
import toast from "svelte-5-french-toast";
|
||||||
|
import { supabase } from "$lib/supabase.js";
|
||||||
|
|
||||||
|
export async function UpLoadFiles(file) {
|
||||||
|
if (!file) {
|
||||||
|
toast.error("Please select a file to upload first.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fileExt = file.name.split(".").pop();
|
||||||
|
const fileName = `${Date.now()}.${fileExt}`;
|
||||||
|
const filePath = `${fileName}`;
|
||||||
|
|
||||||
|
const uploadPromise = supabase.storage.from("useruploadedcontent").upload(filePath, file);
|
||||||
|
|
||||||
|
const result = await toast.promise(uploadPromise, {
|
||||||
|
loading: "Uploading...",
|
||||||
|
success: "Upload successful!",
|
||||||
|
error: (error) => `Upload failed. ${error.message} Please try again.`,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result.error) {
|
||||||
|
console.error("Upload error:", result.error.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve public URL
|
||||||
|
const { data: publicData } = supabase.storage.from("useruploadedcontent").getPublicUrl(filePath);
|
||||||
|
|
||||||
|
toast.success(publicData.publicUrl);
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue