@@ -144,6 +144,34 @@ export default class RepoCreateStore extends Store {
144144 . join ( '&' ) ;
145145 }
146146
147+ @action
148+ validateRepoCredential = async ( ) => {
149+ if ( ! this . url || ! this . accessKey || ! this . secretKey ) {
150+ return this . info ( ts ( 'Information to be verified is incomplete!' ) ) ;
151+ }
152+
153+ // format s3 url
154+ const url = this . url . startsWith ( 's3://' ) ? this . url : `s3://${ this . url } ` ;
155+ if ( ! s3UrlPattern . test ( url ) ) {
156+ return this . info ( ts ( 'Invalid s3 url, should be like s3://s3.pek3a.qingstor.com/op-repo' ) ) ;
157+ }
158+
159+ const params = {
160+ type : this . protocolType ,
161+ url : url ,
162+ credential : JSON . stringify ( {
163+ access_key_id : this . accessKey ,
164+ secret_access_key : this . secretKey
165+ } )
166+ } ;
167+ const result = await this . request . get ( 'repos/validate' , params ) ;
168+ if ( result && result . ok ) {
169+ this . success ( ts ( 'Access key verification successfully' ) ) ;
170+ } else {
171+ this . error ( ts ( 'Access key verification fail' ) ) ;
172+ }
173+ } ;
174+
147175 @action
148176 handleSubmit = async e => {
149177 e . preventDefault ( ) ;
@@ -216,10 +244,17 @@ export default class RepoCreateStore extends Store {
216244
217245 this . isLoading = true ;
218246 if ( this . repoId ) {
219- delete data . url ;
220- if ( ! accessKey ) {
247+ if ( ! accessKey || ! secretKey ) {
248+ delete data . url ;
221249 delete data . credential ;
250+ } else {
251+ data . url = this . url ;
252+ data . credential = JSON . stringify ( {
253+ access_key_id : accessKey ,
254+ secret_access_key : secretKey
255+ } ) ;
222256 }
257+
223258 _ . extend ( data , { repo_id : this . repoId } ) ;
224259 await this . modifyRepo ( data ) ;
225260 } else {
@@ -230,24 +265,23 @@ export default class RepoCreateStore extends Store {
230265 this . success ( ts ( 'Modify repo successfully' ) ) ;
231266 } else if ( _ . get ( this , 'repoCreated.repo_id' ) ) {
232267 this . success ( ts ( 'Create repo successfully' ) ) ;
268+ } else {
269+ return this . repoCreated ;
233270 }
234-
235- // disable re-submit form in 1 sec
236- setTimeout ( ( ) => {
237- this . isLoading = false ;
238- } , 1000 ) ;
239271 } ;
240272
241273 @action
242274 async create ( params ) {
243275 params = typeof params === 'object' ? params : JSON . stringify ( params ) ;
244276 this . repoCreated = await this . request . post ( 'repos' , params ) ;
277+ this . isLoading = false ;
245278 }
246279
247280 @action
248281 async modifyRepo ( params ) {
249282 params = typeof params === 'object' ? params : JSON . stringify ( params ) ;
250283 this . repoCreated = await this . request . patch ( 'repos' , params ) ;
284+ this . isLoading = false ;
251285 }
252286
253287 @action
@@ -273,12 +307,16 @@ export default class RepoCreateStore extends Store {
273307
274308 @action
275309 setRepo = detail => {
310+ this . repoCreated = null ;
311+
276312 if ( detail ) {
277313 this . repoId = detail . repo_id ;
278314 this . name = detail . name ;
279315 this . description = detail . description ;
280316 this . url = detail . url ;
281317 this . protocolType = detail . type ;
318+ this . accessKey = '' ;
319+ this . secretKey = '' ;
282320 this . providers = detail . providers ;
283321 this . visibility = detail . visibility ;
284322 this . labels = detail . labels || [ { label_key : '' , label_value : '' } ] ;
0 commit comments