TagSpaces is an offline, open source, document manager with tagging support
fix S3 index creation && fix index thumbnail url (#1522)
Stanimir269cb8614342
diff --git a/app/components/SearchInline.tsx b/app/components/SearchInline.tsxindex efca31066..1cb3d0ca4 100644--- a/app/components/SearchInline.tsx+++ b/app/components/SearchInline.tsx@@ -154,7 +154,10 @@ const SearchInline = (props: Props) => {}, []); */useEffect(() => {- mainSearchField.current.value = '';+ // mainSearchField.current.value = '';+ if (Object.keys(props.searchQuery).length > 0) {+ props.setSearchQuery({});+ }}, [props.currentDirectory]);useEffect(() => {diff --git a/app/package-template.json b/app/package-template.jsonindex aeb52e214..a2c7a56cf 100644--- a/app/package-template.json+++ b/app/package-template.json@@ -5,6 +5,6 @@"nodeDependencies": {"@tagspaces/extensions": "1.0.0","sharp": "^0.29.2",- "@tagspaces/tagspaces-ws": "^1.0.16"+ "@tagspaces/tagspaces-ws": "^1.0.18"}}diff --git a/app/package.json b/app/package.jsonindex 73d31ec0e..ad84b19a2 100644--- a/app/package.json+++ b/app/package.json@@ -15,6 +15,6 @@"dependencies": {"@tagspaces/extensions": "1.0.0","sharp": "^0.29.2",- "@tagspaces/tagspaces-ws": "^1.0.16"+ "@tagspaces/tagspaces-ws": "^1.0.18"}}diff --git a/app/reducers/location-index.ts b/app/reducers/location-index.tsindex 229827fe8..c88ed7216 100644--- a/app/reducers/location-index.ts+++ b/app/reducers/location-index.ts@@ -371,10 +371,15 @@ export const actions = {!GlobalSearch.index ||GlobalSearch.index.length === 0) {- GlobalSearch.index = await loadIndex({- path: getLocationPath(currentLocation),- locationID: currentLocation.uuid- });+ GlobalSearch.index = await loadIndex(+ {+ path: getLocationPath(currentLocation),+ locationID: currentLocation.uuid,+ ...(isCloudLocation && { bucketName: currentLocation.bucketName })+ },+ PlatformIO.getDirSeparator(),+ PlatformIO.loadTextFilePromise+ );}Search.searchLocationIndex(GlobalSearch.index, searchQuery).then(searchResults => {@@ -462,7 +467,10 @@ export const actions = {await PlatformIO.enableObjectStoreSupport(location);}// if (Pro && Pro.Indexer && Pro.Indexer.hasIndex) {- indexExist = await hasIndex(nextPath); // , PlatformIO.getDirSeparator());+ indexExist = await hasIndex(+ nextPath,+ PlatformIO.getPropertiesPromise+ ); // , PlatformIO.getDirSeparator());if (searchQuery.forceIndexing ||@@ -489,8 +497,15 @@ export const actions = {// if (Pro && Pro.Indexer && Pro.Indexer.loadIndex) {console.log('Loading index for : ' + nextPath);directoryIndex = await loadIndex(- { path: nextPath, locationID: location.uuid },- PlatformIO.getDirSeparator()+ {+ path: nextPath,+ locationID: location.uuid,+ ...(isCloudLocation && {+ bucketName: currentLocation.bucketName+ })+ },+ PlatformIO.getDirSeparator(),+ PlatformIO.loadTextFilePromise);}return Search.searchLocationIndex(directoryIndex, searchQuery)diff --git a/app/services/electron-io.ts b/app/services/electron-io.tsindex 5471ea68c..fc457ce83 100644--- a/app/services/electron-io.ts+++ b/app/services/electron-io.ts@@ -434,7 +434,7 @@ export default class ElectronIO {}}- const fileName = eentry.name.toLowerCase();+ /* const fileName = eentry.name.toLowerCase();if (extractTextContent &&eentry.isFile &&@@ -450,7 +450,7 @@ export default class ElectronIO {fileName,fileContent);- }+ } */if (window.walkCanceled) {resolve(enhancedEntries);diff --git a/app/services/platform-io.ts b/app/services/platform-io.tsindex 45adaa23b..ed0da1206 100644--- a/app/services/platform-io.ts+++ b/app/services/platform-io.ts@@ -198,7 +198,12 @@ export default class PlatformIO {path,bucketName: objectStoreAPI.config().bucketName};- return PlatformIO.listObjectStoreDir(param, lite, extractText, ignorePatterns);+ return PlatformIO.listObjectStoreDir(+ param,+ lite,+ extractText,+ ignorePatterns+ );}return nativeAPI.listDirectoryPromise(path,@@ -213,7 +218,13 @@ export default class PlatformIO {lite: boolean = true,extractText: boolean = true,ignorePatterns: Array<string> = []- ): Promise<Array<any>> => objectStoreAPI.listDirectoryPromise(param, lite, extractText, ignorePatterns);+ ): Promise<Array<any>> =>+ objectStoreAPI.listDirectoryPromise(+ param,+ lite,+ extractText,+ ignorePatterns+ );static getPropertiesPromise = (path: string): Promise<any> => {if (objectStoreAPI) {@@ -399,6 +410,25 @@ export default class PlatformIO {});};+ static saveTextFilePlatform = (+ param: any,+ content: string,+ overwrite: boolean+ ): Promise<any> => {+ if (objectStoreAPI) {+ return objectStoreAPI.saveTextFilePromise(param, content, overwrite);+ }++ PlatformIO.ignoreByWatcher(param.path);++ return nativeAPI+ .saveTextFilePromise(param.path, content, overwrite)+ .then(result => {+ PlatformIO.deignoreByWatcher(param.path);+ return result;+ });+ };+static saveTextFilePromise = (filePath: string,content: string,diff --git a/app/services/utils-io.ts b/app/services/utils-io.tsindex 26dc02466..c5133d656 100644--- a/app/services/utils-io.ts+++ b/app/services/utils-io.ts@@ -20,8 +20,8 @@ import { v1 as uuidv1 } from 'uuid';import {loadIndex,enhanceDirectoryIndex,- persistIndex,- createIndex+ createIndex,+ getMetaIndexFilePath} from '@tagspaces/tagspaces-platforms/indexer';import { saveAs } from 'file-saver';import micromatch from 'micromatch';@@ -438,6 +438,35 @@ export function getPrevFile(return prevFile;}+/**+ * persistIndex based on location - S3 or Native+ * @param param+ * @param directoryIndex+ */+function persistIndex(param: string | any, directoryIndex: any) {+ let directoryPath;+ if (typeof param === 'object' && param !== null) {+ directoryPath = param.path;+ } else {+ directoryPath = param;+ }+ const folderIndexPath = getMetaIndexFilePath(directoryPath);+ return PlatformIO.saveTextFilePlatform(+ { ...param, path: folderIndexPath },+ JSON.stringify(directoryIndex), // relativeIndex),+ true+ )+ .then(() => {+ console.log(+ 'Index persisted for: ' + directoryPath + ' to ' + folderIndexPath+ );+ return true;+ })+ .catch(err => {+ console.error('Error saving the index for ' + folderIndexPath, err);+ });+}+export function createDirectoryIndex(param: string | any,extractText: boolean = false,@@ -468,21 +497,19 @@ export function createDirectoryIndex(}let listDirectoryPromise;+ let loadTextFilePromise;if (PlatformIO.haveObjectStoreSupport()) {listDirectoryPromise = PlatformIO.listObjectStoreDir;+ // eslint-disable-next-line prefer-destructuring+ loadTextFilePromise = PlatformIO.loadTextFilePromise;}- return createIndex(- param,- extractText,- ignorePatterns,- listDirectoryPromise- )+ return createIndex(param, extractText, ignorePatterns, listDirectoryPromise, loadTextFilePromise).then(directoryIndex =>persistIndex(param, directoryIndex).then(success => {if (success) {console.log('Index generated in folder: ' + directoryPath);- return enhanceDirectoryIndex(dirPath, directoryIndex, locationID);+ return enhanceDirectoryIndex(param, directoryIndex, locationID);}return undefined;})@@ -490,62 +517,6 @@ export function createDirectoryIndex(.catch(err => {console.error('Error creating index: ', err);});-- /* const SearchIndex = [];-- // eslint-disable-next-line compat/compat- return new Promise((resolve, reject) => {- setTimeout(() => {- let counter = 0;- console.time('createDirectoryIndex');- walkDirectory(- dirPath,- {- recursive: true,- skipMetaFolder: true,- skipDotHiddenFolder: true,- extractText- },- fileEntry => {- counter += 1;- if (counter > AppConfig.indexerLimit) {- console.warn('Walk canceled by ' + AppConfig.indexerLimit);- window.walkCanceled = true;- }- SearchIndex.push(enhanceEntry(fileEntry));- },- directoryEntry => {- if (directoryEntry.name !== AppConfig.metaFolder) {- counter += 1;- SearchIndex.push(enhanceEntry(directoryEntry));- }- },- ignorePatterns- )- .then(() => {- // entries - can be used for further processing- window.walkCanceled = false;- console.log(- 'Directory index created ' +- dirPath +- ' containing ' +- SearchIndex.length- );- console.timeEnd('createDirectoryIndex');- if (persist) {- persistIndex(dirPath, SearchIndex);- }- resolve(SearchIndex);- return true;- })- .catch(err => {- window.walkCanceled = false;- console.timeEnd('createDirectoryIndex');- console.warn('Error creating index: ' + err);- reject(err);- });- }, 2000);- }); */}export function walkDirectory(diff --git a/package.json b/package.jsonindex 78df8ad6a..e627e0b33 100644--- a/package.json+++ b/package.json@@ -152,7 +152,7 @@"@material-ui/icons": "^4.11.2","@material-ui/lab": "^4.0.0-alpha.57","@material-ui/pickers": "^3.2.10",- "@tagspaces/tagspaces-platforms": "^1.0.45",+ "@tagspaces/tagspaces-platforms": "^1.0.50","aws-amplify": "^3.3.27","aws-sdk": "^2.984.0","babel-polyfill": "^6.26.0",diff --git a/yarn.lock b/yarn.lockindex 7640e27ce..f076ef6de 100644--- a/yarn.lock+++ b/yarn.lock@@ -3362,10 +3362,10 @@dependencies:defer-to-connect "^1.0.1"-"@tagspaces/tagspaces-platforms@^1.0.45":- version "1.0.45"- resolved "https://registry.yarnpkg.com/@tagspaces/tagspaces-platforms/-/tagspaces-platforms-1.0.45.tgz#42ec8e1fa657467750231179c5e8e56419dad3c4"- integrity sha512-+FIIVjO5ezTUZqiIWTOKkK3DrTFShEWbt/dt7qbtRg+hRM30rmEuD39pLVUm/d0eHd0GvGkG90cCVXfU4ZuHYA==+"@tagspaces/tagspaces-platforms@^1.0.50":+ version "1.0.50"+ resolved "https://registry.yarnpkg.com/@tagspaces/tagspaces-platforms/-/tagspaces-platforms-1.0.50.tgz#5c6686405b6d7e290c3a70d9dafb8916d13f8566"+ integrity sha512-i3f2ltz+q0o/yD9uBvCpgRjpauH3LOyyAtsLWW4rhOxKoY061C/0t0B4HF5zWuZXc+xI2iVYVNberYR+rxHFDQ=="@testim/chrome-version@^1.0.7":version "1.0.7"