Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
add api route to return image
Browse files
entrypoint.sh
CHANGED
@@ -1,8 +1,6 @@
|
|
1 |
#!/bin/bash
|
2 |
npx prisma generate &&
|
3 |
npm run build &&
|
4 |
-
# mkdir -p ./static/data && ln -s /data/uploads ./static/data/uploads
|
5 |
-
ln -s /data/uploads ./build/client/uploads &&
|
6 |
npx prisma generate &&
|
7 |
npx prisma migrate deploy &&
|
8 |
npx prisma db push &&
|
|
|
1 |
#!/bin/bash
|
2 |
npx prisma generate &&
|
3 |
npm run build &&
|
|
|
|
|
4 |
npx prisma generate &&
|
5 |
npx prisma migrate deploy &&
|
6 |
npx prisma db push &&
|
src/lib/components/community/Card.svelte
CHANGED
@@ -45,7 +45,7 @@
|
|
45 |
on:click={handleClick}
|
46 |
>
|
47 |
<div class="w-full h-full absolute top-0 left-0 -z-[1] rounded-xl overflow-hidden" class:!brightness-50={loading}>
|
48 |
-
<
|
49 |
</div>
|
50 |
<div class="group-hover:opacity-100 opacity-0 translate-y-full group-hover:translate-y-0 transition-all duration-200 flex flex-col gap-4 w-full">
|
51 |
<div class="bg-black/40 backdrop-blur-sm border border-white/30 rounded-lg px-6 py-3 text-white transition-all duration-200 w-full">
|
|
|
45 |
on:click={handleClick}
|
46 |
>
|
47 |
<div class="w-full h-full absolute top-0 left-0 -z-[1] rounded-xl overflow-hidden" class:!brightness-50={loading}>
|
48 |
+
<img class="w-full h-full bg-center bg-cover transition-all duration-200 group-hover:scale-110" src="/api/images/{card.image}" alt="{card.prompt}" />
|
49 |
</div>
|
50 |
<div class="group-hover:opacity-100 opacity-0 translate-y-full group-hover:translate-y-0 transition-all duration-200 flex flex-col gap-4 w-full">
|
51 |
<div class="bg-black/40 backdrop-blur-sm border border-white/30 rounded-lg px-6 py-3 text-white transition-all duration-200 w-full">
|
src/lib/components/community/viewer/Viewer.svelte
CHANGED
@@ -69,7 +69,7 @@
|
|
69 |
use:clickoutside on:clickoutside={handleClose}
|
70 |
>
|
71 |
{#if gallery?.id}
|
72 |
-
<img src=
|
73 |
<div class="flex flex-col justify-between w-full overflow-auto flex-1">
|
74 |
<div class="w-full p-6">
|
75 |
<header class="w-full flex items-start justify-between px-2 pt-2">
|
|
|
69 |
use:clickoutside on:clickoutside={handleClose}
|
70 |
>
|
71 |
{#if gallery?.id}
|
72 |
+
<img src="/api/images/{gallery?.image}" alt={gallery?.prompt} class="w-full object-cover h-[200px] lg:h-auto" />
|
73 |
<div class="flex flex-col justify-between w-full overflow-auto flex-1">
|
74 |
<div class="w-full p-6">
|
75 |
<header class="w-full flex items-start justify-between px-2 pt-2">
|
src/routes/api/images/[id]/+server.ts
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { json, type RequestEvent } from '@sveltejs/kit';
|
2 |
+
import { promises } from 'fs';
|
3 |
+
import { env } from '$env/dynamic/public';
|
4 |
+
|
5 |
+
import prisma from '$lib/prisma';
|
6 |
+
|
7 |
+
/** @type {import('./$types').RequestHandler} */
|
8 |
+
|
9 |
+
export async function GET({ params } : RequestEvent) {
|
10 |
+
const id = params.id;
|
11 |
+
const gallery = await prisma.gallery.findFirst({
|
12 |
+
where: {
|
13 |
+
image: id,
|
14 |
+
},
|
15 |
+
select: {
|
16 |
+
image: true,
|
17 |
+
}
|
18 |
+
})
|
19 |
+
|
20 |
+
if (!gallery) {
|
21 |
+
return json({
|
22 |
+
error: {
|
23 |
+
token: "Gallery not found"
|
24 |
+
}
|
25 |
+
}, { status: 404 })
|
26 |
+
}
|
27 |
+
|
28 |
+
const file = await promises.readFile(`${env.PUBLIC_FILE_UPLOAD_DIR}/${gallery.image}`)
|
29 |
+
return new Response(file, {
|
30 |
+
headers: {
|
31 |
+
'Content-Type': 'image/png',
|
32 |
+
},
|
33 |
+
})
|
34 |
+
}
|
vite.config.ts
CHANGED
@@ -7,10 +7,10 @@ export default defineConfig({
|
|
7 |
enhancedImages(),
|
8 |
sveltekit(),
|
9 |
],
|
10 |
-
server: {
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
}
|
16 |
});
|
|
|
7 |
enhancedImages(),
|
8 |
sveltekit(),
|
9 |
],
|
10 |
+
// server: {
|
11 |
+
// fs: {
|
12 |
+
// strict: false,
|
13 |
+
// allow: [".."],
|
14 |
+
// },
|
15 |
+
// }
|
16 |
});
|