Personal Telegram developer console for GitHub
feat(hardening): persist global emergency lock
davoodmehraban89 committed
Oct 5, 2026 at 13:22 UTC
935efda051f636386b2c60b05396d5189fc36188
1 file changed
+16
src/durable/kill-switch-store.js
new
+16
@@ -0,0 +1,16 @@
1
+const json=(payload,status=200)=>Response.json(payload,{status});
2
+export class KillSwitchStore {
3
+ constructor(state){this.state=state;}
4
+ async fetch(request){
5
+ const url=new URL(request.url);if(url.pathname!=='/state')return new Response('Not Found',{status:404});
6
+ if(request.method==='GET'){
7
+ const state=await this.state.storage.get('state');
8
+ return json(state||{mode:'NORMAL',changedAt:0});
9
+ }
10
+ if(request.method==='PUT'){
11
+ const body=await request.json().catch(()=>null);if(!body||!['NORMAL','LOCKED'].includes(body.mode))return json({ok:false},400);
12
+ const next={mode:body.mode,changedAt:Number(body.changedAt)||Date.now()};await this.state.storage.put('state',next);return json(next);
13
+ }
14
+ return new Response('Method Not Allowed',{status:405});
15
+ }
16
+}