Skip to content

Commit 70644c7

Browse files
committed
Add Database Mutation to Create a File
1 parent 871ad61 commit 70644c7

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

src/app/api/uploadthing/core.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { auth } from "@clerk/nextjs/server";
22
import { createUploadthing, type FileRouter } from "uploadthing/next";
33
import { UploadThingError } from "uploadthing/server";
44

5+
import * as mutations from "~/server/db/mutations";
6+
57
const f = createUploadthing();
68

79
export const ourFileRouter = {
@@ -18,6 +20,9 @@ export const ourFileRouter = {
1820
console.log("Upload complete for userId:", metadata.userId);
1921
console.log("file url", file.ufsUrl);
2022

23+
const uploadedFile = { ...file, parent: 0 };
24+
await mutations.createFile(uploadedFile, metadata.userId);
25+
2126
return { uploadedBy: metadata.userId };
2227
}),
2328
} satisfies FileRouter;

src/server/db/mutations.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { db } from "~/server/db";
2+
import { type File, files_table as filesSchema } from "~/server/db/schema";
3+
4+
export function createFile(file: Omit<File, "id">, _userId: string) {
5+
return db.insert(filesSchema).values(file);
6+
}

0 commit comments

Comments
 (0)