fastify / demo

MIT License
26 stars 15 forks source link

Check for existing file when uploading image #38

Open jean-michelet opened 3 weeks ago

jean-michelet commented 3 weeks ago

When uploading a task image, we should look if there is already a file associated, and remove it.

JP-sDEV commented 3 weeks ago

Hi can I be assigned this issue?

jean-michelet commented 3 weeks ago

Hi!

Go ahead!

JP-sDEV commented 3 weeks ago

I'm looking through the codebase and correct me if I'm wrong - I suspect that the fastify.post found in demo/src/routes/api/tasks/index.ts is the endpoint to be changed?

jean-michelet commented 3 weeks ago

This is POST /:id/upload. We store the filename in the tasks table in db for later retrieval. Look how we do store the file and you will know how to check if there is already an existing file. When we retrieve a task, we must first look if a file with name = task.filename exists in the upload directory. But you should delete the file after the db operations.

JP-sDEV commented 3 weeks ago

Understood, I believe I have an idea on where to put the deletion. I'll open a PR hopefully tomorrow morning/afternoon. Thank you!