nsarrazin HF staff commited on
Commit
bbbed00
1 Parent(s): 992a8de

fix: social thumbnail assistants (#732)

Browse files
src/ambient.d.ts ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ declare module "*.ttf" {
2
+ const value: ArrayBuffer;
3
+ export default value;
4
+ }
src/routes/assistant/[assistantId]/thumbnail.png/+server.ts CHANGED
@@ -8,9 +8,11 @@ import type { SvelteComponent } from "svelte";
8
  import { Resvg } from "@resvg/resvg-js";
9
  import satori from "satori";
10
  import { html } from "satori-html";
11
- import { base } from "$app/paths";
12
 
13
- export const GET: RequestHandler = (async ({ url, params, fetch }) => {
 
 
 
14
  const assistant = await collections.assistants.findOne({
15
  _id: new ObjectId(params.assistantId),
16
  });
@@ -39,12 +41,12 @@ export const GET: RequestHandler = (async ({ url, params, fetch }) => {
39
  fonts: [
40
  {
41
  name: "Inter",
42
- data: await fetch(base + "/fonts/Inter-Regular.ttf").then((r) => r.arrayBuffer()),
43
  weight: 500,
44
  },
45
  {
46
  name: "Inter",
47
- data: await fetch(base + "/fonts/Inter-Bold.ttf").then((r) => r.arrayBuffer()),
48
  weight: 700,
49
  },
50
  ],
 
8
  import { Resvg } from "@resvg/resvg-js";
9
  import satori from "satori";
10
  import { html } from "satori-html";
 
11
 
12
+ import InterRegular from "../../../../../static/fonts/Inter-Regular.ttf";
13
+ import InterBold from "../../../../../static/fonts/Inter-Bold.ttf";
14
+
15
+ export const GET: RequestHandler = (async ({ url, params }) => {
16
  const assistant = await collections.assistants.findOne({
17
  _id: new ObjectId(params.assistantId),
18
  });
 
41
  fonts: [
42
  {
43
  name: "Inter",
44
+ data: InterRegular as unknown as ArrayBuffer,
45
  weight: 500,
46
  },
47
  {
48
  name: "Inter",
49
+ data: InterBold as unknown as ArrayBuffer,
50
  weight: 700,
51
  },
52
  ],
src/routes/assistant/[assistantId]/thumbnail.png/ChatThumbnail.svelte CHANGED
@@ -21,10 +21,10 @@
21
  <img class="mr-1.5 h-8 w-8" src={imgUrl} alt="app logo" />
22
  AI assistant
23
  </p>
24
- <h1 class="m-0 {name.length < 38 ? 'text-5xl' : 'text-4xl'} text-balance font-black">
25
  {name}
26
  </h1>
27
- <p class="mb-8 text-pretty text-2xl">
28
  {description.slice(0, 160)}
29
  {#if description.length > 160}...{/if}
30
  </p>
 
21
  <img class="mr-1.5 h-8 w-8" src={imgUrl} alt="app logo" />
22
  AI assistant
23
  </p>
24
+ <h1 class="m-0 {name.length < 38 ? 'text-5xl' : 'text-4xl'} font-black">
25
  {name}
26
  </h1>
27
+ <p class="mb-8 text-2xl">
28
  {description.slice(0, 160)}
29
  {#if description.length > 160}...{/if}
30
  </p>
vite.config.ts CHANGED
@@ -1,6 +1,21 @@
1
  import { sveltekit } from "@sveltejs/kit/vite";
2
- import { defineConfig } from "vite";
3
  import Icons from "unplugin-icons/vite";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  export default defineConfig({
6
  plugins: [
@@ -8,6 +23,7 @@ export default defineConfig({
8
  Icons({
9
  compiler: "svelte",
10
  }),
 
11
  ],
12
  optimizeDeps: {
13
  include: ["browser-image-resizer"],
 
1
  import { sveltekit } from "@sveltejs/kit/vite";
2
+ import { defineConfig, type PluginOption } from "vite";
3
  import Icons from "unplugin-icons/vite";
4
+ import { promises } from "fs";
5
+
6
+ // used to load fonts server side for thumbnail generation
7
+ function loadTTFAsArrayBuffer(): PluginOption {
8
+ return {
9
+ name: "load-ttf-as-array-buffer",
10
+ async transform(_src, id) {
11
+ if (id.endsWith(".ttf")) {
12
+ return `export default new Uint8Array([
13
+ ${new Uint8Array(await promises.readFile(id))}
14
+ ]).buffer`;
15
+ }
16
+ },
17
+ };
18
+ }
19
 
20
  export default defineConfig({
21
  plugins: [
 
23
  Icons({
24
  compiler: "svelte",
25
  }),
26
+ loadTTFAsArrayBuffer(),
27
  ],
28
  optimizeDeps: {
29
  include: ["browser-image-resizer"],