diff --git a/src/service/debugLog.ts b/src/service/debugLog.ts
index 2ab61d2..74d48bd 100644
--- a/src/service/debugLog.ts
+++ b/src/service/debugLog.ts
@@ -1,3 +1,5 @@
+import http from "~/service/http";
+
export type DebugLogEntry = {
id: number;
time: string;
@@ -17,6 +19,18 @@ type DebugLogListResponse = {
};
};
+type DebugConfigResponse = {
+ code: number;
+ message: string;
+ data: {
+ enabled: boolean;
+ proxy: string;
+ skip_ssl_verify: boolean;
+ build_mode: string;
+ proxy_configured: boolean;
+ };
+};
+
const toWsProtocol = (protocol: string) => {
return protocol === "https:" ? "wss:" : "ws:";
};
@@ -61,3 +75,13 @@ export const fetchDebugLogSnapshot = async () => {
const payload = (await response.json()) as DebugLogListResponse;
return payload.data.list ?? [];
};
+
+export const fetchDebugConfig = async () => {
+ return await http.get("/api/debug/config");
+};
+
+export const updateDebugConfig = async (enabled: boolean) => {
+ return await http.post("/api/debug/config", {
+ enabled,
+ });
+};
diff --git a/src/service/http.ts b/src/service/http.ts
index 63c5978..a9b7350 100644
--- a/src/service/http.ts
+++ b/src/service/http.ts
@@ -5,6 +5,8 @@ type UnauthorizedHandler = (sessionId: string) => Promise;
type SessionResolver = () => string | undefined;
+const DEFAULT_HTTP_TIMEOUT_MS = 15000;
+
export type HttpClient = {
get(url: string, config?: AxiosRequestConfig): Promise;
post(url: string, data?: unknown, config?: AxiosRequestConfig): Promise;
@@ -46,7 +48,7 @@ export const createHttpClient = (
): HttpClient => {
const instance = axios.create({
baseURL: import.meta.env.VITE_BASE_URL,
- timeout: 15000,
+ timeout: DEFAULT_HTTP_TIMEOUT_MS,
});
instance.interceptors.request.use((config: InternalAxiosRequestConfig) => {
@@ -106,3 +108,4 @@ export const createHttpClient = (
const http = createHttpClient();
export default http;
+export { DEFAULT_HTTP_TIMEOUT_MS };
diff --git a/src/service/wk.ts b/src/service/wk.ts
index a56f6ea..4f5e16c 100644
--- a/src/service/wk.ts
+++ b/src/service/wk.ts
@@ -1,5 +1,9 @@
import type { Accessor } from "solid-js";
-import http, { createHttpClient, type HttpClient } from "~/service/http";
+import http, {
+ DEFAULT_HTTP_TIMEOUT_MS,
+ createHttpClient,
+ type HttpClient,
+} from "~/service/http";
import type { CourseType } from "~/types/Course";
import type { userInfoType } from "~/types/Userinfo";
@@ -24,9 +28,7 @@ export type LoginReq = {
};
export type LoginData = {
- courses?: CourseType[];
session_id: string;
- user: userInfoType;
};
export type LoginRes = ApiResponse;
@@ -130,6 +132,12 @@ export type CourseData = {
export type CourseRes = ApiResponse;
+export type UserInfoData = {
+ user: userInfoType;
+};
+
+export type UserInfoRes = ApiResponse;
+
export type StudyReq = {
node_id: string;
study_id: string;
@@ -158,23 +166,34 @@ export type StudyRunnerPayload = {
};
export type WkClient = {
+ userInfoApi: () => Promise;
courseApi: (payload: CourseReq) => Promise;
recordApi: (payload: RecordReq) => Promise;
studyApi: (payload: StudyReq) => Promise;
logoutApi: () => Promise;
};
+const RECORD_API_TIMEOUT_MS = 60000;
+const COURSE_API_TIMEOUT_MS = Math.max(DEFAULT_HTTP_TIMEOUT_MS, 30000);
+
export const loginApi = async (payload: LoginReq) => {
const res = await http.post("/api/login", payload);
return res;
};
const createWkClientFromHttp = (client: HttpClient): WkClient => ({
+ userInfoApi() {
+ return client.post("/api/v2/userinfo");
+ },
courseApi(payload) {
- return client.post("/api/v2/course", payload);
+ return client.post("/api/v2/course", payload, {
+ timeout: COURSE_API_TIMEOUT_MS,
+ });
},
recordApi(payload) {
- return client.post("/api/v2/record", payload);
+ return client.post("/api/v2/record", payload, {
+ timeout: RECORD_API_TIMEOUT_MS,
+ });
},
studyApi(payload) {
return client.post("/api/v2/study", payload);
@@ -190,6 +209,10 @@ export const createWkClient = (
return createWkClientFromHttp(createHttpClient(resolveSessionId));
};
+export const createSessionWkClient = (sessionId: string): WkClient => {
+ return createWkClient(() => sessionId);
+};
+
const sleep = (ms: number) => new Promise((res) => setTimeout(res, ms));
export const runStudyQueue = async (_payload: StudyRunnerPayload) => {
diff --git a/src/store/settings.ts b/src/store/settings.ts
index 5ea7522..ceed1f8 100644
--- a/src/store/settings.ts
+++ b/src/store/settings.ts
@@ -14,6 +14,7 @@ type SettingsState = {
persistAccounts: boolean;
persistRecords: boolean;
persistLogs: boolean;
+ debugEnabled: boolean;
autoScrollLogs: boolean;
showLogTimestamps: boolean;
densityMode: DensityMode;
@@ -24,6 +25,7 @@ type SettingsState = {
setPersistSection: (section: CacheSection, value: boolean) => void;
clearPersistedSection: (section: CacheSection) => void;
clearAllPersistedData: () => void;
+ setDebugEnabled: (value: boolean) => void;
setAutoScrollLogs: (value: boolean) => void;
setShowLogTimestamps: (value: boolean) => void;
setDensityMode: (value: DensityMode) => void;
@@ -93,6 +95,7 @@ export const settingsStore = createStore()(
persistAccounts: true,
persistRecords: true,
persistLogs: true,
+ debugEnabled: false,
autoScrollLogs: true,
showLogTimestamps: false,
densityMode: "comfortable",
@@ -160,6 +163,7 @@ export const settingsStore = createStore()(
clearAllPersistedData: () => {
localStorage.removeItem(accountStorageKey);
},
+ setDebugEnabled: (value) => set({ debugEnabled: value }),
setAutoScrollLogs: (value) => set({ autoScrollLogs: value }),
setShowLogTimestamps: (value) => set({ showLogTimestamps: value }),
setDensityMode: (value) => set({ densityMode: value }),