Skip to content

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

done AWS Impl

Stanimir Marinovc9b107377142
diff --git a/app/components/LocationManager.js b/app/components/LocationManager.js
index dea97848c..8c9a88eea 100644
--- a/app/components/LocationManager.js
+++ b/app/components/LocationManager.js
@@ -272,7 +272,7 @@ class LocationManager extends React.Component<Props, State> {
// <Tooltip id="tooltip-icon" title={i18n.t('core:moreOperations')} placement="bottom"></Tooltip>
renderLocation = (location: Location) => (
<ListItem
- data-tid={'location_' + location.name.replace(/ /g,'_')}
+ data-tid={'location_' + location.name.replace(/ /g, '_')}
className={
this.props.currentLocationId === location.uuid
? this.props.classes.listItemSelected
diff --git a/app/components/dialogs/CreateLocationDialog.js b/app/components/dialogs/CreateLocationDialog.js
index cd0b07ba9..133547013 100644
--- a/app/components/dialogs/CreateLocationDialog.js
+++ b/app/components/dialogs/CreateLocationDialog.js
@@ -43,7 +43,7 @@ import GenericDialog, { onEnterKeyHandler } from './GenericDialog';
import i18n from '../../services/i18n';
import PlatformIO from '../../services/platform-io';
import { extractDirectoryName } from '../../utils/paths';
-import { type Location } from '../../reducers/locations';
+import { type Location, locationType } from '../../reducers/locations';
import AppConfig from '../../config';
import { Pro } from '../../pro';
import ObjectStoreForm from './ObjectStoreForm';
@@ -100,7 +100,7 @@ class CreateLocationDialog extends React.Component<Props, State> {
isReadOnly: false,
watchForChanges: false,
persistIndex: false,
- type: 'local'
+ type: locationType.TYPE_LOCAL
};
componentWillReceiveProps = (nextProps: any) => {
@@ -122,8 +122,13 @@ class CreateLocationDialog extends React.Component<Props, State> {
const target = event.target;
const value = target.type === 'checkbox' ? target.checked : target.value;
const name = target.name;
-
- this.handleChange(name, value);
+ if (target.type === 'radio') { // type is changed (skip validation)
+ this.setState({
+ [name]: value
+ });
+ } else {
+ this.handleChange(name, value);
+ }
};
handleChange = (name, value) => {
@@ -135,24 +140,48 @@ class CreateLocationDialog extends React.Component<Props, State> {
handleValidation() {
// const pathRegex = this.state.path.match('^((\.\./|[a-zA-Z0-9_/\-\\])*\.[a-zA-Z0-9]+)$');
// const nameRegex = this.state.name.match('^[A-Z][-a-zA-Z]+$');
- if (this.state.type === 'local') {
- if (this.state.path && this.state.path.length > 0) {
- this.setState({ errorTextPath: false, disableConfirmButton: false });
- } else {
- this.setState({ errorTextPath: true, disableConfirmButton: true });
+ if (this.state.type === locationType.TYPE_LOCAL) {
+ let errorTextName = false;
+ let errorTextPath = false;
+ let disableConfirmButton = false;
+ if (!this.state.name || this.state.name.length === 0) {
+ errorTextName = true;
+ disableConfirmButton = true;
+ }
+
+ if (!this.state.path || this.state.path.length === 0) {
+ errorTextPath = true;
+ disableConfirmButton = true;
+ }
+
+ this.setState({ errorTextName, errorTextPath, disableConfirmButton });
+ } else if (this.state.type === locationType.TYPE_CLOUD) {
+ let cloudErrorTextName = false;
+ let cloudErrorTextPath = false;
+ let cloudErrorAccessKey = false;
+ let cloudErrorSecretAccessKey = false;
+ let disableConfirmButton = false;
+ if (!this.state.storeName || this.state.storeName.length === 0) {
+ cloudErrorTextName = true;
+ disableConfirmButton = true;
+ }
+
+ if (!this.state.storePath || this.state.storePath.length === 0) {
+ cloudErrorTextPath = true;
+ disableConfirmButton = true;
}
- if (this.state.name && this.state.name.length > 0) {
- this.setState({ errorTextName: false, disableConfirmButton: false });
- } else {
- this.setState({ errorTextName: true, disableConfirmButton: true });
+ if (!this.state.accessKeyId || this.state.accessKeyId.length === 0) {
+ cloudErrorAccessKey = true;
+ disableConfirmButton = true;
}
- } else if (this.state.type === 'cloud') {
- if (this.state.name && this.state.name.length > 0) {
- this.setState({ errorTextName: false, disableConfirmButton: false });
- } else {
- this.setState({ errorTextName: true, disableConfirmButton: true });
+
+ if (!this.state.secretAccessKey || this.state.secretAccessKey.length === 0) {
+ cloudErrorSecretAccessKey = true;
+ disableConfirmButton = true;
}
+
+ this.setState({ cloudErrorTextName, cloudErrorTextPath, cloudErrorAccessKey, cloudErrorSecretAccessKey, disableConfirmButton });
}
}
@@ -176,22 +205,52 @@ class CreateLocationDialog extends React.Component<Props, State> {
onConfirm = () => {
if (!this.state.disableConfirmButton) {
- this.props.addLocation({
- uuid: uuidv1(),
- name: this.state.name,
- paths: [this.state.path],
- perspective: this.state.perspective,
- isDefault: this.state.isDefault,
- isReadOnly: this.state.isReadOnly,
- persistIndex: this.state.persistIndex,
- watchForChanges: this.state.watchForChanges
- });
- this.setState({
- open: false,
- errorTextPath: false,
- errorTextName: false,
- disableConfirmButton: true
- });
+ if (this.state.type === locationType.TYPE_LOCAL) {
+ this.props.addLocation({
+ uuid: uuidv1(),
+ type: locationType.TYPE_LOCAL,
+ name: this.state.name,
+ paths: [this.state.path],
+ perspective: this.state.perspective,
+ isDefault: this.state.isDefault,
+ isReadOnly: this.state.isReadOnly,
+ persistIndex: this.state.persistIndex,
+ watchForChanges: this.state.watchForChanges
+ });
+ this.setState({
+ open: false,
+ errorTextPath: false,
+ errorTextName: false,
+ disableConfirmButton: true
+ });
+ } else if (this.state.type === locationType.TYPE_CLOUD) {
+ this.props.addLocation({
+ uuid: uuidv1(),
+ type: locationType.TYPE_CLOUD,
+ name: this.state.storeName,
+ paths: [this.state.storePath],
+ accessKeyId: this.state.accessKeyId,
+ secretAccessKey: this.state.secretAccessKey,
+ bucketName: this.state.bucketName,
+ region: this.state.region.value,
+ perspective: this.state.perspective,
+ isDefault: this.state.isDefault,
+ isReadOnly: this.state.isReadOnly,
+ persistIndex: this.state.persistIndex,
+ watchForChanges: this.state.watchForChanges
+ });
+ /* this.setState({
+ open: false,
+ errorTextPath: false,
+ errorTextName: false,
+ cloudErrorTextName: false,
+ cloudErrorTextPath: false,
+ cloudErrorAccessKey: false,
+ cloudErrorSecretAccessKey: false,
+ disableConfirmButton: true
+ }); */
+ this.setState({});
+ }
this.props.onClose();
}
};
@@ -203,17 +262,17 @@ class CreateLocationDialog extends React.Component<Props, State> {
renderContent = () => {
const { classes } = this.props;
let content;
- if (this.state.type === 'cloud') {
+ if (this.state.type === locationType.TYPE_CLOUD) {
content = (<ObjectStoreForm handleInputChange={this.handleInputChange} handleChange={this.handleChange} state={this.state} />);
} else {
content = (
<div>
<FormControl
fullWidth={true}
- error={this.state.errorTextPath}
+ error={this.state.errorTextName}
>
<TextField
- error={this.state.errorTextPath}
+ error={this.state.errorTextName}
required
margin="dense"
name="name"
@@ -223,7 +282,7 @@ class CreateLocationDialog extends React.Component<Props, State> {
data-tid="locationName"
fullWidth={true}
/>
- {this.state.errorTextName && <FormHelperText>Invalid Name</FormHelperText>}
+ {this.state.errorTextName && <FormHelperText>{i18n.t('core:invalidName')}</FormHelperText>}
</FormControl>
<FormControl
fullWidth={true}
@@ -269,8 +328,8 @@ class CreateLocationDialog extends React.Component<Props, State> {
onChange={this.handleInputChange}
row
>
- <FormControlLabel value="local" control={<Radio />} label="Local" />
- <FormControlLabel value="cloud" control={<Radio />} label="Cloud (S3 AWS)" />
+ <FormControlLabel value={locationType.TYPE_LOCAL} control={<Radio />} label="Local" />
+ <FormControlLabel value={locationType.TYPE_CLOUD} control={<Radio />} label="Cloud (S3 AWS)" />
</RadioGroup>
</Grid>
</Grid>
diff --git a/app/components/dialogs/ObjectStoreForm.js b/app/components/dialogs/ObjectStoreForm.js
index 8d40d9eb4..8149ad590 100644
--- a/app/components/dialogs/ObjectStoreForm.js
+++ b/app/components/dialogs/ObjectStoreForm.js
@@ -231,7 +231,7 @@ class IntegrationReactSelect extends React.Component<Props> {
<Grid item xs={12}>
<FormControl
fullWidth={true}
- error={state.errorTextPath}
+ error={state.cloudErrorTextName}
>
<InputLabel htmlFor="storeName">{i18n.t('core:createLocationName')}</InputLabel>
<Input
@@ -244,13 +244,13 @@ class IntegrationReactSelect extends React.Component<Props> {
onChange={handleInputChange}
value={state.storeName}
/>
- {state.errorTextPath && <FormHelperText>{i18n.t('core:invalidPath')}</FormHelperText>}
+ {state.cloudErrorTextName && <FormHelperText>{i18n.t('core:invalidName')}</FormHelperText>}
</FormControl>
</Grid>
<Grid item xs={12}>
<FormControl
fullWidth={true}
- error={state.errorTextPath}
+ error={state.cloudErrorTextPath}
>
<InputLabel htmlFor="path">{i18n.t('core:createLocationPath')}</InputLabel>
<Input
@@ -263,32 +263,32 @@ class IntegrationReactSelect extends React.Component<Props> {
onChange={handleInputChange}
value={state.storePath}
/>
- {state.errorTextPath && <FormHelperText>{i18n.t('core:invalidPath')}</FormHelperText>}
+ {state.cloudErrorTextPath && <FormHelperText>{i18n.t('core:invalidPath')}</FormHelperText>}
</FormControl>
</Grid>
<Grid item xs={12}>
<FormControl
fullWidth={true}
- error={state.errorTextPath}
+ error={state.cloudErrorAccessKey}
>
- <InputLabel htmlFor="accessKey">{i18n.t('core:accessKeyId')}</InputLabel>
+ <InputLabel htmlFor="accessKeyId">{i18n.t('core:accessKeyId')}</InputLabel>
<Input
required
margin="dense"
- name="accessKey"
+ name="accessKeyId"
label={i18n.t('core:accessKeyId')}
fullWidth={true}
data-tid="accessKeyId"
onChange={handleInputChange}
- value={state.accessKey}
+ value={state.accessKeyId}
/>
- {state.errorTextPath && <FormHelperText>{i18n.t('core:invalidPath')}</FormHelperText>}
+ {state.cloudErrorAccessKey && <FormHelperText>{i18n.t('core:invalidAccessKey')}</FormHelperText>}
</FormControl>
</Grid>
<Grid item xs={12}>
<FormControl
fullWidth={true}
- error={state.errorTextPath}
+ error={state.cloudErrorSecretAccessKey}
>
<InputLabel htmlFor="secretAccessKey">{i18n.t('core:secretAccessKey')}</InputLabel>
<Input
@@ -301,13 +301,11 @@ class IntegrationReactSelect extends React.Component<Props> {
onChange={handleInputChange}
value={state.secretAccessKey}
/>
- {state.errorTextPath && <FormHelperText>{i18n.t('core:invalidPath')}</FormHelperText>}
+ {state.cloudErrorSecretAccessKey && <FormHelperText>{i18n.t('core:invalidSecretAccessKey')}</FormHelperText>}
</FormControl>
</Grid>
<Grid item xs={6}>
- <FormControl
- error={state.errorTextPath}
- >
+ <FormControl>
<InputLabel htmlFor="bucketName">{i18n.t('core:bucketName')}</InputLabel>
<Input
required
@@ -319,7 +317,6 @@ class IntegrationReactSelect extends React.Component<Props> {
onChange={handleInputChange}
value={state.bucketName}
/>
- {state.errorTextPath && <FormHelperText>{i18n.t('core:invalidPath')}</FormHelperText>}
</FormControl>
</Grid>
<Grid item xs={6}>
@@ -334,7 +331,6 @@ class IntegrationReactSelect extends React.Component<Props> {
onChange={this.handleChange('region')}
placeholder="Search a region"
/>
- {state.errorTextPath && <FormHelperText>{i18n.t('core:invalidPath')}</FormHelperText>}
</NoSsr>
</Grid>
</Grid>
diff --git a/app/reducers/app.js b/app/reducers/app.js
index c6e29b3cd..ce74c69d2 100644
--- a/app/reducers/app.js
+++ b/app/reducers/app.js
@@ -17,10 +17,10 @@
* @flow
*/
-import { type Location, getLocation } from './locations';
+import uuidv1 from 'uuid';
+import { type Location, getLocation, locationType } from './locations';
import PlatformIO from '../services/platform-io';
import Search, { type SearchQuery } from '../services/search';
-import uuidv1 from 'uuid';
import AppConfig from '../config';
import {
type FileSystemEntry,
@@ -313,8 +313,8 @@ export default (state: Object = initialState, action: Object) => {
}
case types.UPDATE_THUMB_URLS: {
const dirEntries = [...state.currentDirectoryEntries];
- for (let entry of dirEntries) {
- for (let tmbUrl of action.tmbURLs) {
+ for (const entry of dirEntries) {
+ for (const tmbUrl of action.tmbURLs) {
if (entry.path === tmbUrl.filePath) {
entry.thumbPath = tmbUrl.tmbPath;
break;
@@ -622,7 +622,7 @@ export const actions = {
// actions.showNotification('Please first open a folder!', 'warning', true)
// );
// } else {
- dispatch(actions.toggleSelectDirectoryDialog());
+ dispatch(actions.toggleSelectDirectoryDialog());
// }
},
toggleAboutDialog: () => ({ type: types.TOGGLE_ABOUT_DIALOG }),
@@ -929,6 +929,11 @@ export const actions = {
locations.map(location => {
if (location.uuid === locationId) {
+ if (location.type === locationType.TYPE_CLOUD) {
+ PlatformIO.enableObjectStoreSupport(location);
+ } else if (location.type === locationType.TYPE_LOCAL) {
+ PlatformIO.disableObjectStoreSupport();
+ }
// location.paths = ['test/']; // TODO remove
dispatch(actions.setReadOnlyMode(location.isReadOnly || false));
dispatch(actions.setCurrentLocationId(location.uuid));
diff --git a/app/reducers/locations.js b/app/reducers/locations.js
index 3c4b85440..ec8ed4664 100644
--- a/app/reducers/locations.js
+++ b/app/reducers/locations.js
@@ -30,11 +30,19 @@ export const types = {
REMOVE_LOCATION: 'APP/REMOVE_LOCATION'
};
+export const locationType = {
+ TYPE_LOCAL: '0',
+ TYPE_CLOUD: '1',
+};
+
export type Location = {
uuid: string,
name: string,
- type: number,
- awsKey: string, // TODO
+ type: string,
+ accessKeyId: string,
+ secretAccessKey: string,
+ bucketName: string,
+ region: string,
paths: Array<string>,
perspective?: string, // id of the perspective
creationDate?: string,
@@ -51,6 +59,7 @@ const devicePaths = PlatformIO.getDevicePaths();
Object.keys(devicePaths).forEach(key => {
initialState.push({
uuid: uuidv1(),
+ type: locationType.TYPE_LOCAL,
name: key, // TODO use i18n
paths: [devicePaths[key]],
isDefault: false,
@@ -71,8 +80,13 @@ export default (state: Array<Location> = initialState, action: Object) => {
...state,
{
uuid: action.location.uuid || uuidv1(),
+ type: action.location.type,
name: action.location.name,
paths: action.location.paths,
+ accessKeyId: action.location.accessKeyId,
+ secretAccessKey: action.location.secretAccessKey,
+ bucketName: action.location.bucketName,
+ region: action.location.region,
perspective: action.location.perspective,
creationDate: new Date().toJSON(),
isDefault: action.location.isDefault,