34 lines
1009 B
TypeScript
Raw Normal View History

import { PageContext } from "vike/types";
2024-02-22 20:59:20 +00:00
import { render } from "vike/abort";
import trpcServer from "~/server/api/trpc/trpc";
2024-03-03 18:55:51 +07:00
import { BASE_URL } from "~/lib/consts";
export const data = async (ctx: PageContext) => {
const trpc = await trpcServer(ctx);
2024-02-24 00:27:52 +00:00
const searchParams = ctx.urlParsed.search;
const filesParam = searchParams.files ? searchParams.files.split(",") : null;
2024-02-22 20:59:20 +00:00
const project = await trpc.project.getById(ctx.routeParams?.slug!);
if (!project) {
throw render(404, "Project not found!");
}
2024-03-03 18:24:00 +07:00
const files = await trpc.file.getAll({ projectId: project.id! });
2024-02-24 00:27:52 +00:00
const initialFiles = files.filter((i) =>
filesParam != null ? filesParam.includes(i.path) : i.isPinned
);
2024-02-22 20:59:20 +00:00
return {
title: project.title,
description: `Check ${project.title} on CodeShare!`,
2024-03-03 18:55:51 +07:00
ogImage: project.thumbnail
? BASE_URL + "/api/thumbnail" + project.thumbnail
: undefined,
2024-02-22 20:59:20 +00:00
project,
files,
2024-02-24 00:27:52 +00:00
initialFiles,
2024-02-22 20:59:20 +00:00
};
};
export type Data = Awaited<ReturnType<typeof data>>;