TagSpaces is an offline, open source, document manager with tagging support
Fix: updating perspective after thumbnails change (#1806)
Stanimir8668ebec940d
diff --git a/app/components/EntryProperties.tsx b/app/components/EntryProperties.tsxindex 46b7da42f..918b7ffcb 100644--- a/app/components/EntryProperties.tsx+++ b/app/components/EntryProperties.tsx@@ -73,10 +73,7 @@ import { Pro } from '../pro';import PlatformIO from '../services/platform-facade';import TagsSelect from './TagsSelect';import TransparentBackground from './TransparentBackground';-import {- replaceThumbnailURLPromise,- getThumbnailURLPromise-} from '-/services/thumbsgenerator';+import { getThumbnailURLPromise } from '-/services/thumbsgenerator';import {getLastBackgroundImageChange,getLastThumbnailImageChange,@@ -392,7 +389,7 @@ function EntryProperties(props: Props) {const setThumb = (filePath, thumbFilePath) => {if (filePath !== undefined) {- props.switchLocationType(props.openedEntry.locationId).then(() => {+ return props.switchLocationType(props.openedEntry.locationId).then(() => {if (PlatformIO.haveObjectStoreSupport() ||PlatformIO.haveWebDavSupport()@@ -401,35 +398,36 @@ function EntryProperties(props: Props) {props.updateThumbnailUrl(currentEntry.path, thumbUrl);return true;}- return replaceThumbnailURLPromise(filePath, thumbFilePath)- .then(objUrl => {- props.updateThumbnailUrl(- currentEntry.path,- objUrl.tmbPath +- (props.lastThumbnailImageChange+ /*return replaceThumbnailURLPromise(filePath, thumbFilePath)+ .then(objUrl => {*/+ props.updateThumbnailUrl(+ currentEntry.path,+ thumbFilePath+ // objUrl.tmbPath+ /*(props.lastThumbnailImageChange? '?' + props.lastThumbnailImageChange- : '')- );- props.switchCurrentLocationType();- return true;- })+ : '')*/+ );+ return props.switchCurrentLocationType();+ /*}).catch(err => {props.switchCurrentLocationType();console.warn('Error replaceThumbnailURLPromise ' + err);props.showNotification('Error replacing thumbnail');- });+ });*/});+ } else {+ // reset Thumbnail+ return getThumbnailURLPromise(currentEntry.path)+ .then(objUrl => {+ props.updateThumbnailUrl(currentEntry.path, objUrl.tmbPath);+ return true;+ })+ .catch(err => {+ console.warn('Error getThumbnailURLPromise ' + err);+ props.showNotification('Error reset Thumbnail');+ });}- // reset Thumbnail- return getThumbnailURLPromise(currentEntry.path)- .then(objUrl => {- props.updateThumbnailUrl(currentEntry.path, objUrl.tmbPath);- return true;- })- .catch(err => {- console.warn('Error getThumbnailURLPromise ' + err);- props.showNotification('Error reset Thumbnail');- });};const toggleBackgroundColorPicker = () => {@@ -1384,7 +1382,9 @@ function mapActionCreatorsToProps(dispatch) {}const areEqual = (prevProp: Props, nextProp: Props) =>- JSON.stringify(nextProp.openedEntry) === JSON.stringify(prevProp.openedEntry);+ JSON.stringify(nextProp.openedEntry) ===+ JSON.stringify(prevProp.openedEntry) &&+ nextProp.lastThumbnailImageChange === prevProp.lastThumbnailImageChange;export default withLeaflet(connect(diff --git a/app/reducers/app.ts b/app/reducers/app.tsindex 144746e89..78fba5a5a 100644--- a/app/reducers/app.ts+++ b/app/reducers/app.ts@@ -564,17 +564,15 @@ export default (state: any = initialState, action: any) => {return { ...state, isEntryInFullWidth: action.isFullWidth };}case types.UPDATE_THUMB_URL: {- const dirEntries = [...state.currentDirectoryEntries];- dirEntries.map(entry => {+ const dirEntries = state.currentDirectoryEntries.map(entry => {if (entry.path === action.filePath) {- // eslint-disable-next-line no-param-reassign- entry.thumbPath = action.thumbUrl;+ return { ...entry, thumbPath: action.thumbUrl };}- return true;+ return entry;});return {...state,- currentDirectoryEntries: [...dirEntries]+ currentDirectoryEntries: dirEntries};}case types.UPDATE_THUMB_URLS: {diff --git a/app/services/thumbsgenerator.ts b/app/services/thumbsgenerator.tsindex 5a48fb51d..6999df36c 100644--- a/app/services/thumbsgenerator.ts+++ b/app/services/thumbsgenerator.ts@@ -140,133 +140,134 @@ function getThumbFileLocation(filePath: string) {export function getThumbnailURLPromise(filePath: string): Promise<{ filePath: string; tmbPath?: string }> {- return new Promise(resolve => {- PlatformIO.getPropertiesPromise(filePath)- .then(origStats => {- const thumbFilePath = getThumbFileLocation(filePath);- PlatformIO.getPropertiesPromise(thumbFilePath)- .then(stats => {- if (stats) {- // Thumbnail exists- if (origStats.lmdt > stats.lmdt) {- // Checking if is up to date- createThumbnailPromise(- filePath,- origStats.size,- thumbFilePath,- origStats.isFile- )- .then(tmbPath => resolve({ filePath, tmbPath }))- .catch(err => {- console.warn('Thumb generation failed ' + err);- resolve({ filePath, tmbPath: thumbFilePath });- });- } else {- // Tmb up to date- resolve({ filePath });- }- } else {- // Thumbnail does not exists- createThumbnailPromise(+ return PlatformIO.getPropertiesPromise(filePath)+ .then(origStats => {+ const thumbFilePath = getThumbFileLocation(filePath);+ return PlatformIO.getPropertiesPromise(thumbFilePath)+ .then(stats => {+ if (stats) {+ // Thumbnail exists+ if (origStats.lmdt > stats.lmdt) {+ // Checking if is up to date+ return createThumbnailPromise(filePath,origStats.size,thumbFilePath,origStats.isFile)- .then(tmbPath => resolve({ filePath, tmbPath }))+ .then(tmbPath => ({ filePath, tmbPath })).catch(err => {console.warn('Thumb generation failed ' + err);- resolve({ filePath });+ return Promise.resolve({ filePath, tmbPath: thumbFilePath });});+ } else {+ // Tmb up to date+ return Promise.resolve({ filePath, tmbPath: thumbFilePath });}- return true;- })- .catch(err => {- console.warn('Error getting tmb properties ' + err);- resolve({ filePath });- });- return true;- })- .catch(err => {- console.warn('Error getting file properties ' + err);- resolve({ filePath });- });- });+ } else {+ // Thumbnail does not exists+ return createThumbnailPromise(+ filePath,+ origStats.size,+ thumbFilePath,+ origStats.isFile+ )+ .then(tmbPath => ({ filePath, tmbPath }))+ .catch(err => {+ console.warn('Thumb generation failed ' + err);+ return Promise.resolve({ filePath });+ });+ }+ })+ .catch(err => {+ console.warn('Error getting tmb properties ' + err);+ return Promise.resolve({ filePath });+ });+ })+ .catch(err => {+ console.warn('Error getting file properties ' + err);+ return Promise.resolve({ filePath });+ });}-export function replaceThumbnailURLPromise(+/*export function replaceThumbnailURLPromise(filePath: string,thumbFilePath: string): Promise<any> {- return new Promise(resolve => {- PlatformIO.getPropertiesPromise(filePath)- .then(origStats => {- createThumbnailPromise(- filePath,- origStats.size,- thumbFilePath,- origStats.isFile- )- .then(tmbPath => resolve({ filePath, tmbPath }))- .catch(err => {- console.warn('Thumb generation failed ' + err);- resolve({ filePath, tmbPath: thumbFilePath });- });- return true;- })- .catch(err => {- console.warn('Error getting file properties ' + err);- resolve({ filePath });- });- });-}+ return PlatformIO.getPropertiesPromise(filePath)+ .then(origStats =>+ createThumbnailPromise(+ filePath,+ origStats.size,+ thumbFilePath,+ origStats.isFile+ )+ .then(tmbPath => ({ filePath, tmbPath }))+ .catch(err => {+ console.warn('Thumb generation failed ' + err);+ return { filePath, tmbPath: thumbFilePath };+ })+ )+ .catch(err => {+ console.warn('Error getting file properties ' + err);+ return { filePath };+ });+}*/export function createThumbnailPromise(filePath: string,fileSize: number,thumbFilePath: string,isFile: boolean-): Promise<any> {- return new Promise(async resolve => {- const metaDirectory = extractContainingDirectoryPath(- thumbFilePath,- PlatformIO.getDirSeparator()- );- const fileDirectory = isFile- ? extractContainingDirectoryPath(filePath, PlatformIO.getDirSeparator())- : filePath;- const normalizedFileDirectory = normalizePath(fileDirectory);- if (normalizedFileDirectory.endsWith(AppConfig.metaFolder)) {- resolve(undefined); // prevent creating thumbs in meta/.ts folder- return true;- }- const exist = await PlatformIO.checkDirExist(metaDirectory);+): Promise<string | undefined> {+ const metaDirectory = extractContainingDirectoryPath(+ thumbFilePath,+ PlatformIO.getDirSeparator()+ );+ const fileDirectory = isFile+ ? extractContainingDirectoryPath(filePath, PlatformIO.getDirSeparator())+ : filePath;+ const normalizedFileDirectory = normalizePath(fileDirectory);+ if (normalizedFileDirectory.endsWith(AppConfig.metaFolder)) {+ return Promise.resolve(undefined); // prevent creating thumbs in meta/.ts folder+ }+ return PlatformIO.checkDirExist(metaDirectory).then(exist => {if (!exist) {- await PlatformIO.createDirectoryPromise(metaDirectory);- }-- generateThumbnailPromise(filePath, fileSize)- .then(dataURL => {- if (dataURL && dataURL.length) {- saveThumbnailPromise(thumbFilePath, dataURL)- .then(() => resolve(thumbFilePath))- .catch(err => {- console.warn('Thumb saving failed ' + err + ' for ' + filePath);- resolve(undefined);- });- return true;- }- resolve(thumbFilePath);- return true;- })- .catch(err => {- console.warn('Thumb generation failed ' + err + ' for ' + filePath);- resolve(undefined);+ return PlatformIO.createDirectoryPromise(metaDirectory).then(() => {+ return createThumbnailSavePromise(filePath, fileSize, thumbFilePath);});- return true;+ } else {+ return createThumbnailSavePromise(filePath, fileSize, thumbFilePath);+ }});}+function createThumbnailSavePromise(+ filePath: string,+ fileSize: number,+ thumbFilePath: string+): Promise<string | undefined> {+ return generateThumbnailPromise(filePath, fileSize)+ .then(dataURL => {+ if (dataURL && dataURL.length) {+ return saveThumbnailPromise(thumbFilePath, dataURL)+ .then(() => thumbFilePath)+ .catch(err => {+ console.warn('Thumb saving failed ' + err + ' for ' + filePath);+ return Promise.resolve(undefined);+ });+ }+ return undefined; // thumbFilePath;+ })+ .catch(err => {+ console.warn('Thumb generation failed ' + err + ' for ' + filePath);+ return Promise.resolve(undefined);+ });+}++/**+ * return thumbFilePath: Promise<string> or empty sting on error or not supported+ */export function generateThumbnailPromise(fileURL: string, fileSize: number) {const ext = extractFileExtension(fileURL,