feat: encode access-code in header for better safety

This commit is contained in:
Yuwen Sun
2023-04-08 11:52:56 -04:00
parent 40b8b225f9
commit 71d666fe84
2 changed files with 4 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
import type { ChatRequest, ChatReponse } from "./api/openai/typing";
import { Message, ModelConfig, useAccessStore, useChatStore } from "./store";
import { showToast } from "./components/ui-lib";
import md5 from "spark-md5";
const TIME_OUT_MS = 30000;
@@ -37,8 +38,8 @@ function getHeaders() {
const accessStore = useAccessStore.getState();
let headers: Record<string, string> = {};
if (accessStore.enabledAccessControl()) {
headers["access-code"] = accessStore.accessCode;
if (accessStore.enabledAccessControl() && accessStore.accessCode.length) {
headers["access-code"] = md5.hash(accessStore.accessCode);
}
if (accessStore.token && accessStore.token.length > 0) {