feat: send X-API-Key from review console and document API key auth
- 검토 콘솔: 헤더에 API 키 입력 버튼 추가, 키는 브라우저 localStorage 에만 저장하고 모든 v1 호출(apiFetch)에 X-API-Key 헤더로 실어 보냄 - 바이칼 명세 §0-1 인증 절 추가, 에러 표에 401 추가 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
c88f59fb71
commit
2043b6d399
3 files changed
+58
-9
No files matched your search
+35
-7
@@ -286,6 +286,7 @@
|
||||
<button class="tab-btn" data-tab="precedents">판례</button>
|
||||
</nav>
|
||||
<span id="health-badge" class="badge">엔진 확인 중…</span>
|
||||
<button id="api-key-btn" class="badge" type="button" style="cursor: pointer;">API 키</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
@@ -510,6 +511,33 @@
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
// 서버가 API 키 인증을 켜면 /v1 호출에 X-API-Key 가 필요하다. 키는 이 브라우저에만 저장한다.
|
||||
const API_KEY_STORAGE = "o2o-plagiarism-api-key";
|
||||
function storedApiKey() {
|
||||
try { return localStorage.getItem(API_KEY_STORAGE) || ""; } catch (e) { return ""; }
|
||||
}
|
||||
function apiFetch(url, opts = {}) {
|
||||
const key = storedApiKey();
|
||||
if (!key) return fetch(url, opts);
|
||||
const headers = new Headers(opts.headers || {});
|
||||
headers.set("X-API-Key", key);
|
||||
return fetch(url, { ...opts, headers });
|
||||
}
|
||||
const apiKeyBtn = document.getElementById("api-key-btn");
|
||||
apiKeyBtn.textContent = storedApiKey() ? "API 키 ✓" : "API 키 입력";
|
||||
apiKeyBtn.addEventListener("click", () => {
|
||||
const key = prompt("API 키를 입력하세요. 비우고 확인하면 저장된 키를 지웁니다.", "");
|
||||
if (key === null) return;
|
||||
try {
|
||||
if (key.trim()) localStorage.setItem(API_KEY_STORAGE, key.trim());
|
||||
else localStorage.removeItem(API_KEY_STORAGE);
|
||||
} catch (e) {
|
||||
alert("브라우저 저장소를 쓸 수 없습니다: " + e.message);
|
||||
return;
|
||||
}
|
||||
location.reload();
|
||||
});
|
||||
|
||||
const SAMPLES = {
|
||||
copy: {
|
||||
title: "어미만 변경한 표절 (홍길동전 기반)",
|
||||
@@ -606,7 +634,7 @@ async function runDetect() {
|
||||
document.getElementById("result-body").style.display = "none";
|
||||
|
||||
try {
|
||||
const resp = await fetch("v1/plagiarism/detect", {
|
||||
const resp = await apiFetch("v1/plagiarism/detect", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
@@ -922,7 +950,7 @@ async function loadCorpus() {
|
||||
const tbody = document.getElementById("corpus-tbody");
|
||||
tbody.innerHTML = '<tr><td colspan="4" style="color: var(--muted); text-align: center; padding: 20px;">로딩 중…</td></tr>';
|
||||
try {
|
||||
const resp = await fetch("v1/corpus");
|
||||
const resp = await apiFetch("v1/corpus");
|
||||
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
|
||||
const data = await resp.json();
|
||||
document.getElementById("corpus-count").textContent = data.total;
|
||||
@@ -973,9 +1001,9 @@ async function uploadCorpus() {
|
||||
fd.append("title", title);
|
||||
if (docId) fd.append("doc_id", docId);
|
||||
fd.append("file", file);
|
||||
resp = await fetch("v1/corpus/file", { method: "POST", body: fd });
|
||||
resp = await apiFetch("v1/corpus/file", { method: "POST", body: fd });
|
||||
} else {
|
||||
resp = await fetch("v1/corpus", {
|
||||
resp = await apiFetch("v1/corpus", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ doc_id: docId || null, title, text }),
|
||||
@@ -1004,7 +1032,7 @@ async function uploadCorpus() {
|
||||
async function deleteDoc(docId) {
|
||||
if (!confirm(`'${docId}' 문서를 삭제하시겠습니까? 인덱스가 재빌드됩니다.`)) return;
|
||||
try {
|
||||
const resp = await fetch(`v1/corpus/${encodeURIComponent(docId)}`, {
|
||||
const resp = await apiFetch(`v1/corpus/${encodeURIComponent(docId)}`, {
|
||||
method: "DELETE",
|
||||
});
|
||||
if (!resp.ok && resp.status !== 204) {
|
||||
@@ -1074,7 +1102,7 @@ async function loadPrecedents() {
|
||||
if (workType) params.set("work_type", workType);
|
||||
tbody.innerHTML = '<tr><td colspan="6" style="text-align:center; padding:20px; color:var(--muted);">로딩 중…</td></tr>';
|
||||
try {
|
||||
const resp = await fetch(`v1/precedents?${params}`);
|
||||
const resp = await apiFetch(`v1/precedents?${params}`);
|
||||
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
|
||||
const data = await resp.json();
|
||||
precedentTotal = data.total;
|
||||
@@ -1131,7 +1159,7 @@ let precedentCount = null;
|
||||
|
||||
async function checkHealth() {
|
||||
try {
|
||||
const resp = await fetch("v1/health");
|
||||
const resp = await apiFetch("v1/health");
|
||||
if (!resp.ok) throw new Error("not ok");
|
||||
const data = await resp.json();
|
||||
const autobio = data.autobiography_mode ? ' · 자서전모드' : '';
|
||||
|
||||
Reference in new issue
Block a user