@@ -49,8 +49,13 @@ async function iterateAndDelete(event: H3Event, writable: WritableStream, signal
4949 break ;
5050 }
5151 const uploaded = Date . parse ( object . uploaded . toString ( ) ) ;
52+ console . log ( 'uploaded' , today , uploaded , today - uploaded , ( today - uploaded ) / ( 1000 * 3600 * 24 * 30 * 6 ) )
5253 // remove the object anyway if it's 6 months old already
53- if ( ( today - uploaded ) / ( 1000 * 3600 * 24 * 30 * 6 ) >= 1 ) {
54+ // Use calendar-accurate 6 months check
55+ const uploadedDate = new Date ( uploaded ) ;
56+ const sixMonthsAgo = new Date ( today ) ;
57+ sixMonthsAgo . setMonth ( sixMonthsAgo . getMonth ( ) - 6 ) ;
58+ if ( uploadedDate <= sixMonthsAgo ) {
5459 await writer . write ( JSON . stringify ( {
5560 key : object . key ,
5661 uploaded : new Date ( object . uploaded ) ,
@@ -63,9 +68,14 @@ async function iterateAndDelete(event: H3Event, writable: WritableStream, signal
6368 }
6469 const downloadedAt = ( await downloadedAtBucket . getItem ( object . key ) ) ! ;
6570 // if it has not been downloaded in the last month and it's at least 1 month old
71+ // Calendar-accurate 1 month checks
72+ const downloadedAtDate = new Date ( downloadedAt ) ;
73+ const oneMonthAgo = new Date ( today ) ;
74+ oneMonthAgo . setMonth ( oneMonthAgo . getMonth ( ) - 1 ) ;
75+ const uploadedDate2 = new Date ( uploaded ) ; // uploaded already parsed above
6676 if (
67- ! ( ( today - downloadedAt ) / ( 1000 * 3600 * 24 * 30 ) < 1 ) &&
68- ( today - uploaded ) / ( 1000 * 3600 * 24 * 30 ) >= 1
77+ downloadedAtDate <= oneMonthAgo &&
78+ uploadedDate2 <= oneMonthAgo
6979 ) {
7080 await writer . write ( JSON . stringify ( {
7181 key : object . key ,
0 commit comments