TagSpaces is an offline, open source, document manager with tagging support
Handle rename and upload on read-only s3 connection (#1258)
Stanimir8196ae1eba09
diff --git a/app/components/EntryProperties.tsx b/app/components/EntryProperties.tsxindex f0335f849..ca6f13581 100644--- a/app/components/EntryProperties.tsx+++ b/app/components/EntryProperties.tsx@@ -174,8 +174,8 @@ interface Props {classes: any;theme: any;openedEntry: OpenedEntry;- renameFile: (path: string, nextPath: string) => void;- renameDirectory: (path: string, nextPath: string) => void;+ renameFile: (path: string, nextPath: string) => Promise<boolean>;+ renameDirectory: (path: string, nextPath: string) => Promise<boolean>;showNotification: (message: string) => void;updateOpenedFile: (entryPath: string, fsEntryMeta: any) => void;updateThumbnailUrl: (path: string, thumbUrl: string) => void;@@ -291,12 +291,19 @@ const EntryProperties = (props: Props) => {const nextPath = path + PlatformIO.getDirSeparator() + editName;if (currentEntry.isFile) {- renameFile(currentEntry.path, nextPath);+ renameFile(currentEntry.path, nextPath)+ .then(() => true)+ .catch(() => {+ fileNameRef.current.value = entryName;+ });} else {- renameDirectory(currentEntry.path, editName);+ renameDirectory(currentEntry.path, editName)+ .then(() => true)+ .catch(() => {+ fileNameRef.current.value = entryName;+ });}- // newName = '';setEditName(undefined);}};diff --git a/app/reducers/app.ts b/app/reducers/app.tsindex 030b06d08..00a0d8879 100644--- a/app/reducers/app.ts+++ b/app/reducers/app.ts@@ -901,9 +901,12 @@ export const actions = {function loadDirectoryContentInt(fsEntryMeta?: FileSystemEntryMeta) {// Uncomment the following line will to clear all content before loading new dir contentdispatch(actions.loadDirectorySuccessInt(directoryPath, [], true)); // this is to reset directoryContent (it will reset color too)- const location = extractLocation(directoryPath, locations);- if (location !== undefined) {- dispatch(actions.changeLocation(location));+ if (directoryPath) {+ // TODO move changeLocation in DirTree+ const location = extractLocation(directoryPath, locations);+ if (location !== undefined) {+ dispatch(actions.changeLocation(location));+ }}// dispatch(actions.setCurrentDirectoryColor('')); // this is to reset color onlydispatch(actions.showNotification(i18n.t('core:loading'), 'info', false));@@ -1061,7 +1064,7 @@ export const actions = {},renameDirectory: (directoryPath: string, newDirectoryName: string) => (dispatch: (actions: Object) => void- ) => {+ ) =>PlatformIO.renameDirectoryPromise(directoryPath, newDirectoryName).then(newDirPath => {dispatch(actions.reflectRenameEntry(directoryPath, newDirPath));@@ -1089,8 +1092,8 @@ export const actions = {true));- });- },+ throw error;+ }),createDirectory: (directoryPath: string) => (dispatch: (actions: Object) => void) => {@@ -1709,6 +1712,7 @@ export const actions = {true));+ throw error;}),openFileNatively: (selectedFile: string) => () => {PlatformIO.openFile(selectedFile);diff --git a/app/reducers/io-actions.ts b/app/reducers/io-actions.tsindex ab0eaa009..f2603c64e 100644--- a/app/reducers/io-actions.ts+++ b/app/reducers/io-actions.ts@@ -20,7 +20,6 @@ import { Progress } from 'aws-sdk/clients/s3';import { actions as AppActions } from './app';import {extractFileName,- getMetaFileLocationForDir,getMetaFileLocationForFile,getThumbFileLocationForFile,normalizePath@@ -29,7 +28,6 @@ import {copyFilesPromise,enhanceEntry,FileSystemEntry,- loadJSONFile,loadJSONString,renameFilesPromise} from '-/services/utils-io';@@ -285,7 +283,7 @@ const actions = {targetPath: string,onUploadProgress?: (progress: Progress, response: any) => void) => (dispatch: (actions: Object) => void) =>- new Promise(resolve => {+ new Promise((resolve, reject) => {const uploadJobs = [];paths.map(path => {let target =@@ -410,54 +408,59 @@ const actions = {}return true;});- dispatch(- AppActions.showNotification(- 'File ' +- arrFiles.map(file => file.name).toString() +- ' successfully imported.',- 'default',- true- )- );+ if (arrFiles.length > 0) {+ dispatch(+ AppActions.showNotification(+ 'File ' ++ arrFiles.map(file => file.name).toString() ++ ' successfully imported.',+ 'default',+ true+ )+ );- // Enhance entries- resolve(- arrFiles.map((file: FileSystemEntry) => {- const metaFilePath = getMetaFileLocationForFile(- file.path,- AppConfig.dirSeparator- ).replace(/[/\\]/g, '');- const thumbFilePath = getThumbFileLocationForFile(- file.path,- AppConfig.dirSeparator- ).replace(/[/\\]/g, '');- for (let i = 0; i < arrMeta.length; i += 1) {- const metaFile = arrMeta[i];- if (metaFile.path.replace(/[/\\]/g, '') === metaFilePath) {- // eslint-disable-next-line no-param-reassign- file.meta = metaFile.meta;+ // Enhance entries+ resolve(+ arrFiles.map((file: FileSystemEntry) => {+ const metaFilePath = getMetaFileLocationForFile(+ file.path,+ AppConfig.dirSeparator+ ).replace(/[/\\]/g, '');+ const thumbFilePath = getThumbFileLocationForFile(+ file.path,+ AppConfig.dirSeparator+ ).replace(/[/\\]/g, '');+ for (let i = 0; i < arrMeta.length; i += 1) {+ const metaFile = arrMeta[i];+ if (metaFile.path.replace(/[/\\]/g, '') === metaFilePath) {+ // eslint-disable-next-line no-param-reassign+ file.meta = metaFile.meta;+ }}- }- for (let i = 0; i < arrThumb.length; i += 1) {- const thumbFile = arrThumb[i];- if (thumbFile.path.replace(/[/\\]/g, '') === thumbFilePath) {- // eslint-disable-next-line no-param-reassign- file.thumbPath = PlatformIO.getURLforPath(- thumbFile.thumbPath- );+ for (let i = 0; i < arrThumb.length; i += 1) {+ const thumbFile = arrThumb[i];+ if (thumbFile.path.replace(/[/\\]/g, '') === thumbFilePath) {+ // eslint-disable-next-line no-param-reassign+ file.thumbPath = PlatformIO.getURLforPath(+ thumbFile.thumbPath+ );+ }}- }- if (file.meta) {- return enhanceEntry(file);- }- return file;- })- );-+ if (file.meta) {+ return enhanceEntry(file);+ }+ return file;+ })+ );+ } else {+ // eslint-disable-next-line prefer-promise-reject-errors+ reject('Upload failed');+ }return true;}).catch(err => {console.log('Error import fs: ' + err);+ reject(err);});})};