refactor(utils): add barrel exports

This commit is contained in:
2026-06-18 11:58:50 +08:00
parent 428402d4b1
commit 0d0dabaace
34 changed files with 48 additions and 51 deletions
+1 -3
View File
@@ -26,9 +26,7 @@ import type { LoginStatus } from "@/data/dto/auth";
import { AuthStorage } from "@/data/storage/auth/auth_storage";
import { UserStorage } from "@/data/storage/user/user_storage";
import { useChatDispatch, useChatState } from "@/stores/chat/chat-context";
import { AppEnvUtil } from "@/utils/app-env";
import { BrowserDetector } from "@/utils/browser-detect";
import { UrlLauncherUtil } from "@/utils/url-launcher-util";
import { AppEnvUtil, BrowserDetector, UrlLauncherUtil } from "@/utils";
import { ROUTE_BUILDERS, ROUTES } from "@/router/routes";
import { MobileShell } from "@/app/_components/core";
@@ -14,7 +14,7 @@
*/
import { useState } from "react";
import { BrowserDetector } from "@/utils/browser-detect";
import { BrowserDetector } from "@/utils";
import styles from "./browser-hint-overlay.module.css";
@@ -14,10 +14,7 @@
*/
import { useEffect } from "react";
import { BrowserDetector } from "@/utils/browser-detect";
import { AppEnvUtil } from "@/utils/app-env";
import { SpAsyncUtil } from "@/utils/storage";
import { pwaUtil } from "@/utils/pwa";
import { BrowserDetector, AppEnvUtil, SpAsyncUtil, pwaUtil } from "@/utils";
import { PwaInstallDialog } from "./pwa-install-dialog";
import styles from "./pwa-install-overlay.module.css";
+1 -1
View File
@@ -8,7 +8,7 @@ import { useAuthDispatch, useAuthState } from "@/stores/auth/auth-context";
import { useUserDispatch } from "@/stores/user/user-context";
import { AuthStorage } from "@/data/storage/auth/auth_storage";
import { ROUTES } from "@/router/routes";
import { pwaUtil } from "@/utils/pwa";
import { pwaUtil } from "@/utils";
import {
SplashBackground,
+1 -1
View File
@@ -4,7 +4,7 @@
* 通过环境变量配置后端服务地址与超时时间。
* 原始 Dart: lib/core/net/service_manager.dart
*/
import { AppEnvUtil, type AppEnv } from "@/utils/app-env";
import { AppEnvUtil, type AppEnv } from "@/utils";
export type { AppEnv };
@@ -8,8 +8,7 @@ import type { FetchHook } from "ofetch";
import { ApiPath } from "../../../data/services/api/api_path";
import { ApiError, ErrorCode } from "../../../data/services/api/api_result";
import { AuthStorage } from "@/data/storage/auth/auth_storage";
import { deviceIdentifier } from "@/utils/device_identifier";
import { Result } from "@/utils/result";
import { deviceIdentifier, Result } from "@/utils";
/**
* 不需要 auth token 刷新的路径
+1 -1
View File
@@ -11,9 +11,9 @@ export * from "./fb_id_login_request";
export * from "./google_login_request";
export * from "./guest_login_request";
export * from "./guest_login_response";
export * from "./login_status";
export * from "./login_request";
export * from "./login_response";
export * from "./login_status";
export * from "./logout_response";
export * from "./refresh_token_request";
export * from "./refresh_token_response";
+1 -1
View File
@@ -6,7 +6,7 @@ import {
type GuestChatQuotaInput,
type GuestChatQuotaData,
} from "@/data/schemas/chat/guest_chat_quota";
import { AppEnvUtil } from "@/utils/app-env";
import { AppEnvUtil } from "@/utils";
export class GuestChatQuota {
// 静态常量
+1 -1
View File
@@ -28,7 +28,7 @@ import {
SendCodeRequest,
} from "@/data/dto/auth";
import { User } from "@/data/dto/user";
import { Result } from "@/utils/result";
import { Result } from "@/utils";
import type { IAuthRepository } from "@/data/repositories/interfaces";
import { AuthStorage, type IAuthStorage } from "@/data/storage/auth";
import { UserStorage, type IUserStorage } from "@/data/storage/user";
+1 -1
View File
@@ -22,7 +22,7 @@ import {
ChatSendResponse,
SendMessageRequest,
} from "@/data/dto/chat";
import { Result } from "@/utils/result";
import { Result } from "@/utils";
import type { IChatRepository } from "@/data/repositories/interfaces";
import { LocalChatStorage, LocalMessage } from "@/data/storage/chat";
@@ -13,7 +13,7 @@
* 原始 Dart: lib/data/repositories/auth_repository_impl.dart
*/
import type { Result } from "@/utils/result";
import type { Result } from "@/utils";
import type {
GuestLoginResponse,
LoginResponse,
@@ -11,7 +11,7 @@
* 原始 Dart: lib/data/repositories/chat_repository_impl.dart
*/
import type { Result } from "@/utils/result";
import type { Result } from "@/utils";
import type {
ChatHistoryResponse,
ChatMessage,
@@ -9,7 +9,7 @@
* 原始 Dart: lib/data/repositories/metrics_repository_impl.dart
*/
import type { Result } from "@/utils/result";
import type { Result } from "@/utils";
export interface IMetricsRepository {
/** 上报 PWA 事件。自动注入当前秒级时间戳。 */
@@ -9,7 +9,7 @@
* 原始 Dart: lib/data/repositories/user_repository_impl.dart
*/
import type { Result } from "@/utils/result";
import type { Result } from "@/utils";
import type {
CreditsData,
CreditsHistoryData,
+1 -1
View File
@@ -9,7 +9,7 @@
*/
import { MetricsApi, metricsApi } from "@/data/services/api";
import { AppEvent, PwaEvent } from "@/data/dto/metrics";
import { Result } from "@/utils/result";
import { Result } from "@/utils";
import type { IMetricsRepository } from "@/data/repositories/interfaces";
export class MetricsRepository implements IMetricsRepository {
+1 -1
View File
@@ -16,7 +16,7 @@ import {
User,
UserStatsResponse,
} from "@/data/dto/user";
import { Result } from "@/utils/result";
import { Result } from "@/utils";
import type { IUserRepository } from "@/data/repositories/interfaces";
export class UserRepository implements IUserRepository {
+1 -2
View File
@@ -16,8 +16,7 @@
* - `recordXxx(today)` 写入 todayString,后续 `canXxx` 在同一天返回 `false`。
*/
import { Result, type Result as ResultT } from "@/utils/result";
import { SpAsyncUtil } from "@/utils/storage";
import { Result, type Result as ResultT, SpAsyncUtil } from "@/utils";
import { StorageKeys } from "../storage_keys";
export class AppStorage {
+1 -2
View File
@@ -14,8 +14,7 @@
* - `clearAuthData` 顺序清理:loginToken → guestToken → refreshToken,任一失败立即返回
*/
import { Result, type Result as ResultT } from "@/utils/result";
import { SpAsyncUtil } from "@/utils/storage";
import { Result, type Result as ResultT, SpAsyncUtil } from "@/utils";
import { StorageKeys } from "../storage_keys";
import type { IAuthStorage } from "./iauth_storage";
+1 -1
View File
@@ -9,7 +9,7 @@
* - 所有方法返回 `Promise<Result<T>>`,与 Dart `Future<Result<T>>` 对齐
*/
import type { Result } from "@/utils/result";
import type { Result } from "@/utils";
export interface IAuthStorage {
getLoginToken(): Promise<Result<string | null>>;
@@ -4,8 +4,7 @@ import memoryDriver from "unstorage/drivers/memory";
import { GuestChatQuota } from "@/data/dto/chat/guest_chat_quota";
import { StorageKeys } from "@/data/storage/storage_keys";
import { todayString } from "@/utils/date";
import { SpAsyncUtil } from "@/utils/storage";
import { todayString, SpAsyncUtil } from "@/utils";
import { ChatStorage } from "../chat_storage";
+1 -3
View File
@@ -7,9 +7,7 @@ import {
import { GuestChatQuota as GuestChatQuotaDto } from "@/data/dto/chat/guest_chat_quota";
import { z } from "zod";
import { type Result as ResultT, Result } from "@/utils/result";
import { todayString } from "@/utils/date";
import { SpAsyncUtil } from "@/utils/storage";
import { type Result as ResultT, Result, todayString, SpAsyncUtil } from "@/utils";
import { StorageKeys } from "../storage_keys";
import type { IChatStorage } from "./ichat_storage";
+1 -1
View File
@@ -11,7 +11,7 @@
* 跨天判断逻辑(`needsReset`)保留在 `GuestChatQuota` 类上。
*/
import type { Result } from "@/utils/result";
import type { Result } from "@/utils";
import type { GuestChatQuotaData } from "@/data/schemas/chat/guest_chat_quota";
export interface IChatStorage {
+1 -1
View File
@@ -15,7 +15,7 @@
* 数据量大时考虑升级 schema 加索引。
*/
import { Result, type Result as ResultT } from "@/utils/result";
import { Result, type Result as ResultT } from "@/utils";
import { LocalChatDB } from "./local_chat_db";
import { LocalMessage } from "./local_message";
+1 -1
View File
@@ -11,7 +11,7 @@
* 具体序列化由实现层通过 Zod schema 校验后转换为 `User` 类实例。
*/
import type { Result } from "@/utils/result";
import type { Result } from "@/utils";
import type { UserData } from "@/data/schemas/user/user";
export interface IUserStorage {
+1 -2
View File
@@ -16,8 +16,7 @@
*/
import { UserSchema, type UserData } from "@/data/schemas/user/user";
import { type Result as ResultT } from "@/utils/result";
import { SpAsyncUtil } from "@/utils/storage";
import { type Result as ResultT, SpAsyncUtil } from "@/utils";
import { StorageKeys } from "../storage_keys";
import type { IUserStorage } from "./iuser_storage";
+1 -1
View File
@@ -9,7 +9,7 @@
*
* 注:Web Speech API 在 Chrome / Edge 完整支持;Safari / Firefox 仅录音。
*/
import { Result } from "@/utils/result";
import { Result } from "@/utils";
export interface SpeechRecognitionResultEvent {
transcript: string;
+1 -4
View File
@@ -9,10 +9,7 @@ import { authRepository } from "@/data/repositories/auth_repository";
import type { IAuthRepository } from "@/data/repositories/interfaces";
import { AuthStorage } from "@/data/storage/auth/auth_storage";
import { UserStorage } from "@/data/storage/user/user_storage";
import { deviceIdentifier } from "@/utils/device_identifier";
import { fetchFacebookUserData } from "@/utils/facebook-graph";
import { Logger } from "@/utils/logger";
import { Result } from "@/utils/result";
import { deviceIdentifier, fetchFacebookUserData, Logger, Result } from "@/utils";
import { readGuestId } from "./auth-helpers";
+1 -1
View File
@@ -5,7 +5,7 @@
import { fromPromise, fromCallback } from "xstate";
import { createChatWebSocket, ChatWebSocket } from "@/core/net/chat-websocket";
import { Result } from "@/utils/result";
import { Result } from "@/utils";
import {
PAGE_SIZE,
+1 -2
View File
@@ -25,8 +25,7 @@ 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 { formatDate } from "@/utils/date";
import { Result } from "@/utils/result";
import { formatDate, Result } from "@/utils";
// ============================================================
// Constants
+1 -1
View File
@@ -33,7 +33,7 @@
import { setup, assign } from "xstate";
import { ChatStorage } from "@/data/storage/chat/chat_storage";
import { formatDate, todayString } from "@/utils/date";
import { formatDate, todayString } from "@/utils";
import { ChatState, initialState } from "./chat-state";
+1 -1
View File
@@ -21,7 +21,7 @@ import type {
IAuthRepository,
IUserRepository,
} from "@/data/repositories/interfaces";
import { Result } from "@/utils/result";
import { Result } from "@/utils";
import { type InitData, readInitData, toView, userStorage } from "./user-machine.helpers";
+1 -1
View File
@@ -15,7 +15,7 @@
import type { UserView } from "@/data/dto/user";
import { UserStorage } from "@/data/storage/user/user_storage";
import { Result } from "@/utils/result";
import { Result } from "@/utils";
// ============================================================
// Storage singleton
+15
View File
@@ -0,0 +1,15 @@
/**
* @file Automatically generated by barrelsby.
*/
export * from "./app-env";
export * from "./browser-detect";
export * from "./date";
export * from "./device_identifier";
export * from "./facebook-graph";
export * from "./logger";
export * from "./platform-detect";
export * from "./pwa";
export * from "./result";
export * from "./storage";
export * from "./url-launcher-util";