feat(desktop-client): 阶段4-6 Electron EXE 客户端(登录/课表/作业/通知/成绩/设置 + Socket.IO 实时 + IndexedDB 离线缓存与自动同步 + electron-builder 打包)
This commit is contained in:
1 parent
4566d7cd5e
commit
6e4c7c1050
42 files changed
+5767
-60
No files matched your search
@@ -0,0 +1,26 @@
|
||||
import { DEFAULT_SERVER_URL } from '@classhelper/shared';
|
||||
|
||||
/** 默认后端地址(首次启动的预填值) */
|
||||
export const DEFAULT_SERVER = DEFAULT_SERVER_URL;
|
||||
|
||||
/** 由服务器地址推导 API 基地址,例如 http://127.0.0.1:4000 -> http://127.0.0.1:4000/api */
|
||||
export function apiBaseOf(serverUrl: string): string {
|
||||
return `${serverUrl.trim().replace(/\/+$/, '')}/api`;
|
||||
}
|
||||
|
||||
/** 由服务器地址推导 Socket.IO 地址 */
|
||||
export function socketUrlOf(serverUrl: string): string {
|
||||
return serverUrl.trim().replace(/\/+$/, '');
|
||||
}
|
||||
|
||||
/** 校验用户输入的服务器地址 */
|
||||
export function normalizeServerUrl(input: string): string | null {
|
||||
const value = input.trim().replace(/\/+$/, '');
|
||||
if (!/^https?:\/\/[^\s]+$/i.test(value)) return null;
|
||||
try {
|
||||
const url = new URL(value);
|
||||
return `${url.protocol}//${url.host}`;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user