refactor(chat): rely on server message limits
This commit is contained in:
@@ -5,10 +5,7 @@
|
||||
* - 翻页大小常量
|
||||
* - 仓库注入(接口类型 → 单例)
|
||||
* - DTO ↔ UiMessage 映射(纯函数 —— 可单测)
|
||||
* - Result → number 映射(纯函数 —— 可单测)
|
||||
* - 2 个独立 init 任务的数据加载:
|
||||
* - `readGuestQuota()` —— 游客日配 + 总配(仅游客有意义,纯 ChatStorage)
|
||||
* - `readAndSyncHistory()` —— local → network → save network to local 3 步
|
||||
* - `readAndSyncHistory()` —— local → network → save network to local 3 步
|
||||
*
|
||||
* 设计目标:
|
||||
* - helpers 无 XState 依赖(可独立 import / 测试)
|
||||
@@ -23,7 +20,6 @@
|
||||
import type { UiMessage } from "@/data/dto/chat";
|
||||
import { chatRepository } from "@/data/repositories/chat_repository";
|
||||
import type { IChatRepository } from "@/data/repositories/interfaces";
|
||||
import { ChatStorage } from "@/data/storage/chat/chat_storage";
|
||||
import { ChatSendResponse } from "@/data/dto/chat/chat_send_response";
|
||||
import { todayString, Result, Logger } from "@/utils";
|
||||
|
||||
@@ -142,44 +138,8 @@ export function applyHttpSendOutput(
|
||||
};
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Result → number 映射
|
||||
// ============================================================
|
||||
/** 日配额 Result → number(纯函数) */
|
||||
export function mapQuotaResult(
|
||||
r: Result<{ remaining: number } | null>,
|
||||
fallback: number,
|
||||
): number {
|
||||
if (r.success && r.data != null) return r.data.remaining;
|
||||
return fallback;
|
||||
}
|
||||
|
||||
/** 总配额 Result → number(纯函数) */
|
||||
export function mapTotalQuotaResult(
|
||||
r: Result<number | null>,
|
||||
fallback: number,
|
||||
): number {
|
||||
if (r.success && r.data != null) return r.data;
|
||||
return fallback;
|
||||
}
|
||||
|
||||
export async function readGuestQuota(): Promise<{
|
||||
remaining: number;
|
||||
total: number;
|
||||
}> {
|
||||
const chatStorage = ChatStorage.getInstance();
|
||||
const [dailyResult, totalResult] = await Promise.all([
|
||||
chatStorage.getGuestDailyChatQuota(),
|
||||
chatStorage.getGuestTotalQuota(),
|
||||
]);
|
||||
return {
|
||||
remaining: mapQuotaResult(
|
||||
dailyResult as Result<{ remaining: number } | null>,
|
||||
0,
|
||||
),
|
||||
total: mapTotalQuotaResult(totalResult as Result<number | null>, 0),
|
||||
};
|
||||
}
|
||||
// 本地游客消息额度读取 / 映射逻辑已停用:
|
||||
// 消息数量限制统一由后端接口返回 blocked/daily_limit,前端不再读取 ChatStorage quota。
|
||||
|
||||
// ============================================================
|
||||
// Init 任务 2:history 3 步流(local → network → save)—— `loadHistoryActor` 调
|
||||
|
||||
Reference in New Issue
Block a user