优化后端鉴权与日志安全
This commit is contained in:
@@ -7,10 +7,19 @@ import { formatFenToAmount, normalizeFen } from '../../utils/money.js'
|
||||
import { parseTaskContext as parseTaskContextValue } from '../../utils/task-json.js'
|
||||
import { nowIso } from '../../utils/time.js'
|
||||
import { buildClaimUrl } from './claim-service.js'
|
||||
import type { ClaimTokenRow, OrderItemRow, OrderRow, TaskRow } from '../../types/repository-rows.js'
|
||||
|
||||
export const CLAIM_TERMINAL_STATUSES = new Set(['expired', 'closed'])
|
||||
export const KUAISHOU_CLOUD_CLAIM_GUIDE_BASE_PATH = '/kuaishou-cloud-guide'
|
||||
|
||||
type JsonObject = Record<string, any>
|
||||
type ClaimContext = {
|
||||
claimToken: ClaimTokenRow
|
||||
task: TaskRow
|
||||
order: OrderRow
|
||||
orderItem: OrderItemRow
|
||||
}
|
||||
|
||||
export async function getClaimContext(token: unknown) {
|
||||
const normalized = String(token || '').trim()
|
||||
|
||||
@@ -76,7 +85,7 @@ export async function getClaimContext(token: unknown) {
|
||||
}
|
||||
}
|
||||
|
||||
export function buildClaimDetailPayload({ claimToken, task, order, orderItem }) {
|
||||
export function buildClaimDetailPayload({ claimToken, task, order, orderItem }: ClaimContext) {
|
||||
const kuaishouCloudFulfillment = mapClaimKuaishouCloudFulfillment(task, order)
|
||||
|
||||
return {
|
||||
@@ -113,7 +122,7 @@ export function buildClaimDetailPayload({ claimToken, task, order, orderItem })
|
||||
skuName: orderItem.sku_name,
|
||||
quantity: orderItem.quantity,
|
||||
},
|
||||
session: null,
|
||||
session: null as null,
|
||||
kuaishouCloudFulfillment,
|
||||
result: task.redeemed_at
|
||||
? {
|
||||
@@ -126,7 +135,7 @@ export function buildClaimDetailPayload({ claimToken, task, order, orderItem })
|
||||
}
|
||||
}
|
||||
|
||||
export function mapClaimKuaishouCloudFulfillment(task, order) {
|
||||
export function mapClaimKuaishouCloudFulfillment(task: TaskRow, order: OrderRow) {
|
||||
if (String(task?.executor_key || '').trim() !== 'kuaishou_ct_assisted') {
|
||||
return null
|
||||
}
|
||||
@@ -213,11 +222,11 @@ export function mapClaimKuaishouCloudFulfillment(task, order) {
|
||||
}
|
||||
}
|
||||
|
||||
function parseTaskContext(task) {
|
||||
function parseTaskContext(task: TaskRow): JsonObject {
|
||||
return parseTaskContextValue(task)
|
||||
}
|
||||
|
||||
async function expireClaimContext(claimToken, task) {
|
||||
async function expireClaimContext(claimToken: ClaimTokenRow, task: TaskRow) {
|
||||
const now = nowIso()
|
||||
const nextClaimToken = await updateClaimToken(claimToken.id, {
|
||||
status: 'expired',
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
} from '../fulfillment/kuaishou-cloud-task-service.js'
|
||||
import { buildClaimDetailPayload, getClaimContext } from './kuaishou-cloud-claim-context.js'
|
||||
import { syncKuaishouCloudRoleInfo } from './kuaishou-cloud-sync-service.js'
|
||||
import type { TaskRow } from '../../types/repository-rows.js'
|
||||
|
||||
const KUAISHOU_CLOUD_GUIDE_DIR = path.resolve(PROJECT_ROOT, '../../tems/imgs')
|
||||
const ALLOWED_GUIDE_FILES = new Set(['1.png', '2.png', '3.png'])
|
||||
@@ -136,7 +137,7 @@ export async function verifyKuaishouCloudClaimTicket(token: unknown, payload: Js
|
||||
return getKuaishouCloudClaimDetail(token)
|
||||
}
|
||||
|
||||
export async function getKuaishouCloudClaimGuideAssetPath(filename) {
|
||||
export async function getKuaishouCloudClaimGuideAssetPath(filename: unknown) {
|
||||
const normalized = String(filename || '').trim()
|
||||
if (!ALLOWED_GUIDE_FILES.has(normalized)) {
|
||||
throw createHttpError('指引图片不存在', {
|
||||
@@ -172,7 +173,7 @@ export async function getKuaishouCloudClaimDetail(token: unknown) {
|
||||
})
|
||||
}
|
||||
|
||||
function parseTaskContext(task) {
|
||||
function parseTaskContext(task: Partial<TaskRow> | null | undefined): JsonObject {
|
||||
const rawValue = task?.context_json
|
||||
if (!rawValue) {
|
||||
return {}
|
||||
@@ -189,7 +190,7 @@ function parseTaskContext(task) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function confirmKuaishouCloudClaimRole(token) {
|
||||
export async function confirmKuaishouCloudClaimRole(token: unknown) {
|
||||
const context = await getClaimContext(token)
|
||||
const now = nowIso()
|
||||
|
||||
@@ -245,7 +246,7 @@ export async function confirmKuaishouCloudClaimRole(token) {
|
||||
return getKuaishouCloudClaimDetail(token)
|
||||
}
|
||||
|
||||
export async function redeemKuaishouCloudClaim(token) {
|
||||
export async function redeemKuaishouCloudClaim(token: unknown) {
|
||||
const context = await getClaimContext(token)
|
||||
const now = nowIso()
|
||||
|
||||
|
||||
@@ -4,8 +4,9 @@ import {
|
||||
probeKuaishouCloudTaskBindUrl,
|
||||
refreshKuaishouCloudTaskRoleInfo,
|
||||
} from '../fulfillment/kuaishou-cloud-task-service.js'
|
||||
import type { TaskRow } from '../../types/repository-rows.js'
|
||||
|
||||
export async function syncKuaishouCloudRoleInfo(task) {
|
||||
export async function syncKuaishouCloudRoleInfo(task: TaskRow) {
|
||||
const flow = normalizeKuaishouCloudFlow(parseTaskContext(task).kuaishouCloudFulfillment)
|
||||
|
||||
if (!flow.binding.vnId || !flow.binding.vnKey || !flow.binding.vnPhone) {
|
||||
@@ -42,7 +43,7 @@ export async function syncKuaishouCloudRoleInfo(task) {
|
||||
}
|
||||
}
|
||||
|
||||
function parseTaskContext(task) {
|
||||
function parseTaskContext(task: Partial<TaskRow> | null | undefined): Record<string, any> {
|
||||
const rawValue = task?.context_json
|
||||
|
||||
if (!rawValue) {
|
||||
|
||||
Reference in New Issue
Block a user