优化快手 Cloud 主链路状态机
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
export const TASK_STATUS = {
|
||||
PENDING_PAYMENT: "pending_payment",
|
||||
PAID: "paid",
|
||||
LINK_GENERATED: "link_generated",
|
||||
CLAIMED: "claimed",
|
||||
PENDING_BINDING_PREPARE: "pending_binding_prepare",
|
||||
WAITING_BINDING: "waiting_binding",
|
||||
ROLE_CONFIRMED: "role_confirmed",
|
||||
REDEEMING: "redeeming",
|
||||
DISPATCHED_PENDING_RETURN: "dispatched_pending_return",
|
||||
COMPLETED: "completed",
|
||||
REDEEMED: "redeemed",
|
||||
RETRY_PENDING: "retry_pending",
|
||||
MANUAL_REVIEW: "manual_review",
|
||||
FAILED: "failed",
|
||||
EXPIRED: "expired",
|
||||
CLOSED: "closed",
|
||||
} as const;
|
||||
|
||||
export type KnownTaskStatus = (typeof TASK_STATUS)[keyof typeof TASK_STATUS];
|
||||
export type TaskStatus = KnownTaskStatus | (string & {});
|
||||
|
||||
const CLAIM_INACTIVE_STATUSES = new Set<TaskStatus>([
|
||||
TASK_STATUS.COMPLETED,
|
||||
TASK_STATUS.REDEEMED,
|
||||
TASK_STATUS.MANUAL_REVIEW,
|
||||
TASK_STATUS.FAILED,
|
||||
TASK_STATUS.EXPIRED,
|
||||
TASK_STATUS.CLOSED,
|
||||
]);
|
||||
|
||||
const KUAISHOU_CLOUD_RESULT_STATUSES = new Set<TaskStatus>([
|
||||
TASK_STATUS.DISPATCHED_PENDING_RETURN,
|
||||
TASK_STATUS.COMPLETED,
|
||||
TASK_STATUS.REDEEMED,
|
||||
TASK_STATUS.MANUAL_REVIEW,
|
||||
TASK_STATUS.FAILED,
|
||||
]);
|
||||
|
||||
export function normalizeTaskStatus(value: unknown): TaskStatus {
|
||||
return String(value || "").trim() as TaskStatus;
|
||||
}
|
||||
|
||||
export function isClaimInactiveTaskStatus(status: unknown): boolean {
|
||||
return CLAIM_INACTIVE_STATUSES.has(normalizeTaskStatus(status));
|
||||
}
|
||||
|
||||
export function isKuaishouCloudRoleConfirmedStatus(status: unknown): boolean {
|
||||
return normalizeTaskStatus(status) === TASK_STATUS.ROLE_CONFIRMED;
|
||||
}
|
||||
|
||||
export function isKuaishouCloudCompletedStatus(status: unknown): boolean {
|
||||
const normalized = normalizeTaskStatus(status);
|
||||
return normalized === TASK_STATUS.COMPLETED || normalized === TASK_STATUS.REDEEMED;
|
||||
}
|
||||
|
||||
export function hasKuaishouCloudRedeemResultStatus(status: unknown): boolean {
|
||||
return KUAISHOU_CLOUD_RESULT_STATUSES.has(normalizeTaskStatus(status));
|
||||
}
|
||||
@@ -1,23 +1,8 @@
|
||||
import type { KnownTaskStatus } from '@/domain/task-status'
|
||||
|
||||
export type ClaimTokenStatus = 'active' | 'used' | 'expired' | 'revoked' | (string & {})
|
||||
|
||||
export type ClaimTaskStatus =
|
||||
| 'pending_payment'
|
||||
| 'paid'
|
||||
| 'pending_binding_prepare'
|
||||
| 'waiting_binding'
|
||||
| 'dispatched_pending_return'
|
||||
| 'completed'
|
||||
| 'failed'
|
||||
| 'link_generated'
|
||||
| 'claimed'
|
||||
| 'role_confirmed'
|
||||
| 'redeeming'
|
||||
| 'redeemed'
|
||||
| 'retry_pending'
|
||||
| 'manual_review'
|
||||
| 'expired'
|
||||
| 'closed'
|
||||
| (string & {})
|
||||
export type ClaimTaskStatus = KnownTaskStatus | (string & {})
|
||||
|
||||
export interface ClaimTaskInfo {
|
||||
taskId: number
|
||||
|
||||
@@ -3,6 +3,12 @@ import QRCode from "qrcode";
|
||||
import { ElMessageBox } from "element-plus";
|
||||
|
||||
import { showError, showSuccess } from "@/lib/feedback";
|
||||
import {
|
||||
hasKuaishouCloudRedeemResultStatus,
|
||||
isClaimInactiveTaskStatus,
|
||||
isKuaishouCloudCompletedStatus,
|
||||
isKuaishouCloudRoleConfirmedStatus,
|
||||
} from "@/domain/task-status";
|
||||
import { formatAdminDateTime } from "@/utils/admin-time";
|
||||
import {
|
||||
confirmKuaishouCloudClaimRole,
|
||||
@@ -75,7 +81,7 @@ export function useKuaishouCloudClaim(token: () => string) {
|
||||
const canEnterBindingStep = computed(() => isTicketVerified.value);
|
||||
const isRoleReady = computed(() => Boolean(roleName.value || roleId.value));
|
||||
const isRoleConfirmed = computed(
|
||||
() => String(task.value?.status || "").trim() === "role_confirmed"
|
||||
() => isKuaishouCloudRoleConfirmedStatus(task.value?.status)
|
||||
);
|
||||
const isDispatched = computed(
|
||||
() => String(flow.value?.dispatch.status || "").trim() === "success"
|
||||
@@ -83,28 +89,17 @@ export function useKuaishouCloudClaim(token: () => string) {
|
||||
|
||||
const isCompleted = computed(
|
||||
() =>
|
||||
String(task.value?.status || "").trim() === "completed" ||
|
||||
isKuaishouCloudCompletedStatus(task.value?.status) ||
|
||||
String(flow.value?.consume.status || "").trim() === "success"
|
||||
);
|
||||
|
||||
const hasRedeemResult = computed(() => {
|
||||
const status = String(task.value?.status || "").trim();
|
||||
return (
|
||||
isDispatched.value ||
|
||||
[
|
||||
"dispatched_pending_return",
|
||||
"completed",
|
||||
"manual_review",
|
||||
"failed",
|
||||
].includes(status)
|
||||
);
|
||||
return isDispatched.value || hasKuaishouCloudRedeemResultStatus(task.value?.status);
|
||||
});
|
||||
|
||||
const canSubmitTicket = computed(
|
||||
() =>
|
||||
!["completed", "manual_review", "closed", "expired"].includes(
|
||||
String(task.value?.status || "").trim()
|
||||
) && !submitting.value
|
||||
!isClaimInactiveTaskStatus(task.value?.status) && !submitting.value
|
||||
);
|
||||
|
||||
const currentStep = computed(() => {
|
||||
@@ -323,12 +318,10 @@ export function useKuaishouCloudClaim(token: () => string) {
|
||||
}
|
||||
|
||||
function resolveNextPollDelay() {
|
||||
const taskStatus = String(task.value?.status || "").trim();
|
||||
|
||||
if (
|
||||
!flow.value ||
|
||||
hasRedeemResult.value ||
|
||||
["closed", "expired", "manual_review", "failed"].includes(taskStatus)
|
||||
isClaimInactiveTaskStatus(task.value?.status)
|
||||
) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user