// Prisma Schema for HYW & Koneko 音源管理后台 // // 合作开发: MistAperio Studio × Macrohard Studio // 编写人: 雾启工作室@云汀 (Cloudwhisper/Miao-moe), Macrohard Studio@Ryn磷熠 (Macrohard0001) // // 旧版后台由 Macrohard Studio 开发,编写人 @Macrohard0001 generator client { provider = "prisma-client-js" } datasource db { provider = "sqlite" url = "file:./data.db" } // ============================================ // 用户与认证相关 // ============================================ /// 用户表 - 用于自建登录系统或对接 auth.shiqianjiang.cn model User { id String @id @default(uuid()) email String @unique username String? passwordHash String? // 仅自建登录时使用 displayName String? avatar String? role String @default("user") // user, vip, admin status String @default("active") // active, banned, inactive // 第三方认证信息 authProvider String? // local, auth.shiqianjiang.cn authId String? // 第三方平台的用户ID // 权限配置 permissions String? // JSON: 允许的音质、平台等 // 时间戳 lastLoginAt DateTime? createdAt DateTime @default(now()) updatedAt DateTime @updatedAt // 关联 apiKeys ApiKey[] sessions Session[] logs RequestLog[] @@index([email]) @@index([authProvider, authId]) } /// API 密钥表 model ApiKey { id String @id @default(uuid()) userId String key String @unique name String? permissions String? // JSON: 允许的权限 rateLimit Int @default(100) // 每分钟限制 dailyLimit Int @default(10000) // 每日限制 // 统计 usedCount Int @default(0) lastUsedAt DateTime? // 状态 expiresAt DateTime? status String @default("active") // active, revoked, expired createdAt DateTime @default(now()) user User @relation(fields: [userId], references: [id], onDelete: Cascade) @@index([key]) @@index([userId]) } /// 会话表 model Session { id String @id @default(uuid()) userId String token String @unique userAgent String? ipAddress String? expiresAt DateTime createdAt DateTime @default(now()) user User @relation(fields: [userId], references: [id], onDelete: Cascade) @@index([token]) @@index([userId]) } // ============================================ // 音源管理相关 // ============================================ /// 音源脚本表 - 支持 LX Music、澜音、QZ Music 格式 model SourceScript { id String @id @default(uuid()) name String description String? version String @default("1.0.0") author String? // 脚本类型 format String @default("lx") // lx, lanyin, qzmusic // 脚本内容 scriptContent String // 完整脚本代码 scriptHash String // 内容哈希,用于检测变更 // 平台与音质 platforms String // JSON: ["kw", "kg", "tx", "wy", "mg"] qualities String // JSON: ["128k", "320k", "flac", ...] // 状态 enabled Boolean @default(true) status String @default("active") // active, error, deprecated // 优先级与权重 priority Int @default(0) weight Int @default(100) // 统计 successCount Int @default(0) failCount Int @default(0) avgResponseTime Int @default(0) lastError String? lastUsedAt DateTime? // 元数据 homepage String? license String? tags String? // JSON: ["独家", "高音质", ...] // 时间戳 createdAt DateTime @default(now()) updatedAt DateTime @updatedAt @@index([format]) @@index([enabled]) @@index([scriptHash]) } /// 音源文件表 - 存储大型脚本文件 model SourceFile { id String @id @default(uuid()) sourceId String @unique filePath String fileSize Int fileHash String createdAt DateTime @default(now()) } // ============================================ // 卡密系统 // ============================================ /// 卡密表 model CardKey { id String @id @default(uuid()) key String @unique type String @default("normal") // normal, vip, admin // 状态 status String @default("active") // active, used, expired, disabled // 使用限制 maxUses Int @default(-1) // -1 表示无限制 usedCount Int @default(0) dailyLimit Int @default(100) rateLimit Int @default(10) // 每分钟 // 权限配置 allowedQualities String? // JSON: 允许的音质列表 allowedPlatforms String? // JSON: 允许的平台列表 // 有效期 expireAt DateTime? // 绑定信息 bindIP String? bindDevice String? // 备注 remark String? // 关联脚本 scriptId String? scriptName String? // 时间戳 lastUsedAt DateTime? createdAt DateTime @default(now()) // 关联 logs CardKeyLog[] @@index([key]) @@index([type]) @@index([status]) } /// 卡密使用日志 model CardKeyLog { id String @id @default(uuid()) cardKeyId String key String ip String? action String // verify, use success Boolean error String? userAgent String? createdAt DateTime @default(now()) cardKey CardKey @relation(fields: [cardKeyId], references: [id], onDelete: Cascade) @@index([cardKeyId]) @@index([key]) } // ============================================ // 系统配置与日志 // ============================================ /// 系统配置表 model SystemConfig { id String @id @default("system") // 服务状态 serviceStatus String @default("running") // running, stopped, maintenance maintenanceMessage String? // 频率限制配置 globalQPS Int @default(100) singleIPQPS Int @default(10) singleIPPerMinute Int @default(60) banThreshold Int @default(100) banDuration Int @default(3600) // 秒 // 执行模式 executionMode String @default("hybrid") // simplified, full, hybrid // 主题配置 defaultTheme String @default("default") // 其他配置 extraConfig String? // JSON: 其他扩展配置 updatedAt DateTime @updatedAt } /// IP 规则表 model IPRule { id String @id @default(uuid()) ip String // IP 或 CIDR type String // whitelist, blacklist reason String? expiresAt DateTime? createdAt DateTime @default(now()) @@index([ip]) @@index([type]) } /// 请求日志表 model RequestLog { id String @id @default(uuid()) userId String? // 请求信息 platform String? songId String? quality String? source String? // 使用的音源 // 响应信息 success Boolean responseTime Int // 毫秒 errorMessage String? // 客户端信息 ip String? userAgent String? cardKey String? // 时间戳 createdAt DateTime @default(now()) user User? @relation(fields: [userId], references: [id]) @@index([createdAt]) @@index([platform]) @@index([success]) } /// 主题配置表 model Theme { id String @id @default(uuid()) name String @unique displayName String description String? // 主题类型 type String @default("custom") // preset, custom // 主题配置 config String // JSON: 完整主题配置 // 元数据 author String? preview String? // 预览图URL tags String? // JSON // 状态 isDefault Boolean @default(false) enabled Boolean @default(true) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt @@index([type]) @@index([enabled]) }