fix: update searchParams type to Promise and resolve before accessing id
This commit is contained in:
parent
24d90a9412
commit
d4661dc8e3
@ -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();
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user