Skip to content

Commit c6d264c

Browse files
committed
test
1 parent 7b524c3 commit c6d264c

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

handle-api.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
async function getStateObj(env) {
2-
const raw = await env.MAINTENANCE_KV.get('MAINTENANCE_STATE');
3-
try {
4-
return JSON.parse(raw || '') || {};
5-
} catch {
6-
return {};
7-
}
2+
return globalState.maintenanceState;
83
}
94

105
async function setStateObj(env, obj) {
11-
await env.MAINTENANCE_KV.put('MAINTENANCE_STATE', JSON.stringify(obj));
6+
globalState.maintenanceState = obj;
127
invalidateCache(env);
138
}
149

@@ -19,6 +14,7 @@ function invalidateCache(env) {
1914
globalThis.cache.maintenance = { value: null, ts: 0 };
2015
globalThis.cache.is4g = { value: null, ts: 0 };
2116
}
17+
globalState.is4gMode = globalState.is4gMode; // No-op to simulate cache invalidation
2218
}
2319

2420
export async function handleApi(request, url, host, env, state) {

worker.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,18 @@ const cache = {
1313
is4g: { value: null, ts: 0 }
1414
};
1515

16-
// Read maintenance and banner states from KV (single key) with optional cache
16+
// Global in-memory storage
17+
const globalState = {
18+
maintenanceState: {
19+
isGlobalMaintenance: false,
20+
subdomainsMaintenance: [],
21+
bannerSubdomains: [],
22+
bannerMessage: '',
23+
},
24+
is4gMode: false,
25+
};
26+
27+
// Read maintenance and banner states from in-memory storage
1728
async function getMaintenanceState(env, host, useCache = true) {
1829
// Read cache config from env
1930
const cacheEnabled = env.ENABLE_CACHE === undefined ? true : env.ENABLE_CACHE === true || env.ENABLE_CACHE === 'true';

0 commit comments

Comments
 (0)