后端迁移会话凭证基础模块
This commit is contained in:
@@ -1,31 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
|
|
||||||
import {
|
|
||||||
BAIDU_BEIJING_TIME_URL,
|
|
||||||
BEIJING_TIME_PROOF_CLIP,
|
|
||||||
BEIJING_TIME_PROOF_VIEWPORT,
|
|
||||||
} from './session-proof-constants.js'
|
|
||||||
|
|
||||||
export async function captureBeijingTimeProof(browserContext, { screenshotPath }) {
|
|
||||||
const proofPage = await browserContext.newPage()
|
|
||||||
|
|
||||||
try {
|
|
||||||
await proofPage.setViewportSize(BEIJING_TIME_PROOF_VIEWPORT)
|
|
||||||
await proofPage.goto(BAIDU_BEIJING_TIME_URL, { waitUntil: 'domcontentloaded' })
|
|
||||||
await proofPage.waitForTimeout(3_000)
|
|
||||||
await proofPage.evaluate(() => {
|
|
||||||
window.scrollTo(0, 0)
|
|
||||||
})
|
|
||||||
await proofPage.screenshot({
|
|
||||||
path: screenshotPath,
|
|
||||||
clip: BEIJING_TIME_PROOF_CLIP,
|
|
||||||
})
|
|
||||||
|
|
||||||
return {
|
|
||||||
screenshotPath,
|
|
||||||
pageUrl: BAIDU_BEIJING_TIME_URL,
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
await proofPage.close().catch(() => null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
/// <reference lib="dom" />
|
||||||
|
|
||||||
|
import {
|
||||||
|
BAIDU_BEIJING_TIME_URL,
|
||||||
|
BEIJING_TIME_PROOF_CLIP,
|
||||||
|
BEIJING_TIME_PROOF_VIEWPORT,
|
||||||
|
} from './session-proof-constants.js'
|
||||||
|
|
||||||
|
type BrowserPageLike = {
|
||||||
|
setViewportSize: (viewport: { width: number; height: number }) => Promise<void>
|
||||||
|
goto: (url: string, options?: { waitUntil?: string }) => Promise<unknown>
|
||||||
|
waitForTimeout: (milliseconds: number) => Promise<void>
|
||||||
|
evaluate: (callback: () => unknown) => Promise<unknown>
|
||||||
|
screenshot: (options: {
|
||||||
|
path: string
|
||||||
|
clip: { x: number; y: number; width: number; height: number }
|
||||||
|
}) => Promise<unknown>
|
||||||
|
close: () => Promise<void>
|
||||||
|
}
|
||||||
|
|
||||||
|
type BrowserContextLike = {
|
||||||
|
newPage: () => Promise<BrowserPageLike>
|
||||||
|
}
|
||||||
|
|
||||||
|
export type BeijingTimeProof = {
|
||||||
|
screenshotPath: string
|
||||||
|
pageUrl: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function captureBeijingTimeProof(
|
||||||
|
browserContext: BrowserContextLike,
|
||||||
|
{ screenshotPath }: { screenshotPath: string },
|
||||||
|
): Promise<BeijingTimeProof> {
|
||||||
|
const proofPage = await browserContext.newPage()
|
||||||
|
|
||||||
|
try {
|
||||||
|
await proofPage.setViewportSize(BEIJING_TIME_PROOF_VIEWPORT)
|
||||||
|
await proofPage.goto(BAIDU_BEIJING_TIME_URL, { waitUntil: 'domcontentloaded' })
|
||||||
|
await proofPage.waitForTimeout(3_000)
|
||||||
|
await proofPage.evaluate(() => {
|
||||||
|
window.scrollTo(0, 0)
|
||||||
|
})
|
||||||
|
await proofPage.screenshot({
|
||||||
|
path: screenshotPath,
|
||||||
|
clip: BEIJING_TIME_PROOF_CLIP,
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
screenshotPath,
|
||||||
|
pageUrl: BAIDU_BEIJING_TIME_URL,
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
await proofPage.close().catch(() => null)
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-1
@@ -1,4 +1,6 @@
|
|||||||
export 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'
|
export 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'
|
||||||
|
export type RedeemProofMode = 'full' | 'basic' | 'off'
|
||||||
|
|
||||||
export const BEIJING_TIME_PROOF_VIEWPORT = { width: 1440, height: 860 }
|
export const BEIJING_TIME_PROOF_VIEWPORT = { width: 1440, height: 860 }
|
||||||
export const BEIJING_TIME_PROOF_CLIP = {
|
export const BEIJING_TIME_PROOF_CLIP = {
|
||||||
x: 0,
|
x: 0,
|
||||||
@@ -6,4 +8,4 @@ export const BEIJING_TIME_PROOF_CLIP = {
|
|||||||
width: BEIJING_TIME_PROOF_VIEWPORT.width,
|
width: BEIJING_TIME_PROOF_VIEWPORT.width,
|
||||||
height: 620,
|
height: 620,
|
||||||
}
|
}
|
||||||
export const DEFAULT_REDEEM_PROOF_MODE = 'full'
|
export const DEFAULT_REDEEM_PROOF_MODE: RedeemProofMode = 'full'
|
||||||
+13
-5
@@ -1,10 +1,18 @@
|
|||||||
// @ts-nocheck
|
|
||||||
|
|
||||||
import { runtimeConfig } from '../../config/runtime.js'
|
import { runtimeConfig } from '../../config/runtime.js'
|
||||||
|
|
||||||
import { DEFAULT_REDEEM_PROOF_MODE } from './session-proof-constants.js'
|
import { DEFAULT_REDEEM_PROOF_MODE, type RedeemProofMode } from './session-proof-constants.js'
|
||||||
|
|
||||||
export function resolveRedeemProofMode(rawMode = runtimeConfig.redeem.proofMode) {
|
type RedeemResultForProof = {
|
||||||
|
classification?: {
|
||||||
|
success?: boolean
|
||||||
|
}
|
||||||
|
redeem?: {
|
||||||
|
iRet?: number | string
|
||||||
|
ret?: number | string
|
||||||
|
}
|
||||||
|
} | null | undefined
|
||||||
|
|
||||||
|
export function resolveRedeemProofMode(rawMode: unknown = runtimeConfig.redeem.proofMode): RedeemProofMode {
|
||||||
const normalized = String(rawMode || '')
|
const normalized = String(rawMode || '')
|
||||||
.trim()
|
.trim()
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
@@ -16,7 +24,7 @@ export function resolveRedeemProofMode(rawMode = runtimeConfig.redeem.proofMode)
|
|||||||
return DEFAULT_REDEEM_PROOF_MODE
|
return DEFAULT_REDEEM_PROOF_MODE
|
||||||
}
|
}
|
||||||
|
|
||||||
export function shouldCaptureBeijingTimeProof(finalResult) {
|
export function shouldCaptureBeijingTimeProof(finalResult: RedeemResultForProof): boolean {
|
||||||
if (finalResult?.classification?.success === true) {
|
if (finalResult?.classification?.success === true) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
+9
-1
@@ -1,6 +1,14 @@
|
|||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
|
|
||||||
export function buildArtifactPaths(outputDir) {
|
export type RedeemArtifactPaths = {
|
||||||
|
redeemPageScreenshotPath: string
|
||||||
|
beijingTimeScreenshotPath: string
|
||||||
|
screenshotPath: string
|
||||||
|
htmlPath: string
|
||||||
|
resultPath: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildArtifactPaths(outputDir: string): RedeemArtifactPaths {
|
||||||
return {
|
return {
|
||||||
redeemPageScreenshotPath: path.join(outputDir, 'redeem-page.png'),
|
redeemPageScreenshotPath: path.join(outputDir, 'redeem-page.png'),
|
||||||
beijingTimeScreenshotPath: path.join(outputDir, 'beijing-time.png'),
|
beijingTimeScreenshotPath: path.join(outputDir, 'beijing-time.png'),
|
||||||
@@ -397,6 +397,17 @@
|
|||||||
- `npm run typecheck`
|
- `npm run typecheck`
|
||||||
- `npm run build`
|
- `npm run build`
|
||||||
- `npm test` 共 139 个用例通过
|
- `npm test` 共 139 个用例通过
|
||||||
|
74. 腾讯浏览器会话 proof 基础模块迁移到 `.ts`:
|
||||||
|
- `src/services/session/session-proof-constants.ts`
|
||||||
|
- `src/services/session/session-proof-paths.ts`
|
||||||
|
- `src/services/session/session-proof-mode.ts`
|
||||||
|
- `src/services/session/session-proof-beijing-time.ts`
|
||||||
|
75. 兑换凭证模式、artifact 路径、北京时间截图浏览器上下文与截图返回值已显式类型化
|
||||||
|
76. Docker 内验证通过:
|
||||||
|
- `src/services/session/session-proof.test.js` 共 4 个用例通过
|
||||||
|
- `npm run typecheck`
|
||||||
|
- `npm run build`
|
||||||
|
- `npm test` 共 139 个用例通过
|
||||||
|
|
||||||
## 下一步建议
|
## 下一步建议
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user