Skip to content

Commit

Permalink
move fn onto server
Browse files Browse the repository at this point in the history
  • Loading branch information
secondl1ght committed May 23, 2024
1 parent bd004c3 commit 2357c39
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
38 changes: 0 additions & 38 deletions src/routes/og/generateImage.ts

This file was deleted.

40 changes: 39 additions & 1 deletion src/routes/og/merchant/+server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,46 @@
import { STADIA_API_KEY } from '$env/static/private';
import { MerchantOG } from '$lib/comp';
import { generateImage } from '../generateImage';
import type { RequestHandler } from './$types';

import { read } from '$app/server';
import Manrope from '$lib/fonts/Manrope-Regular.ttf';
import { Resvg } from '@resvg/resvg-js';
import satori from 'satori';
import { html as toReactNode } from 'satori-html';

const fontData = read(Manrope).arrayBuffer();

const height = 630;
const width = 1200;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const generateImage = async (component: any) => {
const jsx = toReactNode(`${component.html}<style>${component.css.code}</style>`);

const svg = await satori(jsx, {
fonts: [
{
name: 'Manrope',
data: await fontData,
style: 'normal'
}
],
height,
width
});

const resvg = new Resvg(svg, {
fitTo: {
mode: 'width',
value: width
}
});

const image = resvg.render();

return image.asPng();
};

export const GET: RequestHandler = async ({ url }) => {
const lat = url.searchParams.get('lat');
const lon = url.searchParams.get('lon');
Expand Down

0 comments on commit 2357c39

Please sign in to comment.