-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: File API module #2418
feat: File API module #2418
Conversation
.field("filename", "") | ||
.attach("file", Buffer.from("some data"), "some_file.txt") | ||
.expect(422) | ||
.expect(400) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One issue with the current simplified Zod error handling is that the validation checker in api.planx.uk/shared/middleware/validate.ts
just returns a 400 so we lose some nuance.
I'll open a GH issue describing this small improvement as well as nicer error formatting using something like https://github.com/causaly/zod-validation-error maybe.
expect(res.body).toHaveProperty("issues"); | ||
expect(res.body).toHaveProperty("name", "ZodError"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above - I'd like there to be more meaningful errors returned here. It does show that the error is the missing filename
field but it's not in a super friendly format.
public: `${process.env.REACT_APP_API_URL}/file/public/upload`, | ||
private: `${process.env.REACT_APP_API_URL}/file/private/upload`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These routes are only used internally and referenced here - it made sense to pick this up as a small tidy up to standardise our routes a little.
Removed vultr server and associated DNS entries |
@@ -11,7 +11,7 @@ export const getFileFromS3 = async (fileId: string) => { | |||
const file = await s3.getObject(params).promise(); | |||
|
|||
return { | |||
body: file.Body, | |||
body: file.Body as Buffer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be S3.Body
which is just Buffer | Uint8Array | Blob | string | Readable
but this was causing Vultr to run out of heap memory when compiling with tsc
. It was going from 350mb to over 1gb just for this change - presumably it was importing and compiling a ton of additional AWS types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes make this really clean & consistent, thanks!
67286e6
to
d5a9bd7
Compare
What does this PR do?
file_type
→fileType