diff --git a/src/constants.js b/src/constants.js index 28e36dc..42d16df 100644 --- a/src/constants.js +++ b/src/constants.js @@ -76,9 +76,16 @@ exports.REPERTORY_LOCATIONS = { win32: '%LOCALAPPDATA%\\repertory', }; -exports.S3_PROVIDER_LIST = ['Filebase']; +const _S3_CUSTOM_PROVIDER = 'Custom...'; +exports.S3_CUSTOM_PROVIDER = _S3_CUSTOM_PROVIDER; +exports.S3_PROVIDER_LIST = ['Filebase', _S3_CUSTOM_PROVIDER]; -exports.S3_REGION_PROVIDER_REGION = ['us-east-1']; +const _S3_CUSTOM_REGION = 'Custom...'; +exports.S3_CUSTOM_REGION = _S3_CUSTOM_REGION; +exports.S3_REGION_PROVIDER_REGION = [ + ['us-east-1', _S3_CUSTOM_REGION], + ['any', _S3_CUSTOM_REGION], +]; exports.S3_PROVIDER_URL = { Filebase: 'https://s3.filebase.com', diff --git a/src/containers/AddMount/AddMount.js b/src/containers/AddMount/AddMount.js index 061dd88..d3da298 100644 --- a/src/containers/AddMount/AddMount.js +++ b/src/containers/AddMount/AddMount.js @@ -21,9 +21,11 @@ const default_state = { Name: '', Port: 20000, Provider: Constants.S3_PROVIDER_LIST[0], - Region: Constants.S3_REGION_PROVIDER_REGION[0], + Region: Constants.S3_REGION_PROVIDER_REGION[0][0], SecretKey: '', Token: '', + CustomURL: '', + CustomRegion: '', }; class AddMount extends Component { @@ -55,12 +57,18 @@ class AddMount extends Component { }; addS3Mount = () => { + const isCustomProvider = this.state.Provider === Constants.S3_CUSTOM_PROVIDER; + const isCustomRegion = this.state.Region === Constants.S3_CUSTOM_REGION; if (this.state.Name.length === 0) { this.props.notifyError('Name cannot be empty.'); } else if (this.state.AccessKey.length === 0) { this.props.notifyError('AccessKey cannot be empty.'); } else if (this.state.SecretKey.length === 0) { this.props.notifyError('SecretKey cannot be empty.'); + } else if (isCustomProvider && !this.state.CustomURL.trim()) { + this.props.notifyError('Custom URL cannot be empty.'); + } else if (isCustomRegion && !this.state.CustomRegion.trim()) { + this.props.notifyError('Custom Region cannot be empty.'); } else { const provider = 'S3' + this.state.Name; if (this.props.S3Mounts.includes(provider)) { @@ -75,9 +83,11 @@ class AddMount extends Component { this.state.Name, this.state.AccessKey, this.state.SecretKey, - this.state.Region, + isCustomRegion ? this.state.CustomRegion : this.state.Region, this.state.BucketName, - Constants.S3_PROVIDER_URL[this.state.Provider] + isCustomProvider + ? this.state.CustomURL + : Constants.S3_PROVIDER_URL[this.state.Provider] ); this.setState({ ...default_state, @@ -190,12 +200,37 @@ class AddMount extends Component { />