feat: 添加 ip 追踪
This commit is contained in:
@@ -4,6 +4,8 @@ import { storeFile } from '@/lib/fileStorage'
|
||||
import { push } from '@/lib/push'
|
||||
import { withCors } from '@/lib/middleware'
|
||||
import { filterIgnoredWindows } from '@/lib/windowFilters'
|
||||
import { getClientIp } from '@/lib/clientIp'
|
||||
import { getIpGeodataLabel } from '@/lib/geodata'
|
||||
import ffmpeg from 'fluent-ffmpeg'
|
||||
import { writeFileSync, unlinkSync, mkdtempSync, readFileSync, rmSync } from 'fs'
|
||||
import { tmpdir } from 'os'
|
||||
@@ -27,6 +29,8 @@ async function handleScreenshotUpload(req: NextRequest) {
|
||||
return NextResponse.json({ error: '缺少主机名' }, { status: 400 })
|
||||
}
|
||||
|
||||
const clientIp = getClientIp(req)
|
||||
|
||||
const formData = await req.formData()
|
||||
const files: File[] = []
|
||||
const rawWindowsInfo: WindowInfo[] = JSON.parse(formData.get('windows_info') as string || '[]')
|
||||
@@ -127,6 +131,7 @@ async function handleScreenshotUpload(req: NextRequest) {
|
||||
const newRecord = await prisma.record.create({
|
||||
data: {
|
||||
hostname,
|
||||
ip: clientIp,
|
||||
timestamp: new Date(),
|
||||
windows: {
|
||||
create: windowsInfo
|
||||
@@ -226,6 +231,7 @@ async function handleGetScreenshots(req: NextRequest) {
|
||||
select: {
|
||||
id: true,
|
||||
timestamp: true,
|
||||
ip: true,
|
||||
isStarred: true,
|
||||
windows: {
|
||||
select: {
|
||||
@@ -262,6 +268,7 @@ async function handleGetScreenshots(req: NextRequest) {
|
||||
// Convert BigInt to string in windows.memory field
|
||||
const serializedRecords = records.map(record => ({
|
||||
...record,
|
||||
ipLocation: getIpGeodataLabel(record.ip),
|
||||
windows: record.windows.map(window => ({
|
||||
...window,
|
||||
memory: window.memory.toString()
|
||||
|
||||
Reference in New Issue
Block a user