@@ -347,6 +347,7 @@ const Template = () => {
347347 compileLoading,
348348 deployLoading,
349349 activateLoading,
350+ setProject,
350351 } = useStore (
351352 useShallow ( ( state ) => ( {
352353 client : state . global . client ,
@@ -358,6 +359,7 @@ const Template = () => {
358359 compileLoading : state . compile . loading ,
359360 deployLoading : state . deploy . loading ,
360361 activateLoading : state . activate . loading ,
362+ setProject : state . project . setProject ,
361363 } ) )
362364 ) ;
363365 const isLoading = compileLoading || deployLoading || activateLoading ;
@@ -383,40 +385,70 @@ const Template = () => {
383385 }
384386 } ;
385387
386- if ( await isExists ( template ) ) {
387- await client . terminal . log ( {
388- type : "error" ,
389- value : `The folder ${ template } already exists` ,
388+ try {
389+ if ( await isExists ( template ) ) {
390+ await client . terminal . log ( {
391+ type : "error" ,
392+ value : `The folder ${ template } already exists` ,
393+ } ) ;
394+ return ;
395+ }
396+
397+ const res = await axios . request ( {
398+ method : "GET" ,
399+ url : `https://api.welldonestudio.io/compiler/s3Proxy?bucket=code-template&fileKey=arbitrum/${ template } .zip` ,
400+ responseType : "arraybuffer" ,
401+ responseEncoding : "null" ,
390402 } ) ;
391- return ;
392- }
393403
394- const res = await axios . request ( {
395- method : "GET" ,
396- url : `https://api.welldonestudio.io/compiler/s3Proxy?bucket=code-template&fileKey=arbitrum/` + template + ".zip" ,
397- responseType : "arraybuffer" ,
398- responseEncoding : "null" ,
399- } ) ;
404+ const jsZip = new JSZip ( ) ;
405+ const zip = await jsZip . loadAsync ( res . data ) ;
400406
401- const jsZip = new JSZip ( ) ;
402- const zip = await jsZip . loadAsync ( res . data ) ;
407+ let content : any ;
408+ try {
409+ Object . keys ( zip . files ) . map ( async ( key ) => {
410+ log . debug ( `@@@ key=${ key } ` ) ;
411+ if ( zip . files [ key ] . dir ) {
412+ await client ?. fileManager . mkdir ( "browser/arbitrum/" + key ) ;
413+ } else if ( ! key . startsWith ( "_" ) && key !== template + "/.DS_Store" ) {
414+ content = await zip . file ( key ) ?. async ( "string" ) ;
415+ await client ?. fileManager . writeFile ( "browser/arbitrum/" + key , content ) ;
416+ }
417+ } ) ;
418+ await fetchProjects ( ) ;
403419
404- let content : any ;
405- try {
406- Object . keys ( zip . files ) . map ( async ( key ) => {
407- log . debug ( `@@@ key=${ key } ` ) ;
408- if ( zip . files [ key ] . dir ) {
409- await client ?. fileManager . mkdir ( "browser/arbitrum/" + key ) ;
410- } else if ( ! key . startsWith ( "_" ) && key !== template + "/.DS_Store" ) {
411- content = await zip . file ( key ) ?. async ( "string" ) ;
412- await client ?. fileManager . writeFile ( "browser/arbitrum/" + key , content ) ;
413- }
414- } ) ;
415- await fetchProjects ( ) ;
420+ // 템플릿 생성 후 해당 프로젝트를 자동으로 선택
421+ const projectPath = `arbitrum/${ template } ` ;
422+ setProject ( projectPath ) ;
416423
417- await client . terminal . log ( { type : "info" , value : template + " is created successfully." } ) ;
418- } catch ( e ) {
419- log . error ( e ) ;
424+ await client . terminal . log ( { type : "info" , value : template + " is created successfully." } ) ;
425+ } catch ( e ) {
426+ log . error ( e ) ;
427+ await client . terminal . log ( {
428+ type : "error" ,
429+ value : "Failed to extract template files. Please try again." ,
430+ } ) ;
431+ }
432+ } catch ( error ) {
433+ log . error ( error ) ;
434+ if ( axios . isAxiosError ( error ) ) {
435+ if ( error . response ?. status === 404 ) {
436+ await client . terminal . log ( {
437+ type : "error" ,
438+ value : `Template "${ template } " not found. Please check the template name.` ,
439+ } ) ;
440+ } else {
441+ await client . terminal . log ( {
442+ type : "error" ,
443+ value : `Failed to download template. Error: ${ error . message } ` ,
444+ } ) ;
445+ }
446+ } else {
447+ await client . terminal . log ( {
448+ type : "error" ,
449+ value : "An unexpected error occurred while creating the template." ,
450+ } ) ;
451+ }
420452 }
421453 } ;
422454
@@ -495,6 +527,9 @@ const TargetProject = () => {
495527 ) ;
496528 const isLoading = compileLoading || deployLoading || activateLoading ;
497529
530+ console . log ( "@@@ target project" , project ) ;
531+ console . log ( "@@@ target projects" , projects ) ;
532+
498533 const handleTargetProjectOnChange = ( event : React . ChangeEvent < HTMLInputElement > ) => {
499534 setProject ( event . target . value ) ;
500535 } ;
0 commit comments