@@ -10,24 +10,28 @@ const sizeOfAsync = promisify(sizeOf);
1010const photosDirectory = config . photosDirectory ;
1111const thumbDirectory = path . join ( photosDirectory , 'thumbs' ) ;
1212
13+ async function directoryExistsAsync ( dirname ) {
14+ try {
15+ const stats = await fs . stat ( dirname ) ;
16+ return stats . isDirectory ( ) ;
17+ } catch ( err ) {
18+ if ( err . code === 'ENOENT' ) {
19+ return false ;
20+ }
21+ throw err ;
22+ }
23+ }
24+
1325async function processPhotosAsync ( ) {
26+ if ( ! await directoryExistsAsync ( photosDirectory ) ) {
27+ console . warn ( "Photos directory doesn't exist: " + photosDirectory ) ;
28+ return [ ] ;
29+ }
1430 try {
1531 // Read the photos directory asynchronously
1632 const photoFiles = await fs . readdir ( photosDirectory ) ;
1733
18- let thumbDirectoryExists = false ;
19-
20- // Check if the thumbs directory exists
21- try {
22- const stats = await fs . stat ( thumbDirectory ) ;
23- thumbDirectoryExists = stats . isDirectory ( ) ;
24- } catch ( err ) {
25- if ( err . code !== 'ENOENT' ) {
26- // Re-throw unexpected errors
27- throw err ;
28- }
29- // thumbs directory does not exist
30- }
34+ let thumbDirectoryExists = await directoryExistsAsync ( thumbDirectory ) ;
3135
3236 if ( ! thumbDirectoryExists ) {
3337 console . warn ( 'Photos directory doesn\'t contain a "thumbs" directory, full photos will be used instead.' ) ;
@@ -102,7 +106,7 @@ async function processPhotosAsync() {
102106let photos = [ ] ;
103107const photoPromise = processPhotosAsync ( )
104108 . then ( result => photos = result )
105- . catch ( err => {
109+ . catch ( _ => {
106110 photos = [ ] ;
107111 // Handle the error as needed, e.g., notify the user or retry
108112 } ) ;
0 commit comments