TagSpaces is an offline, open source, document manager with tagging support
fix video thumbnails for web and S3
sytolk8c069b7ad7f3
diff --git a/src/main/protocol.ts b/src/main/protocol.tsindex 310b3fcf5..06e873787 100644--- a/src/main/protocol.ts+++ b/src/main/protocol.ts@@ -44,10 +44,13 @@ const initialize = () => {}protocol.handle(mediaProtocol, (request: any) => {- // list all files in the directory- const filepath = decodeURIComponent(- request.url.slice(`${mediaProtocol}://`.length).replace(/\/$/, ''),- ); // remove trailing slash+ // Get the file path from the URL without the trailing slash+ let filepath = request.url+ .slice(`${mediaProtocol}://`.length)+ .replace(/\/$/, '');+ filepath = decodeURIComponent(filepath);+ // Re-encode '#' characters to preserve them in the file URL+ filepath = filepath.replace(/#/g, '%23');const pathname = normalize(fileURLToPath(`file://${filepath}`)); //pathToFileURL(filepath).toString();const asFileUrl = pathToFileURL(pathname).toString();console.log(diff --git a/src/renderer/hooks/IOActionsContextProvider.tsx b/src/renderer/hooks/IOActionsContextProvider.tsxindex 84255862d..4a6a4bf07 100644--- a/src/renderer/hooks/IOActionsContextProvider.tsx+++ b/src/renderer/hooks/IOActionsContextProvider.tsx@@ -885,6 +885,7 @@ export const IOActionsContextProvider = ({fsEntry.size,location.loadTextFilePromise,location.getFileContentPromise,+ location.getThumbPath,location?.getDirSeparator(),).then((dataURL) => {if (dataURL && dataURL.length > 6) {@@ -1047,6 +1048,7 @@ export const IOActionsContextProvider = ({fsEntry.size,currentLocation.loadTextFilePromise,currentLocation.getFileContentPromise,+ currentLocation.getThumbPath,currentLocation?.getDirSeparator(),).then((dataURL) => {@@ -1267,6 +1269,7 @@ export const IOActionsContextProvider = ({0,currentLocation.loadTextFilePromise,currentLocation.getFileContentPromise,+ currentLocation.getThumbPath,currentLocation?.getDirSeparator(),).then((dataURL) => {if (dataURL && dataURL.length > 6) {diff --git a/src/renderer/hooks/ThumbGenerationContextProvider.tsx b/src/renderer/hooks/ThumbGenerationContextProvider.tsxindex 1565d3525..ce9c17c3a 100644--- a/src/renderer/hooks/ThumbGenerationContextProvider.tsx+++ b/src/renderer/hooks/ThumbGenerationContextProvider.tsx@@ -474,6 +474,7 @@ export const ThumbGenerationContextProvider = ({fileSize,location.loadTextFilePromise,location.getFileContentPromise,+ location.getThumbPath,location.getDirSeparator(),).then((dataURL) => {diff --git a/src/renderer/services/thumbsgenerator.ts b/src/renderer/services/thumbsgenerator.tsindex 2eb675a23..3df9fa87c 100644--- a/src/renderer/services/thumbsgenerator.ts+++ b/src/renderer/services/thumbsgenerator.ts@@ -109,6 +109,7 @@ export function generateThumbnailPromise(fileSize: number,loadTextFilePromise,getFileContentPromise,+ getThumbPath,dirSeparator: string,) {const ext = extractFileExtension(fileURL, dirSeparator).toLowerCase();@@ -175,13 +176,14 @@ export function generateThumbnailPromise();}} else if (supportedVideos.indexOf(ext) >= 0) {- if (Pro) {- return Pro.ThumbsGenerator.generateVideoThumbnail(- fileURLEscaped,- maxSize,- );+ if (getThumbPath) {+ return getThumbPath(fileURL).then((url) => {+ if (Pro) {+ return Pro.ThumbsGenerator.generateVideoThumbnail(url, maxSize);+ }+ return generateVideoThumbnail(url);+ });}- return generateVideoThumbnail(fileURLEscaped);}return generateDefaultThumbnail();}@@ -442,6 +444,7 @@ function generateVideoThumbnail(fileURL): Promise<string> {const ctx = canvas.getContext('2d');let img: HTMLImageElement = new Image();let video: HTMLVideoElement = document.createElement('video');+ video.crossOrigin = 'anonymous'; // Attempt to bypass CORS restrictionsconst captureTime = 1.5; // time in seconds at which to capture the image from the videovideo.onloadedmetadata = () => {@@ -471,7 +474,9 @@ function generateVideoThumbnail(fileURL): Promise<string> {console.log(`Error opening: ${fileURL} for tmb gen with: ${err} `);resolve('');};- video.src = fileURL.replace(/#/g, '%23');+ video.src = fileURL.startsWith('http')+ ? fileURL+ : fileURL.replace(/#/g, '%23');} catch (e) {console.log(`Error creating video thumb for : ${fileURL} with: ${e}`);resolve('');