File tree Expand file tree Collapse file tree 3 files changed +32
-5
lines changed Expand file tree Collapse file tree 3 files changed +32
-5
lines changed Original file line number Diff line number Diff line change 11# Secure Document Share - Backend
22
3- ## Overview
4- This is the backend for our Secure Document Share App.
5-
6- ## Features
7- tbd
3+ ## About
4+ This is the backend for our Secure Document Share App.<br >
5+ It provides the WebSocket and Http Server.
86
97### Prerequisites
108Ensure you have the following installed:
@@ -30,3 +28,8 @@ Ensure you have the following installed:
3028 ``` sh
3129 node server.mjs --port=< port>
3230 ```
31+
32+ 4 . ** Setup the cron**
33+ ``` sh
34+ 0 0 * * * /usr/bin/node /path/to/your/project/cron/daily.mjs
35+ ```
Original file line number Diff line number Diff line change 1+ import { deleteOldFiles } from './lib.js' ;
2+
3+ // Run the cleanup task to delete old files
4+ deleteOldFiles ( './data' , 3 ) . catch ( console . error ) ;
Original file line number Diff line number Diff line change 1+ import * as fs from 'fs/promises' ;
2+ import * as path from 'path' ;
3+
4+ export async function deleteOldFiles ( dir , retentionDays ) {
5+ const now = Date . now ( ) ;
6+ const files = await fs . readdir ( dir ) ;
7+
8+ for ( const file of files ) {
9+ const filePath = path . join ( dir , file ) ;
10+ const stat = await fs . stat ( filePath ) ;
11+
12+ if ( file . endsWith ( '.bin' ) ) {
13+ const ageInDays = ( now - stat . mtimeMs ) / ( 1000 * 60 * 60 * 24 ) ;
14+ if ( ageInDays > retentionDays && stat . isFile ( ) ) {
15+ await fs . unlink ( filePath ) ;
16+ console . log ( `Deleted: ${ filePath } ` ) ;
17+ }
18+ }
19+ }
20+ }
You can’t perform that action at this time.
0 commit comments