aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/VideoBox.tsx
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2022-07-28 14:10:32 -0400
committerbobzel <zzzman@gmail.com>2022-07-28 14:10:32 -0400
commitb830a5dc8df82886a9304ebe02fe93cdf1c0b521 (patch)
tree2a5810f03390e89d494860fbb3841c53a9da96fa /src/client/views/nodes/VideoBox.tsx
parent8597999f53a7599d9bdeeb70150baec95b2f6dd0 (diff)
fixed video thumbnail generation to have a lock that prevents multiple attempts to create the thumbnails at the same time. fixed ImageUpload to catch resize errors and not crash the server.
Diffstat (limited to 'src/client/views/nodes/VideoBox.tsx')
-rw-r--r--src/client/views/nodes/VideoBox.tsx16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/client/views/nodes/VideoBox.tsx b/src/client/views/nodes/VideoBox.tsx
index 681f7c5b2..4af4d2020 100644
--- a/src/client/views/nodes/VideoBox.tsx
+++ b/src/client/views/nodes/VideoBox.tsx
@@ -418,31 +418,29 @@ export class VideoBox extends ViewBoxAnnotatableComponent<ViewBoxAnnotatableProp
// extracts video thumbnails and saves them as field of doc
getVideoThumbnails = () => {
- const video = document.createElement('video');
+ if (this.dataDoc.thumbnails !== undefined) return;
+ this.dataDoc.thumbnails = new List<string>();
const thumbnailPromises: Promise<any>[] = [];
+ const video = document.createElement('video');
- video.onloadedmetadata = () => {
- video.currentTime = 0;
- };
+ video.onloadedmetadata = () => (video.currentTime = 0);
video.onseeked = () => {
const canvas = document.createElement('canvas');
canvas.height = video.videoHeight;
canvas.width = video.videoWidth;
const ctx = canvas.getContext('2d');
- ctx?.drawImage(video, 0, 0, canvas.width, canvas.height);
+ ctx?.drawImage(video, 0, 0, canvas.width, canvas.height, 0, 0, 25, 25);
const imgUrl = canvas.toDataURL();
const retitled = StrCast(this.rootDoc.title).replace(/[ -\.:]/g, '');
const encodedFilename = encodeURIComponent('thumbnail' + retitled + '_' + video.currentTime.toString().replace(/\./, '_'));
const filename = basename(encodedFilename);
- thumbnailPromises.push(VideoBox.convertDataUri(imgUrl, filename));
+ thumbnailPromises?.push(VideoBox.convertDataUri(imgUrl, filename, true));
const newTime = video.currentTime + video.duration / (VideoBox.numThumbnails - 1);
if (newTime < video.duration) {
video.currentTime = newTime;
} else {
- Promise.all(thumbnailPromises).then(thumbnails => {
- this.dataDoc.thumbnails = new List<string>(thumbnails);
- });
+ Promise.all(thumbnailPromises).then(thumbnails => (this.dataDoc.thumbnails = new List<string>(thumbnails)));
}
};