refactor(api): remove unused network endpoints
This commit is contained in:
@@ -15,7 +15,6 @@ import { AppEnvUtil, deviceIdentifier, Result } from "@/utils";
|
||||
* (这些路径返回 401 时不触发刷新)
|
||||
*/
|
||||
const NO_AUTH_REFRESH_PATHS: readonly string[] = [
|
||||
ApiPath.sendCode,
|
||||
ApiPath.emailLogin,
|
||||
ApiPath.register,
|
||||
ApiPath.guestLogin,
|
||||
|
||||
@@ -16,7 +16,6 @@ const log = new Logger("TokenInterceptor");
|
||||
* 不需要 token 的路径
|
||||
*/
|
||||
const NO_TOKEN_PATHS: readonly string[] = [
|
||||
ApiPath.sendCode,
|
||||
ApiPath.emailLogin,
|
||||
ApiPath.register,
|
||||
ApiPath.guestLogin,
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
/**
|
||||
* Apple 登录请求 DTO
|
||||
*/
|
||||
import {
|
||||
AppleLoginRequestSchema,
|
||||
type AppleLoginRequestInput,
|
||||
type AppleLoginRequestData,
|
||||
} from "@/data/schemas/auth/apple_login_request";
|
||||
|
||||
export class AppleLoginRequest {
|
||||
declare readonly identityToken: string;
|
||||
declare readonly platform: string;
|
||||
declare readonly isTestAccount: boolean;
|
||||
|
||||
private constructor(input: AppleLoginRequestInput) {
|
||||
const data = AppleLoginRequestSchema.parse(input);
|
||||
Object.assign(this, data);
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
static from(input: AppleLoginRequestInput): AppleLoginRequest {
|
||||
return new AppleLoginRequest(input);
|
||||
}
|
||||
|
||||
static fromJson(json: unknown): AppleLoginRequest {
|
||||
return AppleLoginRequest.from(json as AppleLoginRequestInput);
|
||||
}
|
||||
|
||||
toJson(): AppleLoginRequestData {
|
||||
return AppleLoginRequestSchema.parse(this);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
* @file Automatically generated by barrelsby.
|
||||
*/
|
||||
|
||||
export * from "./apple_login_request";
|
||||
export * from "./auth_mode";
|
||||
export * from "./auth_panel_mode";
|
||||
export * from "./facebook_login_request";
|
||||
@@ -18,4 +17,3 @@ export * from "./logout_response";
|
||||
export * from "./refresh_token_request";
|
||||
export * from "./refresh_token_response";
|
||||
export * from "./register_request";
|
||||
export * from "./send_code_request";
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/**
|
||||
* 发送验证码请求 DTO
|
||||
*/
|
||||
import {
|
||||
SendCodeRequestSchema,
|
||||
type SendCodeRequestInput,
|
||||
type SendCodeRequestData,
|
||||
} from "@/data/schemas/auth/send_code_request";
|
||||
|
||||
export class SendCodeRequest {
|
||||
declare readonly email: string;
|
||||
|
||||
private constructor(input: SendCodeRequestInput) {
|
||||
const data = SendCodeRequestSchema.parse(input);
|
||||
Object.assign(this, data);
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
static from(input: SendCodeRequestInput): SendCodeRequest {
|
||||
return new SendCodeRequest(input);
|
||||
}
|
||||
|
||||
static fromJson(json: unknown): SendCodeRequest {
|
||||
return SendCodeRequest.from(json as SendCodeRequestInput);
|
||||
}
|
||||
|
||||
toJson(): SendCodeRequestData {
|
||||
return SendCodeRequestSchema.parse(this);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/**
|
||||
* 消息同步响应 DTO
|
||||
*/
|
||||
import {
|
||||
ChatSyncDataSchema,
|
||||
type ChatSyncDataInput,
|
||||
type ChatSyncDataData,
|
||||
} from "@/data/schemas/chat/chat_sync_data";
|
||||
|
||||
export class ChatSyncData {
|
||||
declare readonly syncedCount: number;
|
||||
declare readonly totalHistory: number;
|
||||
|
||||
private constructor(input: ChatSyncDataInput) {
|
||||
const data = ChatSyncDataSchema.parse(input);
|
||||
Object.assign(this, data);
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
static from(input: ChatSyncDataInput): ChatSyncData {
|
||||
return new ChatSyncData(input);
|
||||
}
|
||||
|
||||
static fromJson(json: unknown): ChatSyncData {
|
||||
return ChatSyncData.from(json as ChatSyncDataInput);
|
||||
}
|
||||
|
||||
toJson(): ChatSyncDataData {
|
||||
return ChatSyncDataSchema.parse(this);
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/**
|
||||
* 消息同步请求 DTO
|
||||
*/
|
||||
import {
|
||||
ChatSyncRequestSchema,
|
||||
type ChatSyncRequestInput,
|
||||
type ChatSyncRequestData,
|
||||
} from "@/data/schemas/chat/chat_sync_request";
|
||||
import { SyncMessage } from "./sync_message";
|
||||
|
||||
export class ChatSyncRequest {
|
||||
declare readonly messages: SyncMessage[];
|
||||
|
||||
private constructor(input: ChatSyncRequestInput) {
|
||||
const data = ChatSyncRequestSchema.parse(input);
|
||||
Object.assign(this, {
|
||||
...data,
|
||||
messages: data.messages.map((m) => SyncMessage.from(m)),
|
||||
});
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
static from(input: ChatSyncRequestInput): ChatSyncRequest {
|
||||
return new ChatSyncRequest(input);
|
||||
}
|
||||
|
||||
static fromJson(json: unknown): ChatSyncRequest {
|
||||
return ChatSyncRequest.from(json as ChatSyncRequestInput);
|
||||
}
|
||||
|
||||
toJson(): ChatSyncRequestData {
|
||||
return ChatSyncRequestSchema.parse(this);
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/**
|
||||
* 图片上传响应 DTO
|
||||
*/
|
||||
import {
|
||||
ImageUploadResponseSchema,
|
||||
type ImageUploadResponseInput,
|
||||
type ImageUploadResponseData,
|
||||
} from "@/data/schemas/chat/image_upload_response";
|
||||
|
||||
export class ImageUploadResponse {
|
||||
declare readonly success: boolean;
|
||||
declare readonly imageId: string;
|
||||
declare readonly thumbUrl: string;
|
||||
declare readonly mediumUrl: string;
|
||||
declare readonly originalUrl: string;
|
||||
declare readonly width: number;
|
||||
declare readonly height: number;
|
||||
declare readonly bytes: number;
|
||||
|
||||
private constructor(input: ImageUploadResponseInput) {
|
||||
const data = ImageUploadResponseSchema.parse(input);
|
||||
Object.assign(this, data);
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
static from(input: ImageUploadResponseInput): ImageUploadResponse {
|
||||
return new ImageUploadResponse(input);
|
||||
}
|
||||
|
||||
static fromJson(json: unknown): ImageUploadResponse {
|
||||
return ImageUploadResponse.from(json as ImageUploadResponseInput);
|
||||
}
|
||||
|
||||
toJson(): ImageUploadResponseData {
|
||||
return ImageUploadResponseSchema.parse(this);
|
||||
}
|
||||
}
|
||||
@@ -7,12 +7,7 @@ export * from "./chat_list_item";
|
||||
export * from "./chat_media";
|
||||
export * from "./chat_message";
|
||||
export * from "./chat_send_response";
|
||||
export * from "./chat_sync_data";
|
||||
export * from "./chat_sync_request";
|
||||
export * from "./image_upload_response";
|
||||
export * from "./send_message_request";
|
||||
export * from "./stt_data";
|
||||
export * from "./sync_message";
|
||||
export * from "./ui_message";
|
||||
export * from "./unlock_history_response";
|
||||
export * from "./unlock_private_request";
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/**
|
||||
* STT(语音转文字)响应 DTO
|
||||
*/
|
||||
import {
|
||||
SttDataSchema,
|
||||
type SttDataInput,
|
||||
type SttDataData,
|
||||
} from "@/data/schemas/chat/stt_data";
|
||||
|
||||
export class SttData {
|
||||
declare readonly text: string;
|
||||
|
||||
private constructor(input: SttDataInput) {
|
||||
const data = SttDataSchema.parse(input);
|
||||
Object.assign(this, data);
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
static from(input: SttDataInput): SttData {
|
||||
return new SttData(input);
|
||||
}
|
||||
|
||||
static fromJson(json: unknown): SttData {
|
||||
return SttData.from(json as SttDataInput);
|
||||
}
|
||||
|
||||
toJson(): SttDataData {
|
||||
return SttDataSchema.parse(this);
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/**
|
||||
* 待同步的单条消息 DTO
|
||||
*/
|
||||
import {
|
||||
SyncMessageSchema,
|
||||
type SyncMessageInput,
|
||||
type SyncMessageData,
|
||||
} from "@/data/schemas/chat/sync_message";
|
||||
|
||||
export class SyncMessage {
|
||||
declare readonly role: string;
|
||||
declare readonly content: string;
|
||||
declare readonly timestamp: string;
|
||||
|
||||
private constructor(input: SyncMessageInput) {
|
||||
const data = SyncMessageSchema.parse(input);
|
||||
Object.assign(this, data);
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
static from(input: SyncMessageInput): SyncMessage {
|
||||
return new SyncMessage(input);
|
||||
}
|
||||
|
||||
static fromJson(json: unknown): SyncMessage {
|
||||
return SyncMessage.from(json as SyncMessageInput);
|
||||
}
|
||||
|
||||
toJson(): SyncMessageData {
|
||||
return SyncMessageSchema.parse(this);
|
||||
}
|
||||
}
|
||||
@@ -7,4 +7,3 @@ export * from "./create_payment_order_response";
|
||||
export * from "./payment_order_status_response";
|
||||
export * from "./payment_plan";
|
||||
export * from "./payment_plans_response";
|
||||
export * from "./payment_vip_status_response";
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
/**
|
||||
* VIP 状态响应 DTO
|
||||
*/
|
||||
import {
|
||||
PaymentVipStatusResponseSchema,
|
||||
type PaymentVipStatusResponseData,
|
||||
type PaymentVipStatusResponseInput,
|
||||
} from "@/data/schemas/payment/payment_vip_status_response";
|
||||
|
||||
export class PaymentVipStatusResponse {
|
||||
declare readonly isVip: boolean;
|
||||
declare readonly vipExpiresAt: string | null;
|
||||
|
||||
private constructor(input: PaymentVipStatusResponseInput) {
|
||||
const data = PaymentVipStatusResponseSchema.parse(input);
|
||||
Object.assign(this, data);
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
static from(input: PaymentVipStatusResponseInput): PaymentVipStatusResponse {
|
||||
return new PaymentVipStatusResponse(input);
|
||||
}
|
||||
|
||||
static fromJson(json: unknown): PaymentVipStatusResponse {
|
||||
return PaymentVipStatusResponse.from(
|
||||
json as PaymentVipStatusResponseInput,
|
||||
);
|
||||
}
|
||||
|
||||
toJson(): PaymentVipStatusResponseData {
|
||||
return PaymentVipStatusResponseSchema.parse(this);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/**
|
||||
* 积分数据 DTO
|
||||
*/
|
||||
import {
|
||||
CreditsDataSchema,
|
||||
type CreditsDataInput,
|
||||
type CreditsDataData,
|
||||
} from "@/data/schemas/user/credits_data";
|
||||
|
||||
export class CreditsData {
|
||||
declare readonly userId: string;
|
||||
declare readonly dolBalance: number;
|
||||
|
||||
private constructor(input: CreditsDataInput) {
|
||||
const data = CreditsDataSchema.parse(input);
|
||||
Object.assign(this, data);
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
static from(input: CreditsDataInput): CreditsData {
|
||||
return new CreditsData(input);
|
||||
}
|
||||
|
||||
static fromJson(json: unknown): CreditsData {
|
||||
return CreditsData.from(json as CreditsDataInput);
|
||||
}
|
||||
|
||||
toJson(): CreditsDataData {
|
||||
return CreditsDataSchema.parse(this);
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/**
|
||||
* 积分历史记录 DTO
|
||||
*/
|
||||
import {
|
||||
CreditsHistoryDataSchema,
|
||||
type CreditsHistoryDataInput,
|
||||
type CreditsHistoryDataData,
|
||||
} from "@/data/schemas/user/credits_history_data";
|
||||
|
||||
export class CreditsHistoryData {
|
||||
declare readonly records: Record<string, unknown>[];
|
||||
declare readonly total: number;
|
||||
declare readonly limit: number;
|
||||
declare readonly offset: number;
|
||||
|
||||
private constructor(input: CreditsHistoryDataInput) {
|
||||
const data = CreditsHistoryDataSchema.parse(input);
|
||||
Object.assign(this, data);
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
static from(input: CreditsHistoryDataInput): CreditsHistoryData {
|
||||
return new CreditsHistoryData(input);
|
||||
}
|
||||
|
||||
static fromJson(json: unknown): CreditsHistoryData {
|
||||
return CreditsHistoryData.from(json as CreditsHistoryDataInput);
|
||||
}
|
||||
|
||||
toJson(): CreditsHistoryDataData {
|
||||
return CreditsHistoryDataSchema.parse(this);
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,8 @@
|
||||
*/
|
||||
|
||||
export * from "./avatar_data";
|
||||
export * from "./credits_data";
|
||||
export * from "./credits_history_data";
|
||||
export * from "./personality_traits";
|
||||
export * from "./recent_memory";
|
||||
export * from "./update_profile_request";
|
||||
export * from "./user";
|
||||
export * from "./user_entitlements";
|
||||
export * from "./user_stats_response";
|
||||
export * from "./user_view";
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
/**
|
||||
* 更新个人资料请求 DTO
|
||||
*/
|
||||
import {
|
||||
UpdateProfileRequestSchema,
|
||||
type UpdateProfileRequestInput,
|
||||
type UpdateProfileRequestData,
|
||||
} from "@/data/schemas/user/update_profile_request";
|
||||
|
||||
export class UpdateProfileRequest {
|
||||
declare readonly username: string;
|
||||
declare readonly nickname: string;
|
||||
declare readonly preferredLanguage: string;
|
||||
declare readonly currentMood: string;
|
||||
|
||||
private constructor(input: UpdateProfileRequestInput) {
|
||||
const data = UpdateProfileRequestSchema.parse(input);
|
||||
Object.assign(this, data);
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
static from(input: UpdateProfileRequestInput): UpdateProfileRequest {
|
||||
return new UpdateProfileRequest(input);
|
||||
}
|
||||
|
||||
static fromJson(json: unknown): UpdateProfileRequest {
|
||||
return UpdateProfileRequest.from(json as UpdateProfileRequestInput);
|
||||
}
|
||||
|
||||
toJson(): UpdateProfileRequestData {
|
||||
return UpdateProfileRequestSchema.parse(this);
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/**
|
||||
* 用户统计响应 DTO
|
||||
*/
|
||||
import {
|
||||
UserStatsResponseSchema,
|
||||
type UserStatsResponseInput,
|
||||
type UserStatsResponseData,
|
||||
} from "@/data/schemas/user/user_stats_response";
|
||||
import { PersonalityTraits } from "./personality_traits";
|
||||
import { RecentMemory } from "./recent_memory";
|
||||
|
||||
export class UserStatsResponse {
|
||||
declare readonly userId: string;
|
||||
declare readonly username: string;
|
||||
declare readonly platform: string;
|
||||
declare readonly intimacy: number;
|
||||
declare readonly relationshipStage: string;
|
||||
declare readonly dolBalance: number;
|
||||
declare readonly totalMessages: number;
|
||||
declare readonly lastMessageAt: string;
|
||||
declare readonly accountCreatedAt: string;
|
||||
declare readonly currentMood: string;
|
||||
declare readonly personalityTraits: PersonalityTraits;
|
||||
declare readonly recentMemories: RecentMemory[];
|
||||
declare readonly promptTokensTotal: number;
|
||||
declare readonly completionTokensTotal: number;
|
||||
declare readonly cacheHitTokensTotal: number;
|
||||
declare readonly tokensTotal: number;
|
||||
|
||||
private constructor(input: UserStatsResponseInput) {
|
||||
const data = UserStatsResponseSchema.parse(input);
|
||||
Object.assign(this, {
|
||||
...data,
|
||||
personalityTraits: PersonalityTraits.from(data.personalityTraits),
|
||||
recentMemories: data.recentMemories.map((m) => RecentMemory.from(m)),
|
||||
});
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
static from(input: UserStatsResponseInput): UserStatsResponse {
|
||||
return new UserStatsResponse(input);
|
||||
}
|
||||
|
||||
static fromJson(json: unknown): UserStatsResponse {
|
||||
return UserStatsResponse.from(json as UserStatsResponseInput);
|
||||
}
|
||||
|
||||
toJson(): UserStatsResponseData {
|
||||
return UserStatsResponseSchema.parse(this);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
import { ExceptionHandler } from "@/core/errors";
|
||||
import { ApiError, AuthApi, authApi, ErrorCode } from "@/data/services/api";
|
||||
import {
|
||||
AppleLoginRequest,
|
||||
FacebookLoginRequest,
|
||||
FbIdLoginRequest,
|
||||
GoogleLoginRequest,
|
||||
@@ -16,7 +15,6 @@ import {
|
||||
RefreshTokenRequest,
|
||||
RefreshTokenResponse,
|
||||
RegisterRequest,
|
||||
SendCodeRequest,
|
||||
} from "@/data/dto/auth";
|
||||
import { User } from "@/data/dto/user";
|
||||
import {
|
||||
@@ -94,13 +92,6 @@ export class AuthRepository implements IAuthRepository {
|
||||
});
|
||||
}
|
||||
|
||||
/** 发送邮箱验证码。 */
|
||||
async sendCode(email: string): Promise<Result<void>> {
|
||||
return Result.wrap(async () => {
|
||||
await this.api.sendCode(SendCodeRequest.from({ email }));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出真实用户登录并恢复游客态。
|
||||
*
|
||||
@@ -231,24 +222,6 @@ export class AuthRepository implements IAuthRepository {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apple 登录。
|
||||
* 注:Dart 端另有一个 `uploadFacebookAvatar` 方法,但当前 TS 端 `AuthApi`
|
||||
* 尚未实现该端点,故仓库暂不暴露。等 `AuthApi` 补齐后再加。
|
||||
*/
|
||||
async appleLogin(identityToken: string): Promise<Result<LoginResponse>> {
|
||||
return this._socialLogin(LoginStatus.Apple, () =>
|
||||
this.api.appleLogin(
|
||||
AppleLoginRequest.from(
|
||||
withTestAccountFlag({
|
||||
identityToken,
|
||||
platform: getAuthPlatform(),
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新 token:先读本地的 refresh token,空则直接返回错误;
|
||||
* 调用 API 成功后写回新的 login token + refresh token。
|
||||
|
||||
@@ -38,9 +38,6 @@ export interface IAuthRepository {
|
||||
guestId?: string;
|
||||
}): Promise<Result<LoginResponse>>;
|
||||
|
||||
/** 发送邮箱验证码。 */
|
||||
sendCode(email: string): Promise<Result<void>>;
|
||||
|
||||
/** 退出真实用户登录并恢复游客态。 */
|
||||
logout(): Promise<Result<void>>;
|
||||
|
||||
@@ -65,9 +62,6 @@ export interface IAuthRepository {
|
||||
avatarUrl?: string;
|
||||
}): Promise<Result<LoginResponse>>;
|
||||
|
||||
/** Apple 登录。 */
|
||||
appleLogin(identityToken: string): Promise<Result<LoginResponse>>;
|
||||
|
||||
/** 刷新 token:先读本地的 refresh token,空则返回错误。 */
|
||||
refreshToken(): Promise<Result<RefreshTokenResponse>>;
|
||||
|
||||
|
||||
@@ -7,9 +7,7 @@ import type {
|
||||
CreatePaymentOrderResponse,
|
||||
PayChannel,
|
||||
PaymentOrderStatusResponse,
|
||||
PaymentPlan,
|
||||
PaymentPlansResponse,
|
||||
PaymentVipStatusResponse,
|
||||
} from "@/data/dto/payment";
|
||||
import type { Result } from "@/utils/result";
|
||||
|
||||
@@ -23,12 +21,6 @@ export interface IPaymentRepository {
|
||||
/** 清除本地缓存套餐列表。 */
|
||||
clearCachedPlans(): Promise<Result<void>>;
|
||||
|
||||
/** 获取会员套餐列表。 */
|
||||
getVipPlans(): Promise<Result<PaymentPlan[]>>;
|
||||
|
||||
/** 获取积分套餐列表。 */
|
||||
getCreditPlans(): Promise<Result<PaymentPlan[]>>;
|
||||
|
||||
/** 创建支付订单。 */
|
||||
createOrder(
|
||||
planId: string,
|
||||
@@ -38,7 +30,4 @@ export interface IPaymentRepository {
|
||||
|
||||
/** 查询支付订单状态。 */
|
||||
getOrderStatus(orderId: string): Promise<Result<PaymentOrderStatusResponse>>;
|
||||
|
||||
/** 查询当前用户 VIP 状态。 */
|
||||
getVipStatus(): Promise<Result<PaymentVipStatusResponse>>;
|
||||
}
|
||||
|
||||
@@ -6,33 +6,14 @@
|
||||
|
||||
import type { Result } from "@/utils";
|
||||
import type {
|
||||
CreditsData,
|
||||
CreditsHistoryData,
|
||||
UpdateProfileRequest,
|
||||
User,
|
||||
UserEntitlements,
|
||||
UserStatsResponse,
|
||||
} from "@/data/dto/user";
|
||||
|
||||
export interface IUserRepository {
|
||||
/** 获取用户统计信息。 */
|
||||
getUserStats(): Promise<Result<UserStatsResponse>>;
|
||||
|
||||
/** 获取当前登录用户信息。 */
|
||||
getCurrentUser(): Promise<Result<User>>;
|
||||
|
||||
/** 更新个人资料。 */
|
||||
updateProfile(request: UpdateProfileRequest): Promise<Result<User>>;
|
||||
|
||||
/** 查询积分余额。 */
|
||||
getCredits(): Promise<Result<CreditsData>>;
|
||||
|
||||
/** 查询积分操作历史,分页参数默认 limit=50, offset=0。 */
|
||||
getCreditsHistory(
|
||||
limit?: number,
|
||||
offset?: number,
|
||||
): Promise<Result<CreditsHistoryData>>;
|
||||
|
||||
/** 获取当前用户权益快照。 */
|
||||
getEntitlements(): Promise<Result<UserEntitlements>>;
|
||||
}
|
||||
|
||||
@@ -10,9 +10,7 @@ import {
|
||||
CreatePaymentOrderResponse,
|
||||
PayChannel,
|
||||
PaymentOrderStatusResponse,
|
||||
PaymentPlan,
|
||||
PaymentPlansResponse,
|
||||
PaymentVipStatusResponse,
|
||||
} from "@/data/dto/payment";
|
||||
import { PaymentApi, paymentApi } from "@/data/services/api";
|
||||
import { PaymentPlansStorage } from "@/data/storage/payment";
|
||||
@@ -49,22 +47,6 @@ export class PaymentRepository implements IPaymentRepository {
|
||||
});
|
||||
}
|
||||
|
||||
/** 获取会员套餐列表。 */
|
||||
async getVipPlans(): Promise<Result<PaymentPlan[]>> {
|
||||
return Result.wrap(async () => {
|
||||
const response = await this.api.getPlans();
|
||||
return response.plans.filter(isVipPaymentPlan);
|
||||
});
|
||||
}
|
||||
|
||||
/** 获取积分套餐列表。 */
|
||||
async getCreditPlans(): Promise<Result<PaymentPlan[]>> {
|
||||
return Result.wrap(async () => {
|
||||
const response = await this.api.getPlans();
|
||||
return response.plans.filter(isCreditPaymentPlan);
|
||||
});
|
||||
}
|
||||
|
||||
/** 创建支付订单。 */
|
||||
async createOrder(
|
||||
planId: string,
|
||||
@@ -86,21 +68,9 @@ export class PaymentRepository implements IPaymentRepository {
|
||||
return Result.wrap(() => this.api.getOrderStatus(orderId));
|
||||
}
|
||||
|
||||
/** 查询当前用户 VIP 状态。 */
|
||||
async getVipStatus(): Promise<Result<PaymentVipStatusResponse>> {
|
||||
return Result.wrap(() => this.api.getVipStatus());
|
||||
}
|
||||
}
|
||||
|
||||
/** 全局懒单例。 */
|
||||
export const getPaymentRepository = createLazySingleton<IPaymentRepository>(
|
||||
() => new PaymentRepository(paymentApi),
|
||||
);
|
||||
|
||||
export function isVipPaymentPlan(plan: PaymentPlan): boolean {
|
||||
return plan.vipDays !== null;
|
||||
}
|
||||
|
||||
export function isCreditPaymentPlan(plan: PaymentPlan): boolean {
|
||||
return plan.dolAmount !== null;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
"use client";
|
||||
import { UserApi, userApi } from "@/data/services/api";
|
||||
import {
|
||||
CreditsData,
|
||||
CreditsHistoryData,
|
||||
UpdateProfileRequest,
|
||||
User,
|
||||
UserEntitlements,
|
||||
UserStatsResponse,
|
||||
} from "@/data/dto/user";
|
||||
import { Result } from "@/utils";
|
||||
import type { IUserRepository } from "@/data/repositories/interfaces";
|
||||
@@ -15,34 +11,11 @@ import { createLazySingleton } from "./lazy_singleton";
|
||||
export class UserRepository implements IUserRepository {
|
||||
constructor(private readonly api: UserApi) {}
|
||||
|
||||
/** 获取用户统计信息。 */
|
||||
async getUserStats(): Promise<Result<UserStatsResponse>> {
|
||||
return Result.wrap(() => this.api.getUserStats());
|
||||
}
|
||||
|
||||
/** 获取当前登录用户信息。 */
|
||||
async getCurrentUser(): Promise<Result<User>> {
|
||||
return Result.wrap(() => this.api.getCurrentUser());
|
||||
}
|
||||
|
||||
/** 更新个人资料。 */
|
||||
async updateProfile(request: UpdateProfileRequest): Promise<Result<User>> {
|
||||
return Result.wrap(() => this.api.updateProfile(request));
|
||||
}
|
||||
|
||||
/** 查询积分余额。 */
|
||||
async getCredits(): Promise<Result<CreditsData>> {
|
||||
return Result.wrap(() => this.api.getCredits());
|
||||
}
|
||||
|
||||
/** 查询积分操作历史,分页参数默认 limit=50, offset=0。 */
|
||||
async getCreditsHistory(
|
||||
limit = 50,
|
||||
offset = 0,
|
||||
): Promise<Result<CreditsHistoryData>> {
|
||||
return Result.wrap(() => this.api.getCreditsHistory(limit, offset));
|
||||
}
|
||||
|
||||
/** 获取当前用户权益快照。 */
|
||||
async getEntitlements(): Promise<Result<UserEntitlements>> {
|
||||
return Result.wrap(() => this.api.getEntitlements());
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
/**
|
||||
* Apple 登录请求
|
||||
*
|
||||
*/
|
||||
import { z } from "zod";
|
||||
|
||||
import { booleanOrFalse } from "../nullable-defaults";
|
||||
|
||||
export const AppleLoginRequestSchema = z.object({
|
||||
identityToken: z.string(),
|
||||
platform: z.string(),
|
||||
isTestAccount: booleanOrFalse,
|
||||
});
|
||||
|
||||
export type AppleLoginRequestInput = z.input<typeof AppleLoginRequestSchema>;
|
||||
export type AppleLoginRequestData = z.output<typeof AppleLoginRequestSchema>;
|
||||
@@ -2,7 +2,6 @@
|
||||
* @file Automatically generated by barrelsby.
|
||||
*/
|
||||
|
||||
export * from "./apple_login_request";
|
||||
export * from "./facebook_login_request";
|
||||
export * from "./facebook_user_data";
|
||||
export * from "./fb_id_login_request";
|
||||
@@ -15,4 +14,3 @@ export * from "./logout_response";
|
||||
export * from "./refresh_token_request";
|
||||
export * from "./refresh_token_response";
|
||||
export * from "./register_request";
|
||||
export * from "./send_code_request";
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
/**
|
||||
* 发送验证码请求
|
||||
*
|
||||
*/
|
||||
import { z } from "zod";
|
||||
|
||||
export const SendCodeRequestSchema = z.object({
|
||||
email: z.string(),
|
||||
});
|
||||
|
||||
export type SendCodeRequestInput = z.input<typeof SendCodeRequestSchema>;
|
||||
export type SendCodeRequestData = z.output<typeof SendCodeRequestSchema>;
|
||||
@@ -1,15 +0,0 @@
|
||||
/**
|
||||
* 消息同步响应
|
||||
*
|
||||
*/
|
||||
import { z } from "zod";
|
||||
|
||||
import { numberOrZero } from "../nullable-defaults";
|
||||
|
||||
export const ChatSyncDataSchema = z.object({
|
||||
syncedCount: numberOrZero,
|
||||
totalHistory: numberOrZero,
|
||||
});
|
||||
|
||||
export type ChatSyncDataInput = z.input<typeof ChatSyncDataSchema>;
|
||||
export type ChatSyncDataData = z.output<typeof ChatSyncDataSchema>;
|
||||
@@ -1,13 +0,0 @@
|
||||
/**
|
||||
* 消息同步请求
|
||||
*
|
||||
*/
|
||||
import { z } from "zod";
|
||||
import { SyncMessageSchema } from "./sync_message";
|
||||
|
||||
export const ChatSyncRequestSchema = z.object({
|
||||
messages: z.array(SyncMessageSchema),
|
||||
});
|
||||
|
||||
export type ChatSyncRequestInput = z.input<typeof ChatSyncRequestSchema>;
|
||||
export type ChatSyncRequestData = z.output<typeof ChatSyncRequestSchema>;
|
||||
@@ -1,21 +0,0 @@
|
||||
/**
|
||||
* 图片上传响应
|
||||
*
|
||||
*/
|
||||
import { z } from "zod";
|
||||
|
||||
import { booleanOrTrue, numberOrZero, stringOrEmpty } from "../nullable-defaults";
|
||||
|
||||
export const ImageUploadResponseSchema = z.object({
|
||||
success: booleanOrTrue,
|
||||
imageId: stringOrEmpty,
|
||||
thumbUrl: stringOrEmpty,
|
||||
mediumUrl: stringOrEmpty,
|
||||
originalUrl: stringOrEmpty,
|
||||
width: numberOrZero,
|
||||
height: numberOrZero,
|
||||
bytes: numberOrZero,
|
||||
});
|
||||
|
||||
export type ImageUploadResponseInput = z.input<typeof ImageUploadResponseSchema>;
|
||||
export type ImageUploadResponseData = z.output<typeof ImageUploadResponseSchema>;
|
||||
@@ -6,12 +6,7 @@ export * from "./chat_history_response";
|
||||
export * from "./chat_message";
|
||||
export * from "./chat_payloads";
|
||||
export * from "./chat_send_response";
|
||||
export * from "./chat_sync_data";
|
||||
export * from "./chat_sync_request";
|
||||
export * from "./image_upload_response";
|
||||
export * from "./send_message_request";
|
||||
export * from "./stt_data";
|
||||
export * from "./sync_message";
|
||||
export * from "./unlock_history_response";
|
||||
export * from "./unlock_private_request";
|
||||
export * from "./unlock_private_response";
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
/**
|
||||
* STT(语音转文字)响应
|
||||
*
|
||||
*/
|
||||
import { z } from "zod";
|
||||
|
||||
import { stringOrEmpty } from "../nullable-defaults";
|
||||
|
||||
export const SttDataSchema = z.object({
|
||||
text: stringOrEmpty,
|
||||
});
|
||||
|
||||
export type SttDataInput = z.input<typeof SttDataSchema>;
|
||||
export type SttDataData = z.output<typeof SttDataSchema>;
|
||||
@@ -1,16 +0,0 @@
|
||||
/**
|
||||
* 待同步的单条消息
|
||||
*
|
||||
*/
|
||||
import { z } from "zod";
|
||||
|
||||
import { stringOrEmpty } from "../nullable-defaults";
|
||||
|
||||
export const SyncMessageSchema = z.object({
|
||||
role: stringOrEmpty,
|
||||
content: stringOrEmpty,
|
||||
timestamp: stringOrEmpty,
|
||||
});
|
||||
|
||||
export type SyncMessageInput = z.input<typeof SyncMessageSchema>;
|
||||
export type SyncMessageData = z.output<typeof SyncMessageSchema>;
|
||||
@@ -7,4 +7,3 @@ export * from "./create_payment_order_response";
|
||||
export * from "./payment_order_status_response";
|
||||
export * from "./payment_plan";
|
||||
export * from "./payment_plans_response";
|
||||
export * from "./payment_vip_status_response";
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
/**
|
||||
* VIP 状态响应
|
||||
*/
|
||||
import { z } from "zod";
|
||||
|
||||
import { booleanOrFalse, stringOrNull } from "../nullable-defaults";
|
||||
|
||||
export const PaymentVipStatusResponseSchema = z.object({
|
||||
isVip: booleanOrFalse,
|
||||
vipExpiresAt: stringOrNull,
|
||||
});
|
||||
|
||||
export type PaymentVipStatusResponseInput = z.input<
|
||||
typeof PaymentVipStatusResponseSchema
|
||||
>;
|
||||
export type PaymentVipStatusResponseData = z.output<
|
||||
typeof PaymentVipStatusResponseSchema
|
||||
>;
|
||||
@@ -1,15 +0,0 @@
|
||||
/**
|
||||
* 积分数据模型
|
||||
*
|
||||
*/
|
||||
import { z } from "zod";
|
||||
|
||||
import { numberOrZero, stringOrEmpty } from "../nullable-defaults";
|
||||
|
||||
export const CreditsDataSchema = z.object({
|
||||
userId: stringOrEmpty,
|
||||
dolBalance: numberOrZero,
|
||||
});
|
||||
|
||||
export type CreditsDataInput = z.input<typeof CreditsDataSchema>;
|
||||
export type CreditsDataData = z.output<typeof CreditsDataSchema>;
|
||||
@@ -1,17 +0,0 @@
|
||||
/**
|
||||
* 积分历史记录模型
|
||||
*
|
||||
*/
|
||||
import { z } from "zod";
|
||||
|
||||
import { arrayOrEmpty, numberOrZero } from "../nullable-defaults";
|
||||
|
||||
export const CreditsHistoryDataSchema = z.object({
|
||||
records: arrayOrEmpty(z.record(z.string(), z.unknown())),
|
||||
total: numberOrZero,
|
||||
limit: numberOrZero,
|
||||
offset: numberOrZero,
|
||||
});
|
||||
|
||||
export type CreditsHistoryDataInput = z.input<typeof CreditsHistoryDataSchema>;
|
||||
export type CreditsHistoryDataData = z.output<typeof CreditsHistoryDataSchema>;
|
||||
@@ -3,13 +3,9 @@
|
||||
*/
|
||||
|
||||
export * from "./avatar_data";
|
||||
export * from "./credits_data";
|
||||
export * from "./credits_history_data";
|
||||
export * from "./persisted_user";
|
||||
export * from "./personality_traits";
|
||||
export * from "./recent_memory";
|
||||
export * from "./update_profile_request";
|
||||
export * from "./user";
|
||||
export * from "./user_entitlement_snapshot";
|
||||
export * from "./user_entitlements";
|
||||
export * from "./user_stats_response";
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
/**
|
||||
* 更新个人资料请求
|
||||
*
|
||||
*/
|
||||
import { z } from "zod";
|
||||
|
||||
import { stringOrEmpty } from "../nullable-defaults";
|
||||
|
||||
export const UpdateProfileRequestSchema = z.object({
|
||||
username: stringOrEmpty,
|
||||
nickname: stringOrEmpty,
|
||||
preferredLanguage: stringOrEmpty,
|
||||
currentMood: stringOrEmpty,
|
||||
});
|
||||
|
||||
export type UpdateProfileRequestInput = z.input<typeof UpdateProfileRequestSchema>;
|
||||
export type UpdateProfileRequestData = z.output<typeof UpdateProfileRequestSchema>;
|
||||
@@ -1,36 +0,0 @@
|
||||
/**
|
||||
* 用户统计响应
|
||||
*
|
||||
*/
|
||||
import { z } from "zod";
|
||||
|
||||
import {
|
||||
arrayOrEmpty,
|
||||
numberOrZero,
|
||||
schemaOr,
|
||||
stringOrEmpty,
|
||||
} from "../nullable-defaults";
|
||||
import { PersonalityTraitsSchema, PERSONALITY_TRAITS_DEFAULTS } from "./personality_traits";
|
||||
import { RecentMemorySchema } from "./recent_memory";
|
||||
|
||||
export const UserStatsResponseSchema = z.object({
|
||||
userId: stringOrEmpty,
|
||||
username: stringOrEmpty,
|
||||
platform: stringOrEmpty,
|
||||
intimacy: numberOrZero,
|
||||
relationshipStage: stringOrEmpty,
|
||||
dolBalance: numberOrZero,
|
||||
totalMessages: numberOrZero,
|
||||
lastMessageAt: stringOrEmpty,
|
||||
accountCreatedAt: stringOrEmpty,
|
||||
currentMood: stringOrEmpty,
|
||||
personalityTraits: schemaOr(PersonalityTraitsSchema, PERSONALITY_TRAITS_DEFAULTS),
|
||||
recentMemories: arrayOrEmpty(RecentMemorySchema),
|
||||
promptTokensTotal: numberOrZero,
|
||||
completionTokensTotal: numberOrZero,
|
||||
cacheHitTokensTotal: numberOrZero,
|
||||
tokensTotal: numberOrZero,
|
||||
});
|
||||
|
||||
export type UserStatsResponseInput = z.input<typeof UserStatsResponseSchema>;
|
||||
export type UserStatsResponseData = z.output<typeof UserStatsResponseSchema>;
|
||||
@@ -11,15 +11,11 @@ export class ApiPath {
|
||||
|
||||
// ============ 功能模块分组 ============
|
||||
private static readonly _auth = `${ApiPath._baseUrl}/auth`;
|
||||
private static readonly _verify = `${ApiPath._baseUrl}/verify`;
|
||||
private static readonly _user = `${ApiPath._baseUrl}/user`;
|
||||
private static readonly _payment = `${ApiPath._baseUrl}/payment`;
|
||||
private static readonly _chat = `${ApiPath._baseUrl}/chat`;
|
||||
|
||||
// ============ 认证相关 ============
|
||||
/** 发送验证码 */
|
||||
static readonly sendCode = `${ApiPath._verify}/send`;
|
||||
|
||||
/** 邮箱密码登录 */
|
||||
static readonly emailLogin = `${ApiPath._auth}/login`;
|
||||
|
||||
@@ -29,9 +25,6 @@ export class ApiPath {
|
||||
/** 设备自动登录 */
|
||||
static readonly guestLogin = `${ApiPath._auth}/guest`;
|
||||
|
||||
/** Apple 登录 */
|
||||
static readonly appleLogin = `${ApiPath._auth}/login/apple`;
|
||||
|
||||
/** Google 登录 */
|
||||
static readonly googleLogin = `${ApiPath._auth}/login/google`;
|
||||
|
||||
@@ -51,24 +44,9 @@ export class ApiPath {
|
||||
static readonly getCurrentUser = `${ApiPath._auth}/me`;
|
||||
|
||||
// ============ 用户相关 ============
|
||||
/** 获取用户统计信息 */
|
||||
static readonly userStats = `${ApiPath._user}/stats`;
|
||||
|
||||
/** 获取个人信息(与 /auth/me 等价) */
|
||||
static readonly userProfile = `${ApiPath._user}/profile`;
|
||||
|
||||
/** 更新个人信息 */
|
||||
static readonly updateProfile = `${ApiPath._user}/profile`;
|
||||
|
||||
/** 上传头像 */
|
||||
static readonly userAvatar = `${ApiPath._user}/avatar`;
|
||||
|
||||
/** 查询积分余额 */
|
||||
static readonly userCredits = `${ApiPath._user}/credits`;
|
||||
|
||||
/** 查询积分操作历史 */
|
||||
static readonly userCreditsHistory = `${ApiPath._user}/credits/history`;
|
||||
|
||||
/** 获取当前用户权益快照 */
|
||||
static readonly userEntitlements = `${ApiPath._user}/entitlements`;
|
||||
|
||||
@@ -82,20 +60,6 @@ export class ApiPath {
|
||||
/** 获取商品套餐列表 */
|
||||
static readonly paymentPlans = `${ApiPath._payment}/plans`;
|
||||
|
||||
/** 查询当前用户 VIP 状态 */
|
||||
static readonly paymentVipStatus = `${ApiPath._payment}/vip-status`;
|
||||
|
||||
/** @deprecated PAYWALL_API 使用 paymentPlans。 */
|
||||
static readonly paymentProducts = ApiPath.paymentPlans;
|
||||
|
||||
/** 申请退款 */
|
||||
static readonly paymentRefund = `${ApiPath._payment}/refund`;
|
||||
|
||||
/** 获取商品详情路径 */
|
||||
static getPaymentProductDetail(productId: string): string {
|
||||
return `${ApiPath.paymentProducts}/${productId}`;
|
||||
}
|
||||
|
||||
// ============ 聊天相关 ============
|
||||
/** 发送消息 */
|
||||
static readonly chatSend = `${ApiPath._chat}/send`;
|
||||
@@ -103,15 +67,6 @@ export class ApiPath {
|
||||
/** 获取聊天历史 */
|
||||
static readonly chatHistory = `${ApiPath._chat}/history`;
|
||||
|
||||
/** 语音转文字(STT) */
|
||||
static readonly chatStt = `${ApiPath._chat}/stt`;
|
||||
|
||||
/** 同步游客消息 */
|
||||
static readonly chatSync = `${ApiPath._chat}/sync`;
|
||||
|
||||
/** 上传图片 */
|
||||
static readonly chatUploadImage = `${ApiPath._chat}/upload-image`;
|
||||
|
||||
/** 解锁私密消息 */
|
||||
static readonly chatUnlockPrivate = `${ApiPath._chat}/unlock-private`;
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import { httpClient } from "./http_client";
|
||||
import { ApiPath } from "./api_path";
|
||||
import { ApiEnvelope, unwrap } from "./response_helper";
|
||||
import {
|
||||
AppleLoginRequest,
|
||||
FacebookLoginRequest,
|
||||
FbIdLoginRequest,
|
||||
GoogleLoginRequest,
|
||||
@@ -21,7 +20,6 @@ import {
|
||||
RefreshTokenRequest,
|
||||
RefreshTokenResponse,
|
||||
RegisterRequest,
|
||||
SendCodeRequest,
|
||||
} from "@/data/dto/auth";
|
||||
import { User } from "@/data/dto/user";
|
||||
import type { UserData } from "@/data/schemas/user/user";
|
||||
@@ -30,16 +28,6 @@ import { Logger } from "@/utils";
|
||||
const log = new Logger("DataServicesApiAuthApi");
|
||||
|
||||
export class AuthApi {
|
||||
/**
|
||||
* 发送验证码
|
||||
*/
|
||||
async sendCode(body: SendCodeRequest): Promise<void> {
|
||||
await httpClient<ApiEnvelope<unknown>>(ApiPath.sendCode, {
|
||||
method: "POST",
|
||||
body: body.toJson(),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 邮箱密码登录
|
||||
*/
|
||||
@@ -61,17 +49,6 @@ export class AuthApi {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Apple 登录
|
||||
*/
|
||||
async appleLogin(body: AppleLoginRequest): Promise<LoginResponse> {
|
||||
const env = await httpClient<ApiEnvelope<unknown>>(ApiPath.appleLogin, {
|
||||
method: "POST",
|
||||
body: body.toJson(),
|
||||
});
|
||||
return LoginResponse.fromJson(unwrap(env) as Record<string, unknown>);
|
||||
}
|
||||
|
||||
/**
|
||||
* Google 登录
|
||||
*/
|
||||
@@ -112,7 +89,7 @@ export class AuthApi {
|
||||
* 不要再用 `unwrap` + `LogoutResponse.fromJson` 解析 —— Zod schema 是 z.object,
|
||||
* 对 null 会抛 ZodError "Invalid input: expected object, received null"。
|
||||
*
|
||||
* 对齐 `register` / `sendCode` 的写法:调通就完事,不解析响应体。
|
||||
* 对齐 `register` 的写法:调通就完事,不解析响应体。
|
||||
*/
|
||||
async logout(): Promise<void> {
|
||||
await httpClient<ApiEnvelope<unknown>>(ApiPath.logout, {
|
||||
|
||||
@@ -10,12 +10,7 @@ import { ApiEnvelope, unwrap } from "./response_helper";
|
||||
import {
|
||||
ChatHistoryResponse,
|
||||
ChatSendResponse,
|
||||
ChatSyncData,
|
||||
ChatSyncRequest,
|
||||
ImageUploadResponse,
|
||||
SendMessageRequest,
|
||||
SttData,
|
||||
SyncMessage,
|
||||
UnlockHistoryResponse,
|
||||
UnlockPrivateRequest,
|
||||
UnlockPrivateResponse,
|
||||
@@ -45,46 +40,6 @@ export class ChatApi {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 语音转文字(multipart 上传)
|
||||
*/
|
||||
async speechToText(audio: Blob | File): Promise<SttData> {
|
||||
const formData = new FormData();
|
||||
formData.append("audio", audio);
|
||||
const env = await httpClient<ApiEnvelope<unknown>>(ApiPath.chatStt, {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
});
|
||||
return SttData.fromJson(unwrap(env) as Record<string, unknown>);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步游客消息
|
||||
*/
|
||||
async syncMessages(messages: SyncMessage[]): Promise<ChatSyncData> {
|
||||
const body = ChatSyncRequest.from({ messages });
|
||||
const env = await httpClient<ApiEnvelope<unknown>>(ApiPath.chatSync, {
|
||||
method: "POST",
|
||||
body: body.toJson(),
|
||||
});
|
||||
return ChatSyncData.fromJson(unwrap(env) as Record<string, unknown>);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传图片
|
||||
*/
|
||||
async uploadImage(image: Blob | File): Promise<ImageUploadResponse> {
|
||||
const formData = new FormData();
|
||||
formData.append("image", image);
|
||||
const env = await httpClient<ApiEnvelope<unknown>>(
|
||||
ApiPath.chatUploadImage,
|
||||
{ method: "POST", body: formData }
|
||||
);
|
||||
return ImageUploadResponse.fromJson(
|
||||
unwrap(env) as Record<string, unknown>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解锁单条历史付费 / 私密消息
|
||||
*/
|
||||
|
||||
@@ -8,7 +8,6 @@ import {
|
||||
CreatePaymentOrderResponse,
|
||||
PaymentOrderStatusResponse,
|
||||
PaymentPlansResponse,
|
||||
PaymentVipStatusResponse,
|
||||
} from "@/data/dto/payment";
|
||||
|
||||
import { ApiPath } from "./api_path";
|
||||
@@ -61,17 +60,6 @@ export class PaymentApi {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当前用户 VIP 状态
|
||||
*/
|
||||
async getVipStatus(): Promise<PaymentVipStatusResponse> {
|
||||
const env = await httpClient<ApiEnvelope<unknown>>(
|
||||
ApiPath.paymentVipStatus,
|
||||
);
|
||||
return PaymentVipStatusResponse.fromJson(
|
||||
unwrap(env) as Record<string, unknown>,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,26 +8,12 @@ import { httpClient } from "./http_client";
|
||||
import { ApiPath } from "./api_path";
|
||||
import { ApiEnvelope, unwrap } from "./response_helper";
|
||||
import {
|
||||
CreditsData,
|
||||
CreditsHistoryData,
|
||||
UpdateProfileRequest,
|
||||
User,
|
||||
UserEntitlements,
|
||||
UserStatsResponse,
|
||||
} from "@/data/dto/user";
|
||||
import type { UserData } from "@/data/schemas/user/user";
|
||||
|
||||
export class UserApi {
|
||||
/**
|
||||
* 获取用户统计信息
|
||||
*/
|
||||
async getUserStats(): Promise<UserStatsResponse> {
|
||||
const env = await httpClient<ApiEnvelope<unknown>>(ApiPath.userStats);
|
||||
return UserStatsResponse.fromJson(
|
||||
unwrap(env) as Record<string, unknown>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取个人信息
|
||||
*/
|
||||
@@ -36,41 +22,6 @@ export class UserApi {
|
||||
return User.fromJson(unwrap(env) as UserData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新个人资料
|
||||
*/
|
||||
async updateProfile(body: UpdateProfileRequest): Promise<User> {
|
||||
const env = await httpClient<ApiEnvelope<unknown>>(ApiPath.updateProfile, {
|
||||
method: "PUT",
|
||||
body: body.toJson(),
|
||||
});
|
||||
return User.fromJson(unwrap(env) as UserData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询积分余额
|
||||
*/
|
||||
async getCredits(): Promise<CreditsData> {
|
||||
const env = await httpClient<ApiEnvelope<unknown>>(ApiPath.userCredits);
|
||||
return CreditsData.fromJson(unwrap(env) as Record<string, unknown>);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询积分操作历史
|
||||
*/
|
||||
async getCreditsHistory(
|
||||
limit = 50,
|
||||
offset = 0
|
||||
): Promise<CreditsHistoryData> {
|
||||
const env = await httpClient<ApiEnvelope<unknown>>(
|
||||
ApiPath.userCreditsHistory,
|
||||
{ query: { limit, offset } }
|
||||
);
|
||||
return CreditsHistoryData.fromJson(
|
||||
unwrap(env) as Record<string, unknown>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户权益快照
|
||||
*/
|
||||
|
||||
@@ -16,7 +16,6 @@ export * from "../../core/net/interceptor/auth_refresh_interceptor";
|
||||
export * from "../../core/net/interceptor/logging_interceptor";
|
||||
export * from "../../core/net/interceptor/token_interceptor";
|
||||
// 注:原 ./auth/* 平台适配层已删除(社交登录改由 NextAuth 处理)
|
||||
export * from "../dto/auth/apple_login_request";
|
||||
export * from "../dto/auth/facebook_login_request";
|
||||
export * from "../dto/auth/facebook_user_data";
|
||||
export * from "../dto/auth/fb_id_login_request";
|
||||
@@ -29,27 +28,16 @@ export * from "../dto/auth/logout_response";
|
||||
export * from "../dto/auth/refresh_token_request";
|
||||
export * from "../dto/auth/refresh_token_response";
|
||||
export * from "../dto/auth/register_request";
|
||||
export * from "../dto/auth/send_code_request";
|
||||
export * from "../dto/chat/chat_history_response";
|
||||
export * from "../dto/chat/chat_message";
|
||||
export * from "../dto/chat/chat_send_response";
|
||||
export * from "../dto/chat/chat_sync_data";
|
||||
export * from "../dto/chat/chat_sync_request";
|
||||
export * from "../dto/chat/image_upload_response";
|
||||
export * from "../dto/chat/send_message_request";
|
||||
export * from "../dto/chat/stt_data";
|
||||
export * from "../dto/chat/sync_message";
|
||||
export * from "../dto/metrics/app_event";
|
||||
export * from "../dto/metrics/pwa_event";
|
||||
export * from "../dto/user/avatar_data";
|
||||
export * from "../dto/user/credits_data";
|
||||
export * from "../dto/user/credits_history_data";
|
||||
export * from "../dto/user/personality_traits";
|
||||
export * from "../dto/user/recent_memory";
|
||||
export * from "../dto/user/update_profile_request";
|
||||
export * from "../dto/user/user";
|
||||
export * from "../dto/user/user_stats_response";
|
||||
export * from "../schemas/auth/apple_login_request";
|
||||
export * from "../schemas/auth/facebook_login_request";
|
||||
export * from "../schemas/auth/facebook_user_data";
|
||||
export * from "../schemas/auth/fb_id_login_request";
|
||||
@@ -62,23 +50,13 @@ export * from "../schemas/auth/logout_response";
|
||||
export * from "../schemas/auth/refresh_token_request";
|
||||
export * from "../schemas/auth/refresh_token_response";
|
||||
export * from "../schemas/auth/register_request";
|
||||
export * from "../schemas/auth/send_code_request";
|
||||
export * from "../schemas/chat/chat_history_response";
|
||||
export * from "../schemas/chat/chat_message";
|
||||
export * from "../schemas/chat/chat_send_response";
|
||||
export * from "../schemas/chat/chat_sync_data";
|
||||
export * from "../schemas/chat/chat_sync_request";
|
||||
export * from "../schemas/chat/image_upload_response";
|
||||
export * from "../schemas/chat/send_message_request";
|
||||
export * from "../schemas/chat/stt_data";
|
||||
export * from "../schemas/chat/sync_message";
|
||||
export * from "../schemas/metrics/app_event";
|
||||
export * from "../schemas/metrics/pwa_event";
|
||||
export * from "../schemas/user/avatar_data";
|
||||
export * from "../schemas/user/credits_data";
|
||||
export * from "../schemas/user/credits_history_data";
|
||||
export * from "../schemas/user/personality_traits";
|
||||
export * from "../schemas/user/recent_memory";
|
||||
export * from "../schemas/user/update_profile_request";
|
||||
export * from "../schemas/user/user";
|
||||
export * from "../schemas/user/user_stats_response";
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import type { PaymentVipStatusResponse } from "@/data/dto/payment";
|
||||
import { getPaymentRepository } from "@/data/repositories/payment_repository";
|
||||
import type { Result } from "@/utils";
|
||||
|
||||
export function getCurrentVipPaymentStatus(): Promise<
|
||||
Result<PaymentVipStatusResponse>
|
||||
> {
|
||||
return getPaymentRepository().getVipStatus();
|
||||
}
|
||||
Reference in New Issue
Block a user