Skip to content

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

Upload many files from local folder to a s3 folder in the location manager && from Desktop

stanimir4240b7edc242
diff --git a/app/components/CustomDragLayer.tsx b/app/components/CustomDragLayer.tsx
index 31e72a98d..b559b51b1 100644
--- a/app/components/CustomDragLayer.tsx
+++ b/app/components/CustomDragLayer.tsx
@@ -48,7 +48,7 @@ export const CustomDragLayer: React.FC<CustomDragLayerProps> = props => {
itemType: monitor.getItemType(),
initialOffset: monitor.getInitialSourceClientOffset(),
currentOffset: monitor.getSourceClientOffset(),
- clientOffset: monitor.getClientOffset(),
+ clientOffset: monitor.getClientOffset(),
isDragging: monitor.isDragging()
}));
diff --git a/app/components/LocationManager.tsx b/app/components/LocationManager.tsx
index 45eae4773..0f2a869fc 100644
--- a/app/components/LocationManager.tsx
+++ b/app/components/LocationManager.tsx
@@ -115,6 +115,7 @@ interface Props {
autohide: boolean
) => void;
moveFiles: (files: Array<string>, destination: string) => void;
+ uploadFiles: (files: Array<string>, destination: string) => void;
}
interface State {
@@ -611,7 +612,7 @@ class LocationManager extends React.Component<Props, State> {
return;
}
const targetPath = item.path;
- const targetLocationType = item.locationType;
+ const targetLocation = item.location;
/*if (item.children && item.children.props && item.children.props.path) {
targetPath = item.children.props.path;
} else {
@@ -620,8 +621,11 @@ class LocationManager extends React.Component<Props, State> {
if (monitor && targetPath != undefined) {
// TODO handle monitor -> isOver and change folder icon
console.log('Dropped files: ' + path);
- if (targetLocationType === locationType.TYPE_CLOUD) {
- this.props.uploadFiles(arrPath, targetPath);
+ if (targetLocation && targetLocation.type === locationType.TYPE_CLOUD) {
+ PlatformIO.enableObjectStoreSupport(targetLocation)
+ .then(() => {
+ this.props.uploadFiles(arrPath, targetPath);
+ });
} else {
//if (targetLocationType === locationType.TYPE_LOCAL) {
this.props.moveFiles(arrPath, targetPath);
@@ -724,7 +728,7 @@ class LocationManager extends React.Component<Props, State> {
)}
</ListItemIcon>
- {isCloudLocation ? (
+ {isCloudLocation && !AppConfig.isElectron ? (
<div style={{ maxWidth: 250 }}>
<Typography
variant="inherit"
@@ -737,25 +741,24 @@ class LocationManager extends React.Component<Props, State> {
</Typography>
</div>
) : (
- <TargetMoveFileBox
- // @ts-ignore
- accepts={[DragItemTypes.FILE]}
- onDrop={this.handleFileMoveDrop}
- path={location.paths[0]}
- locationType={location.type}
+ <TargetMoveFileBox
+ accepts={[DragItemTypes.FILE]}
+ onDrop={this.handleFileMoveDrop}
+ path={location.paths[0]}
+ location={location}
>
- <div style={{ maxWidth: 250 }} path={location.paths[0]}>
- <Typography
- variant="inherit"
- style={{ paddingLeft: 5, paddingRight: 5 }}
- className={this.props.classes.header}
- data-tid="locationTitleElement"
- noWrap
- >
- {location.name}
- </Typography>
- </div>
- </TargetMoveFileBox>
+ <div style={{ maxWidth: 250 }} >
+ <Typography
+ variant="inherit"
+ style={{ paddingLeft: 5, paddingRight: 5 }}
+ className={this.props.classes.header}
+ data-tid="locationTitleElement"
+ noWrap
+ >
+ {location.name}
+ </Typography>
+ </div>
+ </TargetMoveFileBox>
)}
{!isLocationsReadOnly && (
<ListItemSecondaryAction>
@@ -1000,6 +1003,7 @@ function mapDispatchToProps(dispatch) {
openFile: AppActions.openFile,
showNotification: AppActions.showNotification,
moveFiles: IOActions.moveFiles,
+ uploadFiles: IOActions.uploadFiles,
openURLExternally: AppActions.openURLExternally,
setSelectedEntries: AppActions.setSelectedEntries
},
diff --git a/app/components/menus/DirectoryMenu.tsx b/app/components/menus/DirectoryMenu.tsx
index 305d1b284..ecbf58dbe 100644
--- a/app/components/menus/DirectoryMenu.tsx
+++ b/app/components/menus/DirectoryMenu.tsx
@@ -67,6 +67,7 @@ interface Props {
reflectCreateEntry?: (path: string, isFile: boolean) => void;
toggleCreateFileDialog?: () => void;
// extractContent: (config: Object) => void,
+ uploadFilesAPI: (files: Array<File>, destination: string) => void;
switchPerspective?: (perspectiveId: string) => void;
perspectiveMode?: boolean;
showNotification?: (
@@ -228,11 +229,12 @@ const DirectoryMenu = (props: Props) => {
function handleFileInputChange(selection: any) {
// console.log("Selected File: "+JSON.stringify(selection.currentTarget.files[0]));
const file = selection.currentTarget.files[0];
+ props.uploadFilesAPI([file], props.directoryPath);
+ /*
const filePath =
normalizePath(props.directoryPath) +
PlatformIO.getDirSeparator() +
decodeURIComponent(file.name);
-
const reader = new FileReader();
reader.onload = (event: any) => {
// console.log('Content on file read complete: ' + JSON.stringify(event));
@@ -288,7 +290,7 @@ const DirectoryMenu = (props: Props) => {
reader.readAsDataURL(file);
} else {
reader.readAsArrayBuffer(file);
- }
+ } */
}
function getDirPath(dirPath: string) {
@@ -487,7 +489,8 @@ function mapDispatchToProps(dispatch) {
return bindActionCreators(
{
showNotification: AppActions.showNotification,
- extractContent: IOActions.extractContent
+ extractContent: IOActions.extractContent,
+ uploadFilesAPI: IOActions.uploadFilesAPI
},
dispatch
);
diff --git a/app/containers/MainPage.tsx b/app/containers/MainPage.tsx
index 8aa31c95a..4e2142d76 100644
--- a/app/containers/MainPage.tsx
+++ b/app/containers/MainPage.tsx
@@ -29,7 +29,7 @@ import IconButton from '@material-ui/core/IconButton';
import CloseIcon from '@material-ui/icons/Close';
import { HotKeys } from 'react-hotkeys';
import { NativeTypes } from 'react-dnd-html5-backend';
-//import { DragDropContext } from 'react-dnd';
+// import { DragDropContext } from 'react-dnd';
import VerticalNavigation from '../components/VerticalNavigation';
import MobileNavigation from '../components/MobileNavigation';
import FolderContainer from '../components/FolderContainer';
@@ -75,9 +75,7 @@ import {
isIndexing
} from '../reducers/location-index';
import { buffer } from '../utils/misc';
-import { normalizePath } from '../utils/paths';
import TargetFileBox from '../components/TargetFileBox';
-import PlatformIO from '../services/platform-io';
import AppConfig from '../config';
import buildDesktopMenu from '../services/electron-menus';
import buildTrayIconMenu from '../services/electron-tray-menu';
@@ -86,6 +84,7 @@ import { Pro } from '../pro';
import LoadingLazy from '../components/LoadingLazy';
import withDnDContext from '-/containers/withDnDContext';
import { CustomDragLayer } from '-/components/CustomDragLayer';
+import IOActions from "-/reducers/io-actions";
const initialSplitSize = 44;
const drawerWidth = 300;
@@ -202,6 +201,7 @@ interface Props {
autohide?: boolean
) => void;
reflectCreateEntry: (path: string, isFile: boolean) => void;
+ uploadFilesAPI: (files: Array<File>, destination: string) => void;
}
const AboutDialog = React.lazy(() =>
@@ -488,8 +488,8 @@ class MainPage extends Component<Props, State> {
true
);
} else {
- files.map(file => {
- // TODO move this in reducer -> look at DirectoryMenu handleFileInputChange
+ this.props.uploadFilesAPI(files, this.props.directoryPath);
+ /* files.map(file => {
let filePath = '';
let fileName = '';
try {
@@ -563,7 +563,7 @@ class MainPage extends Component<Props, State> {
reader.readAsArrayBuffer(file);
}
return file;
- });
+ }); */
}
}
};
@@ -956,7 +956,8 @@ function mapDispatchToProps(dispatch) {
openPerspectivesPanel: AppActions.openPerspectivesPanel,
openHelpFeedbackPanel: AppActions.openHelpFeedbackPanel,
closeAllVerticalPanels: AppActions.closeAllVerticalPanels,
- setFirstRun: SettingsActions.setFirstRun
+ setFirstRun: SettingsActions.setFirstRun,
+ uploadFilesAPI: IOActions.uploadFilesAPI
},
dispatch
);
diff --git a/app/reducers/io-actions.ts b/app/reducers/io-actions.ts
index 30caa206b..7f9d6d27c 100644
--- a/app/reducers/io-actions.ts
+++ b/app/reducers/io-actions.ts
@@ -28,6 +28,7 @@ import i18n from '../services/i18n';
import { Pro } from '../pro';
import TaggingActions from './tagging-actions';
import PlatformIO from '-/services/platform-io';
+import AppConfig from '-/config';
const actions = {
extractContent: (
@@ -158,6 +159,170 @@ const actions = {
AppActions.showNotification(i18n.t('core:copyingFilesFailed'))
);
});
+ },
+ /**
+ * with HTML5 Files API
+ * @param files
+ * @param targetPath
+ */
+ uploadFilesAPI: (files: Array<File>, targetPath: string) => (
+ dispatch: (actions: Object) => void
+ ) => {
+ const uploadJobs = [];
+ files.map(file => {
+ uploadJobs.push(file);
+ return true;
+ });
+ uploadJobs.map(file => {
+ const filePath =
+ normalizePath(targetPath) +
+ PlatformIO.getDirSeparator() +
+ decodeURIComponent(file.name);
+ const reader = new FileReader();
+ reader.onload = (event: any) => {
+ // TODO event.currentTarget.result is ArrayBuffer
+ // Sample call from PRO version using content = Utils.base64ToArrayBuffer(baseString);
+ PlatformIO.getPropertiesPromise(filePath)
+ .then(entryProps => {
+ if (entryProps) {
+ dispatch(
+ AppActions.showNotification(
+ 'File with the same name already exist, importing skipped!',
+ 'warning',
+ true
+ )
+ );
+ } else {
+ PlatformIO.saveBinaryFilePromise(
+ filePath,
+ event.currentTarget.result,
+ true
+ )
+ .then(() => {
+ dispatch(
+ AppActions.showNotification(
+ 'File ' + filePath + ' successfully imported.',
+ 'default',
+ true
+ )
+ );
+ dispatch(AppActions.reflectCreateEntry(filePath, true));
+ return true;
+ })
+ .catch(error => {
+ // TODO showAlertDialog("Saving " + filePath + " failed.");
+ console.error(
+ 'Save to file ' + filePath + ' failed ' + error
+ );
+ dispatch(
+ AppActions.showNotification(
+ 'Importing file ' + filePath + ' failed.',
+ 'error',
+ true
+ )
+ );
+ return true;
+ });
+ }
+ return true;
+ })
+ .catch(err => {
+ console.log('Error getting properties ' + err);
+ });
+ };
+
+ if (AppConfig.isCordova) {
+ reader.readAsDataURL(file);
+ } else {
+ reader.readAsArrayBuffer(file);
+ }
+ return file;
+ });
+ },
+ /**
+ * use with Electron only!
+ * @param paths
+ * @param targetPath
+ */
+ uploadFiles: (paths: Array<string>, targetPath: string) => (
+ dispatch: (actions: Object) => void
+ ) => {
+ const uploadJobs = [];
+ paths.map(path => {
+ uploadJobs.push([
+ path,
+ normalizePath(targetPath) +
+ PlatformIO.getDirSeparator() +
+ extractFileName(path, PlatformIO.getDirSeparator())
+ ]);
+ return true;
+ });
+ uploadJobs.map(job => {
+ // console.log("Selected File: "+JSON.stringify(selection.currentTarget.files[0]));
+ // const file = selection.currentTarget.files[0];
+ const filePath = job[1];
+ /* normalizePath(props.directoryPath) +
+ PlatformIO.getDirSeparator() +
+ decodeURIComponent(file.name); */
+
+ // TODO try to replace this with <input type="file"
+ if (AppConfig.isElectron) {
+ import('fs-extra')
+ .then(fs => {
+ const fileContent = fs.readFileSync(job[0]);
+ // TODO event.currentTarget.result is ArrayBuffer
+ // Sample call from PRO version using content = Utils.base64ToArrayBuffer(baseString);
+ PlatformIO.getPropertiesPromise(filePath)
+ .then(entryProps => {
+ if (entryProps) {
+ dispatch(
+ AppActions.showNotification(
+ 'File with the same name already exist, importing skipped!',
+ 'warning',
+ true
+ )
+ );
+ } else {
+ PlatformIO.saveBinaryFilePromise(filePath, fileContent, true)
+ .then(() => {
+ dispatch(
+ AppActions.showNotification(
+ 'File ' + filePath + ' successfully imported.',
+ 'default',
+ true
+ )
+ );
+ dispatch(AppActions.reflectCreateEntry(filePath, true));
+ return true;
+ })
+ .catch(err => {
+ // TODO showAlertDialog("Saving " + filePath + " failed.");
+ console.error(
+ 'Save to file ' + filePath + ' failed ' + err
+ );
+ dispatch(
+ AppActions.showNotification(
+ 'Importing file ' + filePath + ' failed.',
+ 'error',
+ true
+ )
+ );
+ return true;
+ });
+ }
+ return true;
+ })
+ .catch(err => {
+ console.log('Error getting properties ' + err);
+ });
+ return true;
+ })
+ .catch(err => {
+ console.log('Error import fs: ' + err);
+ });
+ }
+ return true;
+ });
}
};