fix: 修复 getClientIP 导入导致的树摇问题
- scan-emails/route.ts: 直接定义 getClientIP 函数,避免从 @/lib/audit 导入 - scan-status/route.ts: 同上 - 原因: Next.js tree-shaking 在打包时未将 getClientIP 包含在模块导出中 - scan-history API: 新增扫描历史查询接口 - db-schema: 新增 scan_history 表
This commit is contained in:
parent
b6f0393450
commit
73b442717e
|
|
@ -8,9 +8,16 @@ import { getMonitorConfig } from '@/lib/monitor/settings-manager'
|
|||
import { ImapFlow } from 'imapflow'
|
||||
import { simpleParser } from 'mailparser'
|
||||
import { formatBeijingTime } from '@/lib/monitor/types'
|
||||
import { writeAuditLog, getClientIP } from '@/lib/audit'
|
||||
import { writeAuditLog } from '@/lib/audit'
|
||||
import { getScanState, setScanState, isCancelRequested, resetCancelFlag } from '@/lib/monitor/scan-state'
|
||||
|
||||
// 直接定义,避免 Next.js tree-shaking 导致模块导出缺失
|
||||
function getClientIP(request: NextRequest): string | null {
|
||||
const forwarded = request.headers.get('x-forwarded-for')
|
||||
if (forwarded) return forwarded.split(',')[0].trim()
|
||||
return request.headers.get('x-real-ip') ?? null
|
||||
}
|
||||
|
||||
interface ScanResult {
|
||||
status: 'running' | 'completed' | 'error' | 'cancelling'
|
||||
startedAt: string
|
||||
|
|
|
|||
|
|
@ -3,9 +3,16 @@ import { NextRequest, NextResponse } from 'next/server'
|
|||
import { initDatabase } from '@/lib/db-schema'
|
||||
import { getCurrentUser } from '@/lib/auth'
|
||||
import { hasPermission } from '@/lib/permissions'
|
||||
import { getClientIP, writeAuditLog } from '@/lib/audit'
|
||||
import { writeAuditLog } from '@/lib/audit'
|
||||
import { getScanState, requestCancel } from '@/lib/monitor/scan-state'
|
||||
|
||||
// 直接定义,避免 Next.js tree-shaking 导致模块导出缺失
|
||||
function getClientIP(request: NextRequest): string | null {
|
||||
const forwarded = request.headers.get('x-forwarded-for')
|
||||
if (forwarded) return forwarded.split(',')[0].trim()
|
||||
return request.headers.get('x-real-ip') ?? null
|
||||
}
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
initDatabase()
|
||||
const user = await getCurrentUser()
|
||||
|
|
|
|||
Loading…
Reference in New Issue