Skip to content

feat(server): add automatic cleanup of upload files older than 24 hours#47

Open
abhishekmanegit wants to merge 1 commit into
Pushkarini579:mainfrom
abhishekmanegit:feature/auto-file-cleanup
Open

feat(server): add automatic cleanup of upload files older than 24 hours#47
abhishekmanegit wants to merge 1 commit into
Pushkarini579:mainfrom
abhishekmanegit:feature/auto-file-cleanup

Conversation

@abhishekmanegit

Copy link
Copy Markdown

What this PR does

Implements automatic cleanup of uploaded retina scan files to prevent disk exhaustion on the server, as requested in #37.

The server/uploads/ directory accumulates every uploaded scan with no removal mechanism. This PR adds a scheduled background task that automatically deletes files older than 24 hours.

Changes

  • Added node-cron as a dependency (server/package.json)
  • Created server/utils/cleanupUploads.js
    • Scans the server/uploads/ directory
    • Checks each file's last-modified timestamp (mtimeMs)
    • Deletes any file older than 24 hours
    • Logs each deletion and any errors encountered
  • Updated server/index.js
    • Imports node-cron and the new cleanup utility
    • Schedules the cleanup job to run every hour (0 * * * *)
    • Also runs cleanup once immediately on server startup

How it works

const MAX_AGE_MS = 24 * 60 * 60 * 1000; // 24 hours

Every hour, the cron job iterates through all files in uploads/, compares each file's age against the 24-hour threshold, and removes any file that exceeds it using fs.unlink.

Testing

Tested locally by temporarily lowering the threshold to 10 seconds and the cron schedule to every 15 seconds:

  1. Started the server (node index.js)
  2. Manually created a test file inside server/uploads/
  3. Confirmed via console logs that the scheduled job detected and deleted the file:
    🧹 Running scheduled uploads cleanup...

🗑️ Cleanup: deleted old file testfile.txt
4. Verified the file was removed from the uploads/ folder
5. Reverted the threshold and schedule back to production values (24 hours / hourly) before committing

Notes

  • No changes were made to existing upload or analysis logic — this is purely additive.
  • The MongoDB connection error visible in local logs is unrelated to this PR (no local MongoDB instance running during testing).

Closes #37

@vercel

vercel Bot commented Jun 21, 2026

Copy link
Copy Markdown

@abhishekmanegit is attempting to deploy a commit to the Pushkarini 's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Server] Implement Automatic File Cleanup

1 participant