后端迁移领取会话服务
This commit is contained in:
-2
@@ -1,5 +1,3 @@
|
||||
// @ts-check
|
||||
|
||||
import {
|
||||
getTencentBrowserSession,
|
||||
getTencentBrowserSessionScreenshotPath,
|
||||
-2
@@ -1,5 +1,3 @@
|
||||
// @ts-check
|
||||
|
||||
import { findClaimTokenByToken, getClaimTokenById, updateClaimToken } from '../../../repositories/claim-token-repo.js'
|
||||
import { getOrderById } from '../../../repositories/order-repo.js'
|
||||
import { getOrderItemById } from '../../../repositories/order-item-repo.js'
|
||||
+11
-11
@@ -1,5 +1,3 @@
|
||||
// @ts-check
|
||||
|
||||
import {
|
||||
closeTencentBrowserSession,
|
||||
createTencentBrowserSession,
|
||||
@@ -16,37 +14,39 @@ import {
|
||||
normalizeClaimLoginType,
|
||||
} from './shared.js'
|
||||
|
||||
export async function createClaimSession(token, payload = {}) {
|
||||
type JsonObject = Record<string, any>
|
||||
|
||||
export async function createClaimSession(token: unknown, payload: JsonObject = {}) {
|
||||
return createClaimSessionWithContextLoader(
|
||||
() => getClaimContext(token),
|
||||
payload,
|
||||
)
|
||||
}
|
||||
|
||||
export async function createClaimSessionForAdminTask(taskId, payload = {}) {
|
||||
export async function createClaimSessionForAdminTask(taskId: unknown, payload: JsonObject = {}) {
|
||||
return createClaimSessionWithContextLoader(
|
||||
() => getClaimContextByTaskId(taskId),
|
||||
payload,
|
||||
)
|
||||
}
|
||||
|
||||
export async function reloadClaimSession(token) {
|
||||
export async function reloadClaimSession(token: unknown) {
|
||||
return reloadClaimSessionWithContextLoader(() => getClaimContext(token))
|
||||
}
|
||||
|
||||
export async function reloadClaimSessionForAdminTask(taskId) {
|
||||
export async function reloadClaimSessionForAdminTask(taskId: unknown) {
|
||||
return reloadClaimSessionWithContextLoader(() => getClaimContextByTaskId(taskId))
|
||||
}
|
||||
|
||||
export async function closeClaimSession(token) {
|
||||
export async function closeClaimSession(token: unknown) {
|
||||
return closeClaimSessionWithContextLoader(() => getClaimContext(token))
|
||||
}
|
||||
|
||||
export async function closeClaimSessionForAdminTask(taskId) {
|
||||
export async function closeClaimSessionForAdminTask(taskId: unknown) {
|
||||
return closeClaimSessionWithContextLoader(() => getClaimContextByTaskId(taskId))
|
||||
}
|
||||
|
||||
async function createClaimSessionWithContextLoader(loadContext, payload = {}) {
|
||||
async function createClaimSessionWithContextLoader(loadContext: () => Promise<JsonObject>, payload: JsonObject = {}) {
|
||||
const context = await loadContext()
|
||||
assertTaskCanProceed(context.task)
|
||||
const requestedLoginType = normalizeClaimLoginType(payload.loginType)
|
||||
@@ -108,7 +108,7 @@ async function createClaimSessionWithContextLoader(loadContext, payload = {}) {
|
||||
})
|
||||
}
|
||||
|
||||
async function reloadClaimSessionWithContextLoader(loadContext) {
|
||||
async function reloadClaimSessionWithContextLoader(loadContext: () => Promise<JsonObject>) {
|
||||
const context = await loadContext()
|
||||
assertTaskCanProceed(context.task)
|
||||
|
||||
@@ -138,7 +138,7 @@ async function reloadClaimSessionWithContextLoader(loadContext) {
|
||||
})
|
||||
}
|
||||
|
||||
async function closeClaimSessionWithContextLoader(loadContext) {
|
||||
async function closeClaimSessionWithContextLoader(loadContext: () => Promise<JsonObject>) {
|
||||
const context = await loadContext()
|
||||
assertTaskCanProceed(context.task)
|
||||
let task = context.task
|
||||
+6
-6
@@ -1,5 +1,3 @@
|
||||
// @ts-check
|
||||
|
||||
import {
|
||||
getTencentBrowserSession,
|
||||
getTencentBrowserSessionSummary,
|
||||
@@ -8,7 +6,9 @@ import { updateTask } from '../../../repositories/task-repo.js'
|
||||
import { nowIso } from '../../../utils/time.js'
|
||||
import { isRecoverableSessionError, parseTaskState } from './shared.js'
|
||||
|
||||
export async function loadTaskSession(task, { includeQrImage = false } = {}) {
|
||||
type JsonObject = Record<string, any>
|
||||
|
||||
export async function loadTaskSession(task: JsonObject, { includeQrImage = false }: { includeQrImage?: boolean } = {}) {
|
||||
if (!task.browser_session_id) {
|
||||
return {
|
||||
task,
|
||||
@@ -41,9 +41,9 @@ export async function loadTaskSession(task, { includeQrImage = false } = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function syncTaskWithSession(task, session) {
|
||||
export async function syncTaskWithSession(task: JsonObject, session: JsonObject) {
|
||||
const activityInfo = session.activityInfo || null
|
||||
const patch = {
|
||||
const patch: JsonObject = {
|
||||
login_type: String(session.loginType || task.login_type || ''),
|
||||
updated_at: nowIso(),
|
||||
}
|
||||
@@ -82,7 +82,7 @@ export async function syncTaskWithSession(task, session) {
|
||||
return updateTask(task.id, patch)
|
||||
}
|
||||
|
||||
export async function clearTaskSession(task, { lastError = '' } = {}) {
|
||||
export async function clearTaskSession(task: JsonObject, { lastError = '' }: { lastError?: string } = {}) {
|
||||
const shouldResetClaimProgress = ['link_generated', 'claimed', 'role_confirmed'].includes(String(task.task_status || ''))
|
||||
const nextTaskStatus = shouldResetClaimProgress ? 'link_generated' : task.task_status
|
||||
const nextUserActionStatus = shouldResetClaimProgress ? 'pending_claim' : task.user_action_status
|
||||
-2
@@ -1,5 +1,3 @@
|
||||
// @ts-check
|
||||
|
||||
import { buildClaimUrl } from '../claim-service.js'
|
||||
import { createHttpError } from '../../../utils/http.js'
|
||||
import { formatFenToAmount, normalizeFen } from '../../../utils/money.js'
|
||||
Reference in New Issue
Block a user