Spaces:
Running
Running
fix: thumbnails with svelte 5
Browse files
src/routes/assistant/[assistantId]/thumbnail.png/+server.ts
CHANGED
@@ -2,7 +2,7 @@ import ChatThumbnail from "./ChatThumbnail.svelte";
|
|
2 |
import { collections } from "$lib/server/database";
|
3 |
import { error, type RequestHandler } from "@sveltejs/kit";
|
4 |
import { ObjectId } from "mongodb";
|
5 |
-
import
|
6 |
|
7 |
import { Resvg } from "@resvg/resvg-js";
|
8 |
import satori from "satori";
|
@@ -41,16 +41,16 @@ export const GET: RequestHandler = (async ({ params }) => {
|
|
41 |
.then(async (buf) => "data:image/jpeg;base64," + buf.toString("base64"));
|
42 |
}
|
43 |
|
44 |
-
const renderedComponent = (ChatThumbnail
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
49 |
});
|
50 |
|
51 |
-
const reactLike = html(
|
52 |
-
"<style>" + renderedComponent.css.code + "</style>" + renderedComponent.html
|
53 |
-
);
|
54 |
|
55 |
const svg = await satori(reactLike, {
|
56 |
width: 1200,
|
|
|
2 |
import { collections } from "$lib/server/database";
|
3 |
import { error, type RequestHandler } from "@sveltejs/kit";
|
4 |
import { ObjectId } from "mongodb";
|
5 |
+
import { render } from "svelte/server";
|
6 |
|
7 |
import { Resvg } from "@resvg/resvg-js";
|
8 |
import satori from "satori";
|
|
|
41 |
.then(async (buf) => "data:image/jpeg;base64," + buf.toString("base64"));
|
42 |
}
|
43 |
|
44 |
+
const renderedComponent = render(ChatThumbnail, {
|
45 |
+
props: {
|
46 |
+
name: assistant.name,
|
47 |
+
description: assistant.description,
|
48 |
+
createdByName: assistant.createdByName,
|
49 |
+
avatar,
|
50 |
+
},
|
51 |
});
|
52 |
|
53 |
+
const reactLike = html("<style>" + renderedComponent.head + "</style>" + renderedComponent.body);
|
|
|
|
|
54 |
|
55 |
const svg = await satori(reactLike, {
|
56 |
width: 1200,
|
src/routes/models/[...model]/thumbnail.png/+server.ts
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
import ModelThumbnail from "./ModelThumbnail.svelte";
|
2 |
import { redirect, type RequestHandler } from "@sveltejs/kit";
|
3 |
-
import type { SvelteComponent } from "svelte";
|
4 |
|
5 |
import { Resvg } from "@resvg/resvg-js";
|
6 |
import satori from "satori";
|
@@ -10,6 +9,7 @@ import InterRegular from "$lib/server/fonts/Inter-Regular.ttf";
|
|
10 |
import InterBold from "$lib/server/fonts/Inter-Bold.ttf";
|
11 |
import { base } from "$app/paths";
|
12 |
import { models } from "$lib/server/models";
|
|
|
13 |
|
14 |
export const GET: RequestHandler = (async ({ params }) => {
|
15 |
const model = models.find(({ id }) => id === params.model);
|
@@ -17,14 +17,14 @@ export const GET: RequestHandler = (async ({ params }) => {
|
|
17 |
if (!model || model.unlisted) {
|
18 |
redirect(302, `${base}/`);
|
19 |
}
|
20 |
-
const renderedComponent = (ModelThumbnail
|
21 |
-
|
22 |
-
|
|
|
|
|
23 |
});
|
24 |
|
25 |
-
const reactLike = html(
|
26 |
-
"<style>" + renderedComponent.css.code + "</style>" + renderedComponent.html
|
27 |
-
);
|
28 |
|
29 |
const svg = await satori(reactLike, {
|
30 |
width: 1200,
|
|
|
1 |
import ModelThumbnail from "./ModelThumbnail.svelte";
|
2 |
import { redirect, type RequestHandler } from "@sveltejs/kit";
|
|
|
3 |
|
4 |
import { Resvg } from "@resvg/resvg-js";
|
5 |
import satori from "satori";
|
|
|
9 |
import InterBold from "$lib/server/fonts/Inter-Bold.ttf";
|
10 |
import { base } from "$app/paths";
|
11 |
import { models } from "$lib/server/models";
|
12 |
+
import { render } from "svelte/server";
|
13 |
|
14 |
export const GET: RequestHandler = (async ({ params }) => {
|
15 |
const model = models.find(({ id }) => id === params.model);
|
|
|
17 |
if (!model || model.unlisted) {
|
18 |
redirect(302, `${base}/`);
|
19 |
}
|
20 |
+
const renderedComponent = render(ModelThumbnail, {
|
21 |
+
props: {
|
22 |
+
name: model.name,
|
23 |
+
logoUrl: model.logoUrl,
|
24 |
+
},
|
25 |
});
|
26 |
|
27 |
+
const reactLike = html("<style>" + renderedComponent.head + "</style>" + renderedComponent.body);
|
|
|
|
|
28 |
|
29 |
const svg = await satori(reactLike, {
|
30 |
width: 1200,
|