fix: update searchParams type to Promise and resolve before accessing id

This commit is contained in:
ZareMate 2025-05-12 08:07:36 +02:00
parent 24d90a9412
commit d4661dc8e3
Signed by: zaremate
GPG Key ID: 369A0E45E03A81C3
2 changed files with 13 additions and 9 deletions

View File

@ -24,9 +24,10 @@ interface FileDetails {
export async function generateMetadata({
searchParams,
}: {
searchParams: { id?: string };
searchParams: Promise<{ id?: string }>;
}): Promise<Metadata> {
const fileId = searchParams.id;
const resolvedSearchParams = await searchParams; // Resolve the promise
const fileId = resolvedSearchParams.id;
if (!fileId) {
return {
@ -84,9 +85,10 @@ async function fetchFileDetails(fileId: string): Promise<FileDetails | null> {
export default async function FilePreviewContainer({
searchParams,
}: {
searchParams: { id?: string };
searchParams: Promise<{ id?: string }>;
}) {
const fileId = searchParams.id;
const resolvedSearchParams = await searchParams; // Resolve the promise
const fileId = resolvedSearchParams.id;
if (!fileId) {
notFound();

View File

@ -18,18 +18,20 @@ export const postRouter = createTRPCRouter({
create: protectedProcedure
.input(z.object({ name: z.string().min(1) }))
.mutation(async ({ ctx, input }) => {
return ctx.db.post.create({
return ctx.db.file.create({
data: {
name: input.name,
createdBy: { connect: { id: ctx.session.user.id } },
url: "default-url", // Replace with actual URL logic
size: 0, // Replace with actual size logic
extension: "txt", // Replace with actual extension logic
},
});
}),
getLatest: protectedProcedure.query(async ({ ctx }) => {
const post = await ctx.db.post.findFirst({
orderBy: { createdAt: "desc" },
where: { createdBy: { id: ctx.session.user.id } },
const post = await ctx.db.file.findFirst({
orderBy: { uploadDate: "desc" }, // Replace 'createdAt' with the correct field name from your schema
where: { uploadedById: ctx.session.user.id },
});
return post ?? null;