fix image upload
visual improvements
This commit is contained in:
parent
94c1e0b679
commit
fe5d77443d
7 changed files with 134 additions and 24 deletions
|
|
@ -10,7 +10,7 @@
|
|||
<div class="flex-none gap-2">
|
||||
<a class="btn btn-ghost" href="/admin/pages">Pages</a>
|
||||
<a class="btn btn-ghost" href="/admin/globals">Globals</a>
|
||||
<form method="POST" action="/admin/login?/logout">
|
||||
<form class="inline" method="POST" action="/admin/login?/logout">
|
||||
<button class="btn btn-outline" type="submit">Logout</button>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
|||
27
app/src/routes/admin/api/upload/+server.ts
Normal file
27
app/src/routes/admin/api/upload/+server.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { env } from '$env/dynamic/public';
|
||||
import { error, json } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from './$types';
|
||||
|
||||
export const POST: RequestHandler = async ({ request, locals }) => {
|
||||
const formData = await request.formData();
|
||||
const file = formData.get('file') as File | null;
|
||||
const alt = formData.get('alt') as string | null;
|
||||
|
||||
if (!file) {
|
||||
throw error(400, 'No file provided');
|
||||
}
|
||||
|
||||
const uploadForm = new FormData();
|
||||
uploadForm.append('file', file);
|
||||
if (alt) uploadForm.append('alt', alt);
|
||||
|
||||
try {
|
||||
const record = await locals.pb.collection('media').create(uploadForm);
|
||||
const publicUrl = env.PUBLIC_POCKETBASE_URL || 'http://localhost:8090';
|
||||
const url = `${publicUrl}/api/files/${record.collectionId}/${record.id}/${record.file}`;
|
||||
return json({ record, url });
|
||||
} catch (e) {
|
||||
console.error('Media upload error:', e);
|
||||
throw error(500, 'Upload failed');
|
||||
}
|
||||
};
|
||||
|
|
@ -42,7 +42,10 @@
|
|||
<input type="hidden" name="data" value={JSON.stringify(footer)} />
|
||||
<h2 class="mb-4 text-2xl font-bold">Footer</h2>
|
||||
{#each ['businessName', 'tagline', 'address', 'phone', 'email', 'copyrightText'] as field}
|
||||
<label class="form-control"><span class="label-text">{field}</span><input class="input input-bordered" bind:value={footer[field]} /></label>
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">{field}</span></div>
|
||||
<input class="input input-bordered w-full" bind:value={footer[field]} />
|
||||
</label>
|
||||
{/each}
|
||||
<h3 class="mt-6 font-bold">Social links</h3>
|
||||
{#each footer.socialLinks || [] as link, i}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue