@@ -6,7 +6,8 @@ export async function handleApi(request, url, host, env, state) {
66
77 // Toggle global maintenance mode
88 if ( url . pathname === '/worker/api/toggle-maintenance/global' && request . method === 'POST' ) {
9- await env . MAINTENANCE_KV . put ( 'MAINTENANCE_GLOBAL' , state . isGlobalMaintenance ? 'false' : 'true' ) ;
9+ const newState = { ...state , isGlobalMaintenance : ! state . isGlobalMaintenance } ;
10+ await env . MAINTENANCE_KV . put ( 'MAINTENANCE_STATE' , JSON . stringify ( newState ) ) ;
1011 return new Response ( 'Maintenance globale mise à jour' ) ;
1112 }
1213
@@ -15,7 +16,8 @@ export async function handleApi(request, url, host, env, state) {
1516 const { subdomain } = await request . json ( ) ;
1617 if ( ! state . subdomainsMaintenance . includes ( subdomain ) ) {
1718 state . subdomainsMaintenance . push ( subdomain ) ;
18- await env . MAINTENANCE_KV . put ( 'MAINTENANCE_SUBDOMAINS' , JSON . stringify ( state . subdomainsMaintenance ) ) ;
19+ const newState = { ...state , subdomainsMaintenance : state . subdomainsMaintenance } ;
20+ await env . MAINTENANCE_KV . put ( 'MAINTENANCE_STATE' , JSON . stringify ( newState ) ) ;
1921 }
2022 return new Response ( 'Sous-domaine ajouté' ) ;
2123 }
@@ -24,7 +26,8 @@ export async function handleApi(request, url, host, env, state) {
2426 if ( url . pathname === '/worker/api/maintenance/subdomain/remove' && request . method === 'POST' ) {
2527 const { subdomain } = await request . json ( ) ;
2628 const newList = state . subdomainsMaintenance . filter ( d => d !== subdomain ) ;
27- await env . MAINTENANCE_KV . put ( 'MAINTENANCE_SUBDOMAINS' , JSON . stringify ( newList ) ) ;
29+ const newState = { ...state , subdomainsMaintenance : newList } ;
30+ await env . MAINTENANCE_KV . put ( 'MAINTENANCE_STATE' , JSON . stringify ( newState ) ) ;
2831 return new Response ( 'Sous-domaine retiré' ) ;
2932 }
3033
@@ -45,7 +48,8 @@ export async function handleApi(request, url, host, env, state) {
4548 if ( typeof subdomain !== 'string' ) return new Response ( 'Format attendu: { subdomain: "..." }' , { status : 400 } ) ;
4649 if ( ! state . bannerSubdomains . includes ( subdomain ) ) {
4750 state . bannerSubdomains . push ( subdomain ) ;
48- await env . MAINTENANCE_KV . put ( 'BANNER_SUBDOMAINS' , JSON . stringify ( state . bannerSubdomains ) ) ;
51+ const newState = { ...state , bannerSubdomains : state . bannerSubdomains } ;
52+ await env . MAINTENANCE_KV . put ( 'MAINTENANCE_STATE' , JSON . stringify ( newState ) ) ;
4953 }
5054 return new Response ( 'Sous-domaine ajouté au bandeau' ) ;
5155 }
@@ -55,15 +59,17 @@ export async function handleApi(request, url, host, env, state) {
5559 const { subdomain } = await request . json ( ) ;
5660 if ( typeof subdomain !== 'string' ) return new Response ( 'Format attendu: { subdomain: "..." }' , { status : 400 } ) ;
5761 const newList = state . bannerSubdomains . filter ( d => d !== subdomain ) ;
58- await env . MAINTENANCE_KV . put ( 'BANNER_SUBDOMAINS' , JSON . stringify ( newList ) ) ;
62+ const newState = { ...state , bannerSubdomains : newList } ;
63+ await env . MAINTENANCE_KV . put ( 'MAINTENANCE_STATE' , JSON . stringify ( newState ) ) ;
5964 return new Response ( 'Sous-domaine retiré du bandeau' ) ;
6065 }
6166
6267 // Set the banner message
6368 if ( url . pathname === '/worker/api/banner/message' && request . method === 'POST' ) {
6469 const { message } = await request . json ( ) ;
6570 if ( typeof message === 'string' ) {
66- await env . MAINTENANCE_KV . put ( 'BANNER_MESSAGE' , message ) ;
71+ const newState = { ...state , bannerMessage : message } ;
72+ await env . MAINTENANCE_KV . put ( 'MAINTENANCE_STATE' , JSON . stringify ( newState ) ) ;
6773 return new Response ( 'Message du bandeau mis à jour' ) ;
6874 } else {
6975 return new Response ( 'Format attendu: { message: "..." }' , { status : 400 } ) ;
0 commit comments