优化兑换成功后截图逻辑
This commit is contained in:
@@ -3,10 +3,10 @@
|
||||
"provider": "agiso",
|
||||
"platform": "xianyu",
|
||||
"shopId": "2209880145223",
|
||||
"skuCode": "三角洲海底捞动作",
|
||||
"skuCode": "海底捞第五人格皮肤",
|
||||
"skuName": "海底捞第五人格皮肤",
|
||||
"profileKey": "tencent_claim_redeem",
|
||||
"enabled": true,
|
||||
"enabled": false,
|
||||
"priority": 100,
|
||||
"config": {},
|
||||
"match": {
|
||||
@@ -36,24 +36,5 @@
|
||||
"resolvedSkuName": "海底捞干员庆生动作1个"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"provider": "agiso",
|
||||
"platform": "xianyu",
|
||||
"shopId": "693760716",
|
||||
"skuCode": "三角洲海底捞动作",
|
||||
"skuName": "三角洲行动-自动领取",
|
||||
"profileKey": "tencent_claim_assisted",
|
||||
"enabled": true,
|
||||
"priority": 100,
|
||||
"config": {},
|
||||
"match": {
|
||||
"externalSkuCode": "6228372634012",
|
||||
"externalItemId": "1040695550204",
|
||||
"externalSkuName": "周边",
|
||||
"config": {
|
||||
"resolvedSkuName": "三角洲行动-自动领取"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@@ -3,7 +3,7 @@ import path from 'node:path'
|
||||
|
||||
import { runtimeConfig } from '../../config/runtime.js'
|
||||
|
||||
const BAIDU_BEIJING_TIME_URL = 'https://www.baidu.com/s?wd=%E5%8C%97%E4%BA%AC%E6%97%B6%E9%97%B4'
|
||||
const BAIDU_BEIJING_TIME_URL = 'https://www.baidu.com/s?ie=utf-8&f=3&rsv_bp=1&rsv_idx=1&tn=baidu&wd=%E5%8C%97%E4%BA%AC%E6%97%B6%E9%97%B4&fenlei=256&rsv_pq=0xa7d529b30000a6eb&rsv_t=2d404COdLspTa8jnKQl%2FyCU%2BSCmRyb%2BvSqxxjk%2B7E1scokLYTuDbehaQ0Dvq&rqlang=en&rsv_enter=1&rsv_dl=ih_0&rsv_sug3=1&rsv_sug1=1&rsv_sug7=001&rsv_sug2=1&rsv_btype=i&rsp=0&rsv_sug9=es_2_1&rsv_sug=1'
|
||||
const BEIJING_TIME_PROOF_VIEWPORT = { width: 1440, height: 860 }
|
||||
const BEIJING_TIME_PROOF_CLIP = {
|
||||
x: 0,
|
||||
@@ -95,23 +95,27 @@ export async function writeRedeemArtifactFiles({
|
||||
error: '',
|
||||
}
|
||||
|
||||
try {
|
||||
beijingTimeProof = await captureBeijingTimeProof(browserContext, {
|
||||
screenshotPath: beijingTimeScreenshotPath,
|
||||
})
|
||||
await composeProofScreenshot(browserContext, {
|
||||
outputPath: screenshotPath,
|
||||
redeemImagePath: redeemPageScreenshotPath,
|
||||
timeImagePath: beijingTimeProof.screenshotPath,
|
||||
redeemMessage: String(finalResult.redeem?.sMsg || '兑换完成'),
|
||||
timePageUrl: beijingTimeProof.pageUrl,
|
||||
})
|
||||
} catch (error) {
|
||||
beijingTimeProof = {
|
||||
screenshotPath: '',
|
||||
pageUrl: BAIDU_BEIJING_TIME_URL,
|
||||
error: error instanceof Error ? error.message : '北京时间截图生成失败',
|
||||
if (shouldCaptureBeijingTimeProof(finalResult)) {
|
||||
try {
|
||||
beijingTimeProof = await captureBeijingTimeProof(browserContext, {
|
||||
screenshotPath: beijingTimeScreenshotPath,
|
||||
})
|
||||
await composeProofScreenshot(browserContext, {
|
||||
outputPath: screenshotPath,
|
||||
redeemImagePath: redeemPageScreenshotPath,
|
||||
timeImagePath: beijingTimeProof.screenshotPath,
|
||||
redeemMessage: String(finalResult.redeem?.sMsg || '兑换完成'),
|
||||
timePageUrl: beijingTimeProof.pageUrl,
|
||||
})
|
||||
} catch (error) {
|
||||
beijingTimeProof = {
|
||||
screenshotPath: '',
|
||||
pageUrl: BAIDU_BEIJING_TIME_URL,
|
||||
error: error instanceof Error ? error.message : '北京时间截图生成失败',
|
||||
}
|
||||
await fs.copyFile(redeemPageScreenshotPath, screenshotPath)
|
||||
}
|
||||
} else {
|
||||
await fs.copyFile(redeemPageScreenshotPath, screenshotPath)
|
||||
}
|
||||
|
||||
@@ -151,6 +155,19 @@ export function resolveRedeemProofMode(rawMode = runtimeConfig.redeem.proofMode)
|
||||
return DEFAULT_REDEEM_PROOF_MODE
|
||||
}
|
||||
|
||||
export function shouldCaptureBeijingTimeProof(finalResult) {
|
||||
if (finalResult?.classification?.success === true) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (finalResult?.classification?.success === false) {
|
||||
return false
|
||||
}
|
||||
|
||||
const retCode = Number(finalResult?.redeem?.iRet ?? finalResult?.redeem?.ret)
|
||||
return Number.isFinite(retCode) && retCode === 0
|
||||
}
|
||||
|
||||
function buildArtifactPaths(outputDir) {
|
||||
return {
|
||||
redeemPageScreenshotPath: path.join(outputDir, 'redeem-page.png'),
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
import { shouldCaptureBeijingTimeProof } from './session-proof.js'
|
||||
|
||||
test('shouldCaptureBeijingTimeProof only returns true for successful redeem results', () => {
|
||||
assert.equal(
|
||||
shouldCaptureBeijingTimeProof({
|
||||
classification: {
|
||||
success: true,
|
||||
},
|
||||
}),
|
||||
true,
|
||||
)
|
||||
|
||||
assert.equal(
|
||||
shouldCaptureBeijingTimeProof({
|
||||
classification: {
|
||||
success: false,
|
||||
},
|
||||
}),
|
||||
false,
|
||||
)
|
||||
|
||||
assert.equal(
|
||||
shouldCaptureBeijingTimeProof({
|
||||
redeem: {
|
||||
iRet: 0,
|
||||
},
|
||||
}),
|
||||
true,
|
||||
)
|
||||
|
||||
assert.equal(
|
||||
shouldCaptureBeijingTimeProof({
|
||||
redeem: {
|
||||
iRet: -183,
|
||||
},
|
||||
}),
|
||||
false,
|
||||
)
|
||||
|
||||
assert.equal(shouldCaptureBeijingTimeProof(null), false)
|
||||
})
|
||||
Reference in New Issue
Block a user