优化后端代码质量基础

This commit is contained in:
yml2213
2026-05-26 10:48:30 +08:00
parent a2bce8b272
commit d126b35579
13 changed files with 142 additions and 25 deletions
@@ -2,7 +2,7 @@ import { createHttpError } from '../../utils/http.js'
const DEFAULT_TIMEOUT_MS = 10000
type JsonObject = Record<string, any>
type JsonObject = Record<string, unknown>
type BarkSendInput = {
serverUrl?: string
recipient?: {
@@ -4,7 +4,7 @@ import { sendInternalNotification } from './notification-service.js'
const DEFAULT_COOLDOWN_MS = 10 * 60 * 1000
const notificationCooldownMap = new Map<string, number>()
type JsonObject = Record<string, any>
type JsonObject = Record<string, unknown>
type InternalNotificationPayload = {
title: string
body?: string
@@ -13,6 +13,55 @@ type InternalNotificationPayload = {
cooldownKey?: string
cooldownMs?: number
}
type KuaishouCloudAssetNotEnoughPayload = {
task?: unknown
flow?: unknown
assetBefore?: unknown
requiredAsset?: unknown
skuName?: unknown
}
type CloudtentaclesAuthExpiredPayload = {
pathname?: unknown
errorCode?: unknown
message?: unknown
cooldownSeconds?: unknown
sourceKey?: unknown
accountLabel?: unknown
}
type CloudtentaclesAssetLowPayload = {
asset?: unknown
threshold?: unknown
cooldownSeconds?: unknown
sourceKey?: unknown
accountLabel?: unknown
}
type Open91PendingConfigPayload = {
order?: unknown
orderNo?: unknown
productNo?: unknown
buyNum?: unknown
reason?: unknown
}
type TaskNotificationPayload = {
task?: unknown
reason?: unknown
source?: unknown
errorMessage?: unknown
}
type KuaishouCloudConsumeFailedPayload = {
task?: unknown
order?: unknown
ticketCodeMasked?: unknown
shopId?: unknown
shopName?: unknown
errorMessage?: unknown
}
type ClaimRedeemNeedsAttentionPayload = {
task?: unknown
order?: unknown
status?: unknown
errorMessage?: unknown
}
export async function notifyInternalSafely(payload: InternalNotificationPayload) {
const cooldownKey = String(payload.cooldownKey || '').trim()
@@ -52,7 +101,7 @@ export function notifyKuaishouCloudAssetNotEnough({
assetBefore = 0,
requiredAsset = 0,
skuName = '',
}: JsonObject = {}) {
}: KuaishouCloudAssetNotEnoughPayload = {}) {
const taskRecord = toRecord(task)
const flowRecord = toRecord(flow)
const binding = toRecord(flowRecord.binding)
@@ -81,7 +130,7 @@ export function notifyCloudtentaclesAuthExpired({
cooldownSeconds = 600,
sourceKey = '',
accountLabel = '',
}: JsonObject = {}) {
}: CloudtentaclesAuthExpiredPayload = {}) {
const normalizedSourceKey = String(sourceKey || '').trim()
const normalizedAccountLabel = String(accountLabel || '').trim()
@@ -107,7 +156,7 @@ export function notifyCloudtentaclesAssetLow({
cooldownSeconds = 1800,
sourceKey = '',
accountLabel = '',
}: JsonObject = {}) {
}: CloudtentaclesAssetLowPayload = {}) {
const normalizedSourceKey = String(sourceKey || '').trim()
const normalizedAccountLabel = String(accountLabel || '').trim()
@@ -133,7 +182,7 @@ export function notifyOpen91PendingConfig({
productNo = '',
buyNum = 0,
reason = '未命中履约配置',
}: JsonObject = {}) {
}: Open91PendingConfigPayload = {}) {
const orderRecord = toRecord(order)
return notifyInternalSafely({
@@ -152,7 +201,7 @@ export function notifyOpen91PendingConfig({
export function notifyKuaishouCloudBindUrlRefreshFailed({
task = {},
errorMessage = '',
}: JsonObject = {}) {
}: TaskNotificationPayload = {}) {
const taskRecord = toRecord(task)
return notifyInternalSafely({
@@ -174,7 +223,7 @@ export function notifyKuaishouCloudConsumeFailed({
shopId = '',
shopName = '',
errorMessage = '',
}: JsonObject = {}) {
}: KuaishouCloudConsumeFailedPayload = {}) {
const taskRecord = toRecord(task)
const orderRecord = toRecord(order)
@@ -196,7 +245,7 @@ export function notifyTaskAutoManualReview({
task = {},
reason = '',
source = '',
}: JsonObject = {}) {
}: TaskNotificationPayload = {}) {
const taskRecord = toRecord(task)
return notifyInternalSafely({
@@ -216,7 +265,7 @@ export function notifyClaimRedeemNeedsAttention({
order = {},
status = '',
errorMessage = '',
}: JsonObject = {}) {
}: ClaimRedeemNeedsAttentionPayload = {}) {
const taskRecord = toRecord(task)
const orderRecord = toRecord(order)
@@ -6,7 +6,7 @@ import { createHttpError } from '../../utils/http.js'
const DEFAULT_WPUSH_ENDPOINT = 'https://api.wpush.cn/api/v1/send'
const DEFAULT_TIMEOUT_MS = 10000
type JsonObject = Record<string, any>
type JsonObject = Record<string, unknown>
type NodeHttpResponse = {
ok: boolean
status: number