Skip to content

Commit 1c9c9cd

Browse files
Only update thumbnail generation status and check for file if stream is live
1 parent 31fb7ed commit 1c9c9cd

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

server/aws/s3ThumbnailGenerator.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@ async function getThumbnail(streamer) {
2929
const headObjectCommand = new HeadObjectCommand({Bucket, Key});
3030
const output = await S3_CLIENT.send(headObjectCommand);
3131
if (Date.now() > output.LastModified.getTime() + storage.thumbnails.ttl) {
32-
return await generateStreamThumbnail({streamer, inputURL, Bucket, Key});
32+
return await generateStreamThumbnail({
33+
isLive: true, streamer, inputURL, Bucket, Key
34+
});
3335
}
3436
return resolveObjectURL({Bucket, Key});
3537
} catch (err) {
3638
if (err.name === 'NotFound') {
37-
return await generateStreamThumbnail({streamer, inputURL, Bucket, Key});
39+
return await generateStreamThumbnail({
40+
isLive: true, streamer, inputURL, Bucket, Key
41+
});
3842
}
3943
throw err;
4044
} finally {
@@ -43,18 +47,20 @@ async function getThumbnail(streamer) {
4347
}
4448
}
4549

46-
async function generateStreamThumbnail({streamer, inputURL, Bucket, Key}) {
47-
streamer.streamInfo.thumbnailGenerationStatus = ThumbnailGenerationStatus.IN_PROGRESS;
48-
await streamer.save();
49-
await checkFileExists(inputURL);
50+
async function generateStreamThumbnail({isLive, streamer, inputURL, Bucket, Key}) {
51+
if (isLive) {
52+
streamer.streamInfo.thumbnailGenerationStatus = ThumbnailGenerationStatus.IN_PROGRESS;
53+
await streamer.save();
54+
await checkFileExists(inputURL);
55+
}
5056
return resolveObjectURL(await doGenerateStreamThumbnail({Bucket, Key, inputURL}));
5157
}
5258

5359
async function checkFileExists(inputURL) {
5460
try {
5561
await axios.head(inputURL);
5662
} catch (err) {
57-
if (err.response.status === 404) {
63+
if (err.response && err.response.status === 404) {
5864
LOGGER.error('Stream file at {} does not exist', inputURL);
5965
} else {
6066
LOGGER.error('An unexpected error occurred during HEAD request to file at {}: {}', inputURL, err);

0 commit comments

Comments
 (0)