接口调用时获取用户的x-data-ip和x-data-ua & 修改isp参数类型 & 使用教程初版 &后台用户名字段展示 &添加支付平台字段

This commit is contained in:
Eamon-meng
2025-12-01 19:11:53 +08:00
parent b91de82bc2
commit b0a0b37b19
13 changed files with 300 additions and 43 deletions

View File

@@ -3,6 +3,7 @@ import {API_BASE_URL, ApiResponse, CLIENT_ID, CLIENT_SECRET} from '@/lib/api'
import {cookies, headers} from 'next/headers'
import {cache} from 'react'
import {redirect} from 'next/navigation'
import {userAgent} from 'next/server'
// ======================
// public
@@ -113,7 +114,17 @@ const _callByUser = cache(async <R = undefined>(
async function call<R = undefined>(url: string, request: RequestInit): Promise<ApiResponse<R>> {
let response: Response
try {
response = await fetch(url, request)
const userHeaders = await headers()
// request.headers['x-data-ip'] = header.get('x-forwarded-for')
// request.headers['x-data-ua'] = header.get('user-agent')
response = await fetch(url, {
...request,
headers: {
...request.headers,
'x-data-ip': userHeaders.get('x-forwarded-for') || '',
'x-data-ua': userHeaders.get('user-agent') || '',
},
})
}
catch (e) {
console.error('后端请求失败', url, (e as Error).message)

View File

@@ -29,7 +29,7 @@ export async function createChannels(params: {
count: number
prov?: string
city?: string
isp?: string
isp?: number
}) {
return callByUser<CreateChannelsResp[]>('/api/channel/create', params)
}