修改Web Crypto API 在 HTTP 环境下不可用的问题,自动降级

- HTTPS/localhost :正常启用加密
- HTTP(非 localhost) :自动禁用加密,以明文方式通信
This commit is contained in:
2026-06-26 14:56:03 +08:00
parent 157e7e5bba
commit e21ba57597
8 changed files with 202 additions and 166 deletions
+2 -2
View File
@@ -3,10 +3,10 @@
* Handles auth tokens, request/response encryption, snake_case→camelCase conversion.
*/
import { encrypt, decrypt } from './crypto';
import { encrypt, decrypt, isCryptoAvailable } from './crypto';
const BASE_URL = import.meta.env.VITE_API_BASE || 'http://localhost:8000';
const USE_ENCRYPTION = !!import.meta.env.VITE_ENCRYPTION_KEY;
const USE_ENCRYPTION = !!import.meta.env.VITE_ENCRYPTION_KEY && isCryptoAvailable();
interface RequestOptions {
method?: string;