@@ -18,6 +18,35 @@ <h1>Configuration</h1>
1818</ div >
1919
2020< script >
21+ async function postSetWorkspace ( path ) {
22+ const res = await fetch ( '/api/set-workspace' , {
23+ method : 'POST' ,
24+ headers : { 'Content-Type' : 'application/json' } ,
25+ body : JSON . stringify ( { path } )
26+ } ) ;
27+ let body = { } ;
28+ try {
29+ body = await res . json ( ) ;
30+ } catch ( e ) {
31+ body = { } ;
32+ }
33+ if ( res . status === 409 ) {
34+ return {
35+ ok : false ,
36+ message : body . error || 'Workspace path cannot be changed in this deployment.' ,
37+ code : body . code
38+ } ;
39+ }
40+ if ( ! res . ok ) {
41+ return {
42+ ok : false ,
43+ message : body . error || 'Failed to save workspace path.' ,
44+ code : body . code
45+ } ;
46+ }
47+ return { ok : true , body } ;
48+ }
49+
2150document . addEventListener ( 'DOMContentLoaded' , async ( ) => {
2251 const stored = localStorage . getItem ( 'workspacePath' ) ;
2352 if ( stored ) {
@@ -53,14 +82,12 @@ <h1>Configuration</h1>
5382 } ) ;
5483 const valData = await valRes . json ( ) ;
5584 if ( valData . valid ) {
56- localStorage . setItem ( 'workspacePath' , detected ) ;
57- await fetch ( '/api/set-workspace' , {
58- method : 'POST' ,
59- headers : { 'Content-Type' : 'application/json' } ,
60- body : JSON . stringify ( { path : detected } )
61- } ) ;
62- window . location . href = '/' ;
63- return ;
85+ const saved = await postSetWorkspace ( detected ) ;
86+ if ( saved . ok ) {
87+ localStorage . setItem ( 'workspacePath' , detected ) ;
88+ window . location . href = '/' ;
89+ return ;
90+ }
6491 }
6592 }
6693 document . getElementById ( 'workspace-path' ) . value = detected ;
@@ -84,12 +111,14 @@ <h1>Configuration</h1>
84111 const data = await res . json ( ) ;
85112
86113 if ( data . valid ) {
114+ const saved = await postSetWorkspace ( path ) ;
115+ if ( ! saved . ok ) {
116+ statusEl . className = 'alert alert-danger' ;
117+ statusEl . textContent = saved . message ;
118+ statusEl . style . display = 'block' ;
119+ return ;
120+ }
87121 localStorage . setItem ( 'workspacePath' , path ) ;
88- await fetch ( '/api/set-workspace' , {
89- method : 'POST' ,
90- headers : { 'Content-Type' : 'application/json' } ,
91- body : JSON . stringify ( { path } )
92- } ) ;
93122 statusEl . className = 'alert alert-success' ;
94123 statusEl . textContent = `Found ${ data . workspaceCount } workspaces in the specified location` ;
95124 statusEl . style . display = 'block' ;
0 commit comments