- 新增 /api/admin/songs/batch-reject.post 批量驳回接口(事务清排期/投票/扣接纳数/黑名单去重/异步通知) - requireSongAdmin 三角色校验 + createApiError 统一错误包装 - scheduleDaysBefore/After 四字段排期可见范围限制(开放 API 与公开排期接口三处缓存路径 + DB 条件过滤) - submissionNoteAutoModeration 基于黑名单 KEYWORD/LANGUAGE/GENRE 自动判定留言 publicStatus,命中自动关闭 submissionNotePublic - 更新 songs/request.post 与 songs/[id]/update.put 接入自动审查逻辑
72 lines
1.8 KiB
TypeScript
72 lines
1.8 KiB
TypeScript
export interface UserAgentInfo {
|
|
browser: string | null
|
|
operatingSystem: string | null
|
|
device: string | null
|
|
}
|
|
|
|
const BROWSER_PATTERNS: Array<[RegExp, string]> = [
|
|
[/Edg\//i, 'Microsoft Edge'],
|
|
[/OPR\//i, 'Opera'],
|
|
[/Chrome\//i, 'Chrome'],
|
|
[/Safari\//i, 'Safari'],
|
|
[/Firefox\//i, 'Firefox'],
|
|
[/MSIE |Trident\//i, 'Internet Explorer']
|
|
]
|
|
|
|
const OS_PATTERNS: Array<[RegExp, string]> = [
|
|
[/Windows NT 10\.0/i, 'Windows 10/11'],
|
|
[/Windows NT 6\.3/i, 'Windows 8.1'],
|
|
[/Windows NT 6\.2/i, 'Windows 8'],
|
|
[/Windows NT 6\.1/i, 'Windows 7'],
|
|
[/Windows/i, 'Windows'],
|
|
[/Mac OS X ([\d_.]+)/i, 'macOS'],
|
|
[/iPhone OS ([\d_]+)/i, 'iOS'],
|
|
[/iPad.*CPU OS ([\d_]+)/i, 'iPadOS'],
|
|
[/Android ([\d.]+)/i, 'Android'],
|
|
[/Linux/i, 'Linux']
|
|
]
|
|
|
|
const DEVICE_PATTERNS: Array<[RegExp, string]> = [
|
|
[/iPhone/i, 'iPhone'],
|
|
[/iPad/i, 'iPad'],
|
|
[/Android.*Mobile/i, 'Android Phone'],
|
|
[/Android/i, 'Android Tablet'],
|
|
[/Windows Phone/i, 'Windows Phone'],
|
|
[/Macintosh/i, 'Mac'],
|
|
[/Windows/i, 'Windows PC'],
|
|
[/Linux/i, 'Linux PC']
|
|
]
|
|
|
|
export function parseUserAgent(userAgent: string | null | undefined): UserAgentInfo {
|
|
const ua = (userAgent ?? '').trim()
|
|
if (!ua) return { browser: null, operatingSystem: null, device: null }
|
|
|
|
let browser: string | null = null
|
|
for (const [regex, name] of BROWSER_PATTERNS) {
|
|
if (regex.test(ua)) {
|
|
browser = name
|
|
break
|
|
}
|
|
}
|
|
|
|
let operatingSystem: string | null = null
|
|
for (const [regex, name] of OS_PATTERNS) {
|
|
if (regex.test(ua)) {
|
|
operatingSystem = name
|
|
break
|
|
}
|
|
}
|
|
|
|
let device: string | null = null
|
|
for (const [regex, name] of DEVICE_PATTERNS) {
|
|
if (regex.test(ua)) {
|
|
device = name
|
|
break
|
|
}
|
|
}
|
|
|
|
return { browser, operatingSystem, device }
|
|
}
|
|
|
|
export type LoginMethod = 'password' | 'oauth' | 'webauthn' | 'totp_2fa' | 'email_2fa'
|