Skip to content

Commit e09d718

Browse files
committed
Use loaded admin key for dashboard writes
1 parent 591ea2d commit e09d718

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/dashboard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const $=id=>document.getElementById(id); const esc=v=>String(v??'').replace(/[&<
5151
const expiredIds=new Set();
5252
function fullBridgeKey(){const raw=($('bridgeApiKey')?.value||'').trim(); if(!raw)return ''; return raw.startsWith('sk-')?raw:'sk-'+raw;}
5353
function displayBridgeKey(key){return key?.startsWith('sk-')?key.slice(3):(key||'')}
54-
function auth(){const key=localStorage.getItem('bridgeApiKey')||''; return key?{'authorization':'Bearer '+key,'content-type':'application/json'}:{'content-type':'application/json'}}
54+
function auth(){const key=cfg?.bridgeApiKey||localStorage.getItem('bridgeApiKey')||fullBridgeKey()||''; return key?{'authorization':'Bearer '+key,'content-type':'application/json'}:{'content-type':'application/json'}}
5555
function duplicateCredentialMessage(e){const text=String(e?.message||e||''); return text.includes('duplicate_commandcode_api_key')||text.includes('Duplicate CommandCode API key')?'이미 등록된 키입니다. 다른 CommandCode API key를 입력해주세요.':null;}
5656
function preventDuplicateVisibleKey(input){const value=input.value.trim(); if(!value)return false; const dup=Array.from(document.querySelectorAll('[data-ckey]')).some(el=>el!==input&&el.value.trim()===value); if(!dup)return false; const i=+input.dataset.ckey; input.value=''; if(cfg?.credentials?.[i])cfg.credentials[i].apiKey=''; toast('이미 등록된 키입니다. 입력하지 않았습니다.'); return true;}
5757
function syncBridgeKey(){const el=$('bridgeApiKey'); if(!el)return; const configured=cfg?.bridgeApiKey||''; const stored=localStorage.getItem('bridgeApiKey')||''; const key=configured||stored; if(configured&&stored!==configured)localStorage.setItem('bridgeApiKey',configured); if(document.activeElement!==el) el.value=displayBridgeKey(key); const wrap=$('bridgeKeyWrap'); if(wrap) wrap.style.display=$('bindHost')?.value==='0.0.0.0'?'grid':'none';}

tests/dashboard-ui.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,17 @@ describe("dashboard UI", () => {
106106
expect(html).toContain("이미 등록된 키입니다");
107107
expect(html).toContain("Duplicate CommandCode API key");
108108
});
109+
110+
it("uses the loaded admin API key for writes when browser storage is empty or stale", () => {
111+
const html = dashboardHtml({
112+
server: { host: "0.0.0.0", port: 9992 },
113+
routing: { policy: "daily_burn_priority", maxInFlightPerCredential: 4 },
114+
credentials: [],
115+
models: [],
116+
bridgeApiKey: "test-admin-token",
117+
});
118+
119+
expect(html).toContain("cfg?.bridgeApiKey||localStorage.getItem('bridgeApiKey')");
120+
expect(html).toContain("'authorization':'Bearer '+key");
121+
});
109122
});

0 commit comments

Comments
 (0)