# All files / types index.ts

0% Statements 0/8
100% Branches 1/1
100% Functions 1/1
0% Lines 0/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128

     import { DefaultContext, DefaultState } from 'koa';

    // 用户相关类型
    export interface IUser {
      id: number;
      phone?: string;
      openid?: string;
      nickname: string;
      avatar: string;
      memberLevel: MemberLevel;
      memberExpireAt?: Date;
      dailyUsage: number;
      lastUsageDate: string;
      createdAt: Date;
      updatedAt: Date;
    }

    export type MemberLevel = -1 | 0 | 1 | 2 | 3 | 4; // -1无限额度(测试) 0免费 1入门 2专业 3旗舰 4企业

    // 音频相关类型
    export interface IAudio {
      id: number;
      userId: number;
      title: string;
      text: string;
      summary?: string;
      tags: string[];
      audioUrl: string;
      audioDuration: number;
      audioSize: number;
      wordCount: number;
      voiceId: string;
      voiceParams: VoiceParams;
      status: AudioStatus;
      isFavorite: boolean;
      createdAt: Date;
      updatedAt: Date;
    }

    export interface VoiceParams {
      speed: number; // 0.5 - 2.0
      pitch: number; // -500 - 500
      volume: number; // 0 - 100
      instructText?: string; // Aliyun Instruct 情感/场景控制文本
    }

    export type AudioStatus = 'processing' | 'completed' | 'failed';

    // 订单相关类型
    export interface IOrder {
      id: number;
      userId: number;
      orderNo: string;
      productType: ProductType;
      amount: number;
      status: OrderStatus;
      paymentMethod?: string;
      paidAt?: Date;
      createdAt: Date;
      updatedAt: Date;
    }

    export type ProductType = 'monthly' | 'yearly';
    export type OrderStatus = 'pending' | 'paid' | 'failed' | 'refunded';

    // 请求相关类型
    export interface JwtPayload {
      userId: string;
      phone?: string;
      iat?: number;
      exp?: number;
    }

    // 扩展 Koa Context
    declare module 'koa' {
      interface Context extends DefaultContext {
        state: DefaultState & {
          user?: JwtPayload & {
            memberLevel?: number;
          };
        };
      }
    }

    // API 响应类型
    export interface ApiResponse<T = unknown> {
      code: number;
      message: string;
      data?: T;
    }

    // 分页类型
    export interface PaginationQuery {
      page?: number;
      pageSize?: number;
    }

    export interface PaginationResult<T> {
      list: T[];
      total: number;
      page: number;
      pageSize: number;
      totalPages: number;
    }

    // 音色类型
    export interface Voice {
      id: string;
      name: string;
      gender: 'male' | 'female';
      description: string;
      preview?: string;
    }

    // 会员权益
    export interface MemberQuota {
      dailyLimit: number; // -1 表示无限制
      wordLimit: number;  // -1 表示无限制
    }

    export const MEMBER_QUOTA: Record<MemberLevel, MemberQuota> = {
      '-1': { dailyLimit: -1, wordLimit: -1 },
      0: { dailyLimit: 3, wordLimit: 5000 },
      1: { dailyLimit: 10, wordLimit: 10000 },
      2: { dailyLimit: -1, wordLimit: 10000 },
      3: { dailyLimit: -1, wordLimit: -1 },
      4: { dailyLimit: -1, wordLimit: -1 },
    };