@@ -7,6 +7,7 @@ import { getServerSession } from "next-auth/next";
77import path from "node:path" ;
88
99import { newId } from "@/lib/id-helper" ;
10+ import { log } from "@/lib/utils" ;
1011
1112import { authOptions } from "../../auth/[...nextauth]" ;
1213
@@ -19,10 +20,11 @@ export const config = {
1920const tusServer = new Server ( {
2021 // `path` needs to match the route declared by the next file router
2122 path : "/api/file/tus" ,
22- // maxSize: 1024 * 1024 * 1024 * 2, // 2 GiB
23- // respectForwardedHeaders: true,
23+ maxSize : 1024 * 1024 * 1024 * 2 , // 2 GiB
24+ respectForwardedHeaders : true ,
2425 datastore : new S3Store ( {
2526 partSize : 8 * 1024 * 1024 , // each uploaded part will have ~8MiB,
27+ // TODO: expirationPeriodInMilliseconds is not working due to a permissions issue
2628 // expirationPeriodInMilliseconds: 1000 * 60 * 60 * 3, // 3 hours
2729 s3ClientConfig : {
2830 bucket : process . env . NEXT_PRIVATE_UPLOAD_BUCKET as string ,
@@ -47,39 +49,23 @@ const tusServer = new Server({
4749 generateUrl ( req , { proto, host, path, id } ) {
4850 // Encode the ID to be URL safe
4951 id = Buffer . from ( id , "utf-8" ) . toString ( "base64url" ) ;
50- console . log ( "proto" , proto ) ;
51- // INFO: hardcoding the protocol to https for now - https://github.com/tus/tus-node-server/issues/635
52- proto = process . env . NODE_ENV === "development" ? "http" : "https" ;
5352 return `${ proto } ://${ host } ${ path } /${ id } ` ;
5453 } ,
5554 getFileIdFromRequest ( req ) {
5655 // Extract the ID from the URL
5756 const id = ( req . url as string ) . split ( "/api/file/tus/" ) [ 1 ] ;
5857 return Buffer . from ( id , "base64url" ) . toString ( "utf-8" ) ;
5958 } ,
59+ onResponseError ( req , res , err ) {
60+ log ( {
61+ message : "Error uploading a file. Error: \n\n" + err ,
62+ type : "error" ,
63+ } ) ;
64+ return { status_code : 500 , body : "Internal Server Error" } ;
65+ } ,
6066} ) ;
6167
6268export default function handler ( req : NextApiRequest , res : NextApiResponse ) {
63- // // Set CORS headers for all responses
64- // res.setHeader(
65- // "Access-Control-Allow-Methods",
66- // "GET,POST,PUT,HEAD,DELETE,OPTIONS",
67- // );
68- // res.setHeader(
69- // "Access-Control-Allow-Headers",
70- // "Content-Type,Upload-Length,Upload-Offset,Upload-Metadata,Upload-Defer-Length,Upload-Concat",
71- // );
72- // res.setHeader(
73- // "Access-Control-Expose-Headers",
74- // "Upload-Offset,Upload-Length,Location",
75- // );
76-
77- // if (req.method === "OPTIONS") {
78- // // Handle preflight requests
79- // res.status(204).end();
80- // return;
81- // }
82-
8369 // Get the session
8470 const session = getServerSession ( req , res , authOptions ) ;
8571 if ( ! session ) {
0 commit comments