Skip to content

TagSpaces is an offline, open source, document manager with tagging support

TSN622 - Only one level directory listing on S3/Minio (#1385)

Stanimir07c03e89fe63
diff --git a/app/components/DirectoryTreeView.tsx b/app/components/DirectoryTreeView.tsx
index 45c3de029..191a4c300 100644
--- a/app/components/DirectoryTreeView.tsx
+++ b/app/components/DirectoryTreeView.tsx
@@ -253,48 +253,50 @@ const DirectoryTreeView = forwardRef(
PlatformIO.listDirectoryPromise(subFolder.path, true)
// @ts-ignore
.then(dirEntries => {
- const directoryContent = [];
- dirEntries.map(entry => {
- if (
- entry.name === AppConfig.metaFolder ||
- entry.name.endsWith('/' + AppConfig.metaFolder) ||
- (!props.showUnixHiddenEntries && entry.name.startsWith('.'))
- ) {
- return true;
- }
- // const enhancedEntry = enhanceEntry(entry);
- if (!entry.isFile) {
- // eslint-disable-next-line no-param-reassign
- if (subFolder.accessKeyId) {
- entry.accessKeyId = subFolder.accessKeyId;
- }
- if (subFolder.bucketName) {
- entry.bucketName = subFolder.bucketName;
+ if (dirEntries !== undefined) {
+ const directoryContent = [];
+ dirEntries.map(entry => {
+ if (
+ entry.name === AppConfig.metaFolder ||
+ entry.name.endsWith('/' + AppConfig.metaFolder) ||
+ (!props.showUnixHiddenEntries && entry.name.startsWith('.'))
+ ) {
+ return true;
}
- if (subFolder.region) {
- entry.region = subFolder.region;
- }
- if (subFolder.endpointURL) {
- entry.endpointURL = subFolder.endpointURL;
+ // const enhancedEntry = enhanceEntry(entry);
+ if (!entry.isFile) {
+ // eslint-disable-next-line no-param-reassign
+ if (subFolder.accessKeyId) {
+ entry.accessKeyId = subFolder.accessKeyId;
+ }
+ if (subFolder.bucketName) {
+ entry.bucketName = subFolder.bucketName;
+ }
+ if (subFolder.region) {
+ entry.region = subFolder.region;
+ }
+ if (subFolder.endpointURL) {
+ entry.endpointURL = subFolder.endpointURL;
+ }
+ if (subFolder.secretAccessKey) {
+ entry.secretAccessKey = subFolder.secretAccessKey;
+ }
+ entry.uuid = subFolder.uuid;
+ entry.type = subFolder.type;
+ directoryContent.push(entry);
}
- if (subFolder.secretAccessKey) {
- entry.secretAccessKey = subFolder.secretAccessKey;
+ return true;
+ });
+ if (directoryContent.length > 0) {
+ // eslint-disable-next-line no-param-reassign
+ subFolder.children = directoryContent;
+ if (deepLevel > 0) {
+ const promisesArr = [];
+ directoryContent.map(directory =>
+ promisesArr.push(getDirectoriesTree(directory, deepLevel - 1))
+ );
+ return Promise.all(promisesArr);
}
- entry.uuid = subFolder.uuid;
- entry.type = subFolder.type;
- directoryContent.push(entry);
- }
- return true;
- });
- if (directoryContent.length > 0) {
- // eslint-disable-next-line no-param-reassign
- subFolder.children = directoryContent;
- if (deepLevel > 0) {
- const promisesArr = [];
- directoryContent.map(directory =>
- promisesArr.push(getDirectoriesTree(directory, deepLevel - 1))
- );
- return Promise.all(promisesArr);
}
}
return subFolder;
diff --git a/app/reducers/app.ts b/app/reducers/app.ts
index b91802210..7805de0cd 100644
--- a/app/reducers/app.ts
+++ b/app/reducers/app.ts
@@ -927,14 +927,16 @@ export const actions = {
dispatch(actions.showNotification(i18n.t('core:loading'), 'info', false));
PlatformIO.listDirectoryPromise(directoryPath, false)
.then(results => {
- prepareDirectoryContent(
- results,
- directoryPath,
- settings,
- dispatch,
- getState,
- fsEntryMeta
- );
+ if (results !== undefined) {
+ prepareDirectoryContent(
+ results,
+ directoryPath,
+ settings,
+ dispatch,
+ getState,
+ fsEntryMeta
+ );
+ }
return true;
})
.catch(error => {
@@ -2038,8 +2040,7 @@ export const actions = {
};
// Selectors
-export const currentUser = (state: any) =>
- state.app.user;
+export const currentUser = (state: any) => state.app.user;
export const getDirectoryContent = (state: any) =>
state.app.currentDirectoryEntries;
export const getCurrentDirectoryColor = (state: any) =>
diff --git a/app/services/electron-io.ts b/app/services/electron-io.ts
index c5196d669..bb7685de1 100644
--- a/app/services/electron-io.ts
+++ b/app/services/electron-io.ts
@@ -323,8 +323,9 @@ export default class ElectronIO {
const folderMetaPath =
eentry.path +
AppConfig.dirSeparator +
- AppConfig.metaFolder +
- AppConfig.dirSeparator +
+ (!eentry.path.includes('/' + AppConfig.metaFolder)
+ ? AppConfig.metaFolder + AppConfig.dirSeparator
+ : '') +
AppConfig.metaFolderFile;
try {
const folderMeta = this.fs.readJsonSync(folderMetaPath);
diff --git a/app/services/objectstore-io.ts b/app/services/objectstore-io.ts
index 7601fba10..ca137c835 100644
--- a/app/services/objectstore-io.ts
+++ b/app/services/objectstore-io.ts
@@ -75,6 +75,10 @@ export default class ObjectStoreIO {
});
getURLforPath = (path: string, expirationInSeconds: number = 900): string => {
+ if (!this.objectStore) {
+ console.log('Object store not configured in getURLforPath');
+ return '';
+ }
if (!path || path.length < 1) {
console.warn('Wrong path param for getURLforPath');
return '';
@@ -96,13 +100,13 @@ export default class ObjectStoreIO {
window.close();
};
- listMetaDirectoryPromise = async (path: string): Promise<Array<any>> => {
- const promise: Promise<Array<any>> = new Promise(resolve => {
+ listMetaDirectoryPromise = async (path: string): Promise<Array<any>> =>
+ new Promise(resolve => {
const entries = [];
let entry;
if (!this.objectStore) {
console.log('Object store not configured. Exiting');
- return false;
+ return resolve(entries);
}
const normalizedPath = normalizePath(this.normalizeRootPath(path));
@@ -146,9 +150,6 @@ export default class ObjectStoreIO {
return resolve(entries);
});
});
- const result = await promise;
- return result;
- };
listDirectoryPromise = (
path: string,
@@ -156,16 +157,17 @@ export default class ObjectStoreIO {
): Promise<Array<Object>> =>
new Promise(async resolve => {
const enhancedEntries = [];
- let entryPath;
- let metaFolderPath;
- let stats;
+ // let entryPath;
+ // let metaFolderPath;
+ // let stats;
let eentry;
- const containsMetaFolder = false;
+ // const containsMetaFolder = false;
// const metaMetaFolder = AppConfig.metaFolder + AppConfig.dirSeparator + AppConfig.metaFolder;
if (!this.objectStore) {
console.log('Object store not configured. Exiting');
- return false;
+ resolve(undefined); //enhancedEntries); empty dir is not the same with this state
+ return;
}
// this.listMetaDirectoryPromise(path).then((entries) => {
@@ -174,7 +176,10 @@ export default class ObjectStoreIO {
// }).catch((error) => {
// console.warn('Error loading meta files: ' + JSON.stringify(error));
// });
- const metaContent = await this.listMetaDirectoryPromise(path);
+ let metaContent = [];
+ if (!lite) {
+ metaContent = await this.listMetaDirectoryPromise(path);
+ }
// console.log('Meta folder content: ' + JSON.stringify(metaContent));
const params = {
@@ -239,7 +244,9 @@ export default class ObjectStoreIO {
if (eentry.path !== params.Prefix) {
// skipping the current directory
enhancedEntries.push(eentry);
- metaPromises.push(this.getEntryMeta(eentry));
+ if (!lite) {
+ metaPromises.push(this.getEntryMeta(eentry));
+ }
}
if (window.walkCanceled) {
resolve(enhancedEntries);
@@ -249,14 +256,15 @@ export default class ObjectStoreIO {
// Handling files
data.Contents.forEach(file => {
// console.warn(JSON.stringify(file));
- let thumbPath = getThumbFileLocationForFile(file.Key, '/');
- const thumbAvailable = metaContent.find(
- (obj: any) => obj.path === thumbPath
- );
- if (thumbAvailable) {
- thumbPath = this.getURLforPath(thumbPath, 604800); // 60 * 60 * 24 * 7 = 1 week
- } else {
- thumbPath = '';
+ let thumbPath = '';
+ if (!lite) {
+ const thumbFilePath = getThumbFileLocationForFile(file.Key, '/');
+ const thumbAvailable = metaContent.find(
+ (obj: any) => obj.path === thumbFilePath
+ );
+ if (thumbAvailable) {
+ thumbPath = this.getURLforPath(thumbFilePath, 604800); // 60 * 60 * 24 * 7 = 1 week
+ }
}
eentry = {};
@@ -271,12 +279,14 @@ export default class ObjectStoreIO {
if (file.Key !== params.Prefix) {
// skipping the current folder
enhancedEntries.push(eentry);
- const metaFilePath = getMetaFileLocationForFile(file.Key, '/');
- const metaFileAvailable = metaContent.find(
- (obj: any) => obj.path === metaFilePath
- );
- if (metaFileAvailable) {
- metaPromises.push(this.getEntryMeta(eentry));
+ if (!lite) {
+ const metaFilePath = getMetaFileLocationForFile(file.Key, '/');
+ const metaFileAvailable = metaContent.find(
+ (obj: any) => obj.path === metaFilePath
+ );
+ if (metaFileAvailable) {
+ metaPromises.push(this.getEntryMeta(eentry));
+ }
}
}
});
diff --git a/app/services/platform-io.ts b/app/services/platform-io.ts
index 450d778e7..fd7b2ec73 100644
--- a/app/services/platform-io.ts
+++ b/app/services/platform-io.ts
@@ -140,6 +140,12 @@ export default class PlatformIO {
tmbGenerationList: Array<string>
): Promise<any> => nativeAPI.createThumbnailsInWorker(tmbGenerationList);
+ /**
+ * Promise === undefined on error
+ * @param path
+ * @param lite
+ * @param extractText
+ */
static listDirectoryPromise = (
path: string,
lite: boolean = true,
@@ -237,11 +243,8 @@ export default class PlatformIO {
newFilePath: string
): Promise<any> => {
if (objectStoreAPI) {
- return objectStoreAPI
- .renameFilePromise(filePath, newFilePath)
- .then(result => {
- return result;
- });
+ return objectStoreAPI.renameFilePromise(filePath, newFilePath);
+ // .then(result => result);
}
PlatformIO.ignoreByWatcher(filePath, newFilePath);
diff --git a/app/services/utils-io.ts b/app/services/utils-io.ts
index 61731a521..8176df1c9 100644
--- a/app/services/utils-io.ts
+++ b/app/services/utils-io.ts
@@ -488,7 +488,7 @@ export function walkDirectory(
PlatformIO.listDirectoryPromise(path, false, mergedOptions.extractText)
// @ts-ignore
.then(entries => {
- if (window.walkCanceled) {
+ if (window.walkCanceled || entries === undefined) {
return false;
}
return Promise.all(
@@ -639,11 +639,26 @@ export async function loadSubFolders(
const subfolders = [];
let i = 0;
let isHidden = false;
- folderContent.map(entry => {
- if (!entry.isFile) {
- isHidden = entry.name.startsWith('.');
- if (isHidden) {
- if (loadHidden) {
+ if (folderContent !== undefined) {
+ folderContent.map(entry => {
+ if (!entry.isFile) {
+ isHidden = entry.name.startsWith('.');
+ if (isHidden) {
+ if (loadHidden) {
+ subfolders.push({
+ key: '0-' + (i += 1),
+ isLeaf: false,
+ name: entry.name,
+ isFile: entry.isFile,
+ lmdt: entry.lmdt,
+ meta: entry.meta,
+ path: entry.path,
+ tags: entry.tags
+ });
+ } else {
+ // do nothing
+ }
+ } else {
subfolders.push({
key: '0-' + (i += 1),
isLeaf: false,
@@ -654,24 +669,11 @@ export async function loadSubFolders(
path: entry.path,
tags: entry.tags
});
- } else {
- // do nothing
}
- } else {
- subfolders.push({
- key: '0-' + (i += 1),
- isLeaf: false,
- name: entry.name,
- isFile: entry.isFile,
- lmdt: entry.lmdt,
- meta: entry.meta,
- path: entry.path,
- tags: entry.tags
- });
}
- }
- return true;
- });
+ return true;
+ });
+ }
return subfolders;
}