Files
enlaye_challenge/SOME_EXPLANATION.md
Loïc BERTRAND 4faba8fdc9 save
2025-12-10 21:48:38 +01:00

2.5 KiB
Raw Blame History

Some explanation

Changes

I modified the following files.

src/db/schema.ts

I modified the database schema as we have began during our call. Here is what I did:

  • create a new table hashes
  • create a one-to-many relation from one hash to many files

This structure enables to have multiple file references that have the same hash and file stored in the system.

src/app/api/upload/route.ts

I added the logic to process the new files:

  • get the file as a buffer
  • generate the hash from the buffer using the crypto module
  • check if the hash exists in the hashes table
    • if the hash exists, then
      • get the hash id
    • else (if the hash does not exist), then
      • create a new record in the table hashes and get its id
      • store the file in the storage with this id
  • create a new record in the files table with the foreign id of the hash

src/app/FileTree.tsx

I updated the file tree display :

  • retrieve all rows from the files table
  • build a tree from each files path
  • render nested lists with indentation
  • display a simple empty state when no files are present
  • display the file size for the leaf nodes

BONUS

Of course, as this is a coding challenge (or a small POC), it does not reflect a convenient and user-friendly interface of a final product.

We may think about the following directions to implement the UX for a first release:

  • implement a responsive design with Tailwind / shadcn
  • enable the user to drag and drop files and folders directly on an item of the tree to be able to complete it after a previous upload
  • flag duplicated files with a chip with a unique color and containing the reference or an id to identify the duplicates between them
  • add a step after the file selection and before the upload to warn the user that there are duplicate files in the selection and to wait for approval before continuing (it may encourage the user to clean files before uploading them)
  • display an import report after each upload with the list of imported files and a flag "duplicated / reused" to inform the user that this file has already been stored
  • be able to fold / unfold the nodes in the tree as the list becomes large
  • add a malware analysis before storing the file with ClamAV and inform the user that the file has been analyzed and no malware has been detected (it may reassure the customer)
  • be able to rename in place the files and the directories by clicking on them
  • enable the user to download a certified / signed / timestamped report to testify which files with which hash have been uploaded