TagSpaces is an offline, open source, document manager with tagging support
TSN288 Dir properties for S3 (#1104)
Stanimira390b94a7095
diff --git a/app/components/EntryContainer.tsx b/app/components/EntryContainer.tsxindex adec75310..8df011cb4 100644--- a/app/components/EntryContainer.tsx+++ b/app/components/EntryContainer.tsx@@ -1024,7 +1024,12 @@ class EntryContainer extends React.Component<Props, State> {? i18n.t('core:doYouWantToDeleteFile'): i18n.t('core:deleteDirectoryContentConfirm', {dirPath: currentEntry- ? extractDirectoryName(currentEntry.path)+ ? extractDirectoryName(+ currentEntry.path,+ PlatformIO.haveObjectStoreSupport()+ ? '/'+ : AppConfig.dirSeparator+ ): ''})}diff --git a/app/components/menus/DirectoryMenu.tsx b/app/components/menus/DirectoryMenu.tsxindex 3210ccf5f..2988f8271 100644--- a/app/components/menus/DirectoryMenu.tsx+++ b/app/components/menus/DirectoryMenu.tsx@@ -290,7 +290,10 @@ const DirectoryMenu = (props: Props) => {}function getDirPath(dirPath: string) {- const fileName = extractFileName(dirPath);+ const fileName = extractFileName(+ dirPath,+ PlatformIO.haveObjectStoreSupport() ? '/' : AppConfig.dirSeparator+ );return props.directoryPath && fileName? fileName: cleanTrailingDirSeparator(props.directoryPath);diff --git a/app/reducers/app.ts b/app/reducers/app.tsindex 355c4ad7c..7bb1b902a 100644--- a/app/reducers/app.ts+++ b/app/reducers/app.ts@@ -383,10 +383,11 @@ export default (state: any = initialState, action: any) => {);if (entryIndex < 0 &&- extractParentDirectoryPath(action.newEntry.path).replace(- /(^\/)|(\/$)/g,- ''- ) === state.currentDirectoryPath.replace(/(^\/)|(\/$)/g, '')+ extractParentDirectoryPath(+ action.newEntry.path,+ PlatformIO.haveObjectStoreSupport() ? '/' : AppConfig.dirSeparator+ ).replace(/(^\/)|(\/$)/g, '') ===+ state.currentDirectoryPath.replace(/(^\/)|(\/$)|(^\\)|(\\$)/g, '')) {return {...state,@@ -759,7 +760,12 @@ export const actions = {dispatch(actions.showNotification(i18n.t('deletingDirectorySuccessfull', {- dirPath: extractDirectoryName(directoryPath)+ dirPath: extractDirectoryName(+ directoryPath,+ PlatformIO.haveObjectStoreSupport()+ ? '/'+ : AppConfig.dirSeparator+ )}),'default',true@@ -772,7 +778,12 @@ export const actions = {dispatch(actions.showNotification(i18n.t('errorDeletingDirectoryAlert', {- dirPath: extractDirectoryName(directoryPath)+ dirPath: extractDirectoryName(+ directoryPath,+ PlatformIO.haveObjectStoreSupport()+ ? '/'+ : AppConfig.dirSeparator+ )}),'error',true@@ -819,7 +830,11 @@ export const actions = {dispatch: (actions: Object) => void) => {PlatformIO.createDirectoryPromise(directoryPath)- .then(() => {+ .then(normalizedDirPath => {+ if (normalizedDirPath !== undefined) {+ // eslint-disable-next-line no-param-reassign+ directoryPath = normalizedDirPath;+ }console.log(`Creating directory ${directoryPath} successful.`);dispatch(actions.reflectCreateEntry(directoryPath, false));dispatch(@@ -1202,7 +1217,7 @@ export const actions = {) => {const newEntry = {uuid: uuidv1(),- name: extractFileName(path),+ name: isFile ? extractFileName(path) : extractDirectoryName(path),isFile,extension: extractFileExtension(path),description: '',diff --git a/app/utils/paths.ts b/app/utils/paths.tsindex 2d735ecaf..347351296 100644--- a/app/utils/paths.ts+++ b/app/utils/paths.ts@@ -187,7 +187,12 @@ export function extractParentDirectoryPath(if (path.endsWith(dirSeparator)) {path = path.substring(0, path.lastIndexOf(dirSeparator));}- return path.substring(0, path.lastIndexOf(dirSeparator));+ const lastIndex = path.lastIndexOf(dirSeparator);+ if (lastIndex !== -1) {+ return path.substring(0, lastIndex);+ }+ //return root dir in cases that dirPath not start with dirSeparator (AWS)+ return '';}export function extractDirectoryName(@@ -195,14 +200,22 @@ export function extractDirectoryName(dirSeparator: string = AppConfig.dirSeparator): string {if (!dirPath) return '';- let directoryName;- if (dirPath.endsWith(dirSeparator)) {- directoryName = dirPath.substring(0, dirPath.lastIndexOf(dirSeparator));+ let directoryName = dirPath;+ if (dirPath.indexOf(dirSeparator) !== -1) {+ if (dirPath.endsWith(dirSeparator)) {+ directoryName = directoryName.substring(+ 0,+ dirPath.lastIndexOf(dirSeparator)+ );+ }+ const lastDirSeparator = directoryName.lastIndexOf(dirSeparator);+ if (lastDirSeparator !== -1) {+ directoryName = directoryName.substring(+ lastDirSeparator + 1,+ directoryName.length+ );+ }}- directoryName = dirPath.substring(- dirPath.lastIndexOf(dirSeparator) + 1,- dirPath.length- );return directoryName;}@@ -231,7 +244,7 @@ export function extractContainingDirectoryName(filePath: string) {export function extractTitle(entryPath: string, isDirectory: boolean = false) {let title;if (isDirectory) {- title = extractDirectoryName(entryPath);+ title = extractDirectoryName(entryPath).replace(/(^\/)|(\/$)/g, '');return title;}title = extractFileNameWithoutExt(entryPath);