-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: DH11 application and review tables * fix: update logsnag project * feat: add user to dh11 applications * feat: use DH11 Applications * fix: update routes to refer to dh11 * feat: prisma db migration * feat: backend for uppy signed url upload * fix: remove unnecessary validation, store at root * fix: cleanup packages * feat: basic upload component * feat: add endpoint for getting resume files * feat: handle uppy upload responses * fix: handle empty string dates * feat: connect uppy to react form * fix: prettier formatting * fix: add missing types * fix: make form mobile friendly again * fix: remove migration * fix: add missing libraries --------- Co-authored-by: Krish120003 <[email protected]>
- Loading branch information
1 parent
c2e8df8
commit 591e105
Showing
8 changed files
with
1,781 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { z } from "zod"; | ||
import { publicProcedure, router } from "./trpc"; | ||
import { | ||
GetObjectCommand, | ||
PutObjectCommand, | ||
S3Client, | ||
} from "@aws-sdk/client-s3"; | ||
import { getSignedUrl } from "@aws-sdk/s3-request-presigner"; | ||
import { TRPCError } from "@trpc/server"; | ||
import { env } from "../../env/server.mjs"; | ||
|
||
const { R2_ACCOUNT_ID, R2_ACCESS_KEY_ID, R2_SECRET_KEY_ID, R2_BUCKET_NAME } = | ||
env; | ||
|
||
const R2 = new S3Client({ | ||
region: "auto", | ||
endpoint: `https://${R2_ACCOUNT_ID}.r2.cloudflarestorage.com`, | ||
credentials: { | ||
accessKeyId: R2_ACCESS_KEY_ID, | ||
secretAccessKey: R2_SECRET_KEY_ID, | ||
}, | ||
}); | ||
|
||
export const fileUploadRouter = router({ | ||
getUploadUrl: publicProcedure | ||
.input( | ||
z.object({ | ||
filename: z.string(), | ||
contentType: z.string(), | ||
}) | ||
) | ||
.mutation(async ({ input }) => { | ||
try { | ||
const signedUrl = await getSignedUrl( | ||
R2, | ||
new PutObjectCommand({ | ||
Bucket: R2_BUCKET_NAME, | ||
Key: `${input.filename}`, | ||
ContentType: input.contentType, | ||
}), | ||
{ expiresIn: 3600 } | ||
); | ||
|
||
return { | ||
url: signedUrl, | ||
method: "PUT" as const, | ||
}; | ||
} catch (error) { | ||
console.error("Error generating signed URL:", error); | ||
throw new TRPCError({ | ||
code: "INTERNAL_SERVER_ERROR", | ||
message: "Failed to generate upload URL", | ||
}); | ||
} | ||
}), | ||
getDownloadUrl: publicProcedure | ||
.input( | ||
z.object({ | ||
key: z.string(), | ||
}) | ||
) | ||
.query(async ({ input }) => { | ||
try { | ||
const command = new GetObjectCommand({ | ||
Bucket: R2_BUCKET_NAME, | ||
Key: input.key, | ||
}); | ||
|
||
const signedUrl = await getSignedUrl(R2, command, { | ||
expiresIn: 3600, // URL expires in 1 hour | ||
}); | ||
|
||
return { | ||
url: signedUrl, | ||
}; | ||
} catch (error) { | ||
console.error("Error generating download URL:", error); | ||
throw new TRPCError({ | ||
code: "INTERNAL_SERVER_ERROR", | ||
message: "Failed to generate download URL", | ||
}); | ||
} | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters