完善半自动履约凭证与客户重新授权流程
统一虎牙和微博账号级 CK 保存与导出;CK 失效后回到客户重新登录,后台支持重发授权;客户授权页改为统一深色布局并收敛开发迁移配置。
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
import type { PoolClient } from 'pg'
|
||||
|
||||
import { query } from '../../db/client.js'
|
||||
import {
|
||||
decryptSemiAutoCredential,
|
||||
encryptSemiAutoCredential,
|
||||
} from './semi-auto-credential-crypto.js'
|
||||
|
||||
export type SemiAutoCredentialCookie = {
|
||||
name: string
|
||||
@@ -38,7 +34,7 @@ type CredentialRow = {
|
||||
platform: 'huya' | 'weibo'
|
||||
platform_uid: string
|
||||
platform_nickname: string
|
||||
credential_ciphertext: string
|
||||
credential_payload_json: string
|
||||
credential_source: SemiAutoCredentialSource | ''
|
||||
credential_status: 'unknown' | 'valid' | 'invalid' | 'error'
|
||||
credential_updated_at: string
|
||||
@@ -102,8 +98,7 @@ export function buildSemiAutoCredentialCookieHeader(
|
||||
}
|
||||
|
||||
function decodeCredential(row: CredentialRow): SemiAutoCredentialRecord {
|
||||
const decrypted = decryptSemiAutoCredential(row.credential_ciphertext)
|
||||
const parsed = JSON.parse(decrypted) as Record<string, unknown>
|
||||
const parsed = JSON.parse(row.credential_payload_json) as Record<string, unknown>
|
||||
return {
|
||||
id: Number(row.id),
|
||||
platform: row.platform,
|
||||
@@ -132,15 +127,11 @@ export async function upsertSemiAutoCredentialWithClient(
|
||||
if (cookies.length === 0) {
|
||||
throw new Error('平台 Cookie 为空,无法保存半自动履约凭证')
|
||||
}
|
||||
const encrypted = encryptSemiAutoCredential(
|
||||
JSON.stringify({
|
||||
cookies,
|
||||
}),
|
||||
)
|
||||
const payloadJson = JSON.stringify({ cookies })
|
||||
const result = await client.query<{ id: number }>(
|
||||
`
|
||||
INSERT INTO semi_auto_credentials (
|
||||
platform, platform_uid, platform_nickname, credential_ciphertext,
|
||||
platform, platform_uid, platform_nickname, credential_payload_json,
|
||||
credential_source, credential_status, credential_updated_at,
|
||||
last_checked_at, last_check_error, created_at, updated_at
|
||||
) VALUES (
|
||||
@@ -148,7 +139,7 @@ export async function upsertSemiAutoCredentialWithClient(
|
||||
)
|
||||
ON CONFLICT (platform, platform_uid) DO UPDATE
|
||||
SET platform_nickname = EXCLUDED.platform_nickname,
|
||||
credential_ciphertext = EXCLUDED.credential_ciphertext,
|
||||
credential_payload_json = EXCLUDED.credential_payload_json,
|
||||
credential_source = EXCLUDED.credential_source,
|
||||
credential_status = 'valid',
|
||||
credential_updated_at = NOW(),
|
||||
@@ -163,7 +154,7 @@ export async function upsertSemiAutoCredentialWithClient(
|
||||
String(input.payload.nickname || '')
|
||||
.trim()
|
||||
.slice(0, 120),
|
||||
encrypted,
|
||||
payloadJson,
|
||||
input.source,
|
||||
],
|
||||
)
|
||||
@@ -178,7 +169,7 @@ export async function loadSemiAutoCredential(
|
||||
const result = await query<CredentialRow>(
|
||||
`
|
||||
SELECT
|
||||
id, platform, platform_uid, platform_nickname, credential_ciphertext,
|
||||
id, platform, platform_uid, platform_nickname, credential_payload_json,
|
||||
credential_source, credential_status, credential_updated_at
|
||||
FROM semi_auto_credentials
|
||||
WHERE id = $1
|
||||
|
||||
Reference in New Issue
Block a user