Skip to content

Commit 7faa747

Browse files
committed
fix server crash without photos dir
1 parent bcb0f54 commit 7faa747

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

server/process-photos.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,28 @@ const sizeOfAsync = promisify(sizeOf);
1010
const photosDirectory = config.photosDirectory;
1111
const 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+
1325
async 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() {
102106
let photos = [];
103107
const 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

Comments
 (0)