random login image!

This commit is contained in:
Sean Morley
2024-06-12 17:38:34 +00:00
parent 20b6f826d9
commit 6385f9f46b
11 changed files with 646 additions and 20 deletions

View File

@@ -42,15 +42,6 @@ export const actions: Actions = {
};
}
// if (icon.length > 1) {
// return {
// status: 400,
// body: {
// message: "Icon must be a single character",
// },
// };
// }
const usernameTaken = await db
.select()
.from(userTable)

View File

@@ -1,10 +1,4 @@
import {
error,
fail,
redirect,
type Actions,
type Handle,
} from "@sveltejs/kit";
import { error, fail, redirect, type Actions } from "@sveltejs/kit";
import type { PageServerLoad } from "./$types";
import { db } from "$lib/db/db.server";
import {
@@ -201,4 +195,29 @@ export const actions: Actions = {
return { success: true };
},
background: async (event) => {
console.log("background");
const formData = await event.request.formData();
const background = formData.get("background") as File | null;
if (!background) {
return fail(400, { message: "No background provided" });
}
if (!event.locals.user) {
return redirect(302, "/");
}
let res = await event.fetch("/api/upload", {
method: "POST",
body: background,
headers: {
bucket: "images",
type: "background",
},
});
await res.json();
console.log("Background uploaded");
if (!res.ok) {
return fail(500, { message: "Failed to upload background" });
}
return { success: true };
},
};

View File

@@ -119,6 +119,24 @@
/>
{/if}
<h2 class="text-center font-extrabold text-2xl mb-2">Background Images</h2>
<form
method="POST"
class="w-full max-w-xs"
use:enhance
action="?/background"
enctype="multipart/form-data"
>
<label for="background">Background Image</label>
<input
type="file"
name="background"
id="background"
class="block mb-2 input input-bordered w-full max-w-xs"
/>
<button type="submit" class="py-2 px-4 btn btn-primary">Upload</button>
</form>
<h2 class="text-center font-extrabold text-2xl">Admin Stats (All Users)</h2>
<div class="flex items-center justify-center mb-4">
<div class="stats stats-vertical lg:stats-horizontal shadow">