File tree Expand file tree Collapse file tree 2 files changed +9
-0
lines changed
Expand file tree Collapse file tree 2 files changed +9
-0
lines changed Original file line number Diff line number Diff line change 3636 },
3737 "dependencies" : {
3838 "drizzle-orm" : " ^0.44.5" ,
39+ "mime" : " ^4.1.0" ,
3940 "zod" : " ^4.1.5"
4041 },
4142 "peerDependencies" : {
Original file line number Diff line number Diff line change 11import type { AuthContext } from "better-auth" ;
22import { createAuthEndpoint , getSessionFromCtx , sessionMiddleware } from "better-auth/api" ;
33import type { FieldAttribute } from "better-auth/db" ;
4+ import mime from "mime/lite" ;
45import { z , type ZodType } from "zod" ;
56import type { FileMetadata , R2Config } from "./types" ;
67
@@ -512,11 +513,18 @@ export const createR2Endpoints = (
512513 getR2Storage : ( ) => ReturnType < typeof createR2Storage > | null ,
513514 r2Config ?: R2Config
514515) => {
516+ const allowedMediaTypes = r2Config ?. allowedTypes
517+ ?. map ( type => mime . getType ( type ) )
518+ . filter ( ( mimeType ) : mimeType is string => Boolean ( mimeType ) ) ;
519+
515520 return {
516521 upload : createAuthEndpoint (
517522 "/files/upload-raw" ,
518523 {
519524 method : "POST" ,
525+ metadata : {
526+ allowedMediaTypes,
527+ } ,
520528 } ,
521529 async ctx => {
522530 // Manually get session instead of using middleware
You can’t perform that action at this time.
0 commit comments