import fs from 'fs/promises' ; import path from 'path' ; export const deleteOldVideos = async ( rootVideoFolder , daysToKeepVideos ) => { let deleted = 0 ; const recursiveDelete = async ( dir ) => { const files = await fs . readdir ( dir ) ; for ( const file of files ) { const filePath = path . join ( dir , file ) ; const stats = await fs . stat ( filePath ) ; if ( await stats . isDirectory ( ) ) await recursiveDelete ( filePath ) ; else if ( stats . mtime . getTime ( ) < Date . now ( ) - daysToKeepVideos * 24 * 60 * 60 * 1000 ) { if ( ! ( filePath . endsWith ( '.mp4' ) || filePath . endsWith ( '.nfo' ) || filePath . endsWith ( '.png' ) ) ) { console . log ( `\n\n!!WARNING!! - Found file for deletion in ${ rootVideoFolder } that is not a mp4, nfo or png file!` ) ; console . log ( 'This could indicate that the root video folder is not being detected properly.' ) ; console . log ( 'Please report this as a Issue at https://github.com/Inrixia/Floatplane-Downloader/issues/new' ) ; process . exit ( 0 ) ; } await fs . unlink ( filePath ) ; deleted ++ ; } } } ; await recursiveDelete ( rootVideoFolder ) ; return deleted ; } ;