设置云触手默认登录设备
This commit is contained in:
@@ -9,8 +9,8 @@
|
||||
"username": "",
|
||||
"password": "",
|
||||
"phone": "",
|
||||
"deviceId": "-",
|
||||
"deviceType": 0
|
||||
"deviceId": "08bc9d8c-fd15-48ea-bc00-8d754076cafc",
|
||||
"deviceType": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -79,8 +79,8 @@ export function createDefaultRuntimeConfig(projectRoot: string): RuntimeConfig {
|
||||
bindUrlProbeReferer: "https://gp.qq.com/",
|
||||
bindUrlProbeExtraCookie: "",
|
||||
clientSource: "ct-client",
|
||||
deviceId: "-",
|
||||
deviceType: 0,
|
||||
deviceId: "08bc9d8c-fd15-48ea-bc00-8d754076cafc",
|
||||
deviceType: 1,
|
||||
publicKeyPem: `-----BEGIN PUBLIC KEY-----
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsSzjk+9st2f8IpYqYaM5
|
||||
F7K27ZR2IvzxTr2w4zgZAS2+BRdgMvXUOITdFQT+ytYF/r3pIgTkL7MF9UQuylmb
|
||||
|
||||
@@ -142,8 +142,8 @@ function createRuntimeConfig(): RuntimeConfig {
|
||||
bindUrlProbeExtraCookie: '',
|
||||
publicKeyPem: '',
|
||||
clientSource: 'ct-client',
|
||||
deviceId: '-',
|
||||
deviceType: 0,
|
||||
deviceId: '08bc9d8c-fd15-48ea-bc00-8d754076cafc',
|
||||
deviceType: 1,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -182,8 +182,8 @@ function createRuntimeConfig(overrides: Record<string, unknown> = {}): RuntimeCo
|
||||
bindUrlProbeExtraCookie: '',
|
||||
publicKeyPem: '',
|
||||
clientSource: 'ct-client',
|
||||
deviceId: '-',
|
||||
deviceType: 0,
|
||||
deviceId: '08bc9d8c-fd15-48ea-bc00-8d754076cafc',
|
||||
deviceType: 1,
|
||||
},
|
||||
},
|
||||
}, overrides) as RuntimeConfig
|
||||
|
||||
@@ -43,6 +43,10 @@ export function resolveKuaishouEticketAdminContext(payload: JsonObject = {}, opt
|
||||
|
||||
import { getCloudtentaclesSourceByKey } from "../../../platforms/cloudtentacles/source-config-service.js";
|
||||
import { getCloudtentaclesSessionStateByKey } from "../../../platforms/cloudtentacles/session-state-service.js";
|
||||
import {
|
||||
normalizeCloudtentaclesDeviceId,
|
||||
normalizeCloudtentaclesDeviceType,
|
||||
} from "../../../platforms/cloudtentacles/defaults.js";
|
||||
|
||||
export function resolveCloudtentaclesAdminContext(payload: JsonObject = {}, options: JsonObject = {}) {
|
||||
const sourceKey = String(
|
||||
@@ -63,16 +67,16 @@ export function resolveCloudtentaclesAdminContext(payload: JsonObject = {}, opti
|
||||
defaultBaseUrl,
|
||||
]),
|
||||
token: pickFirstNonEmpty([payload.token, persistedSession.token]),
|
||||
deviceId: pickFirstNonEmpty([
|
||||
payload.deviceId,
|
||||
savedSource.deviceId,
|
||||
persistedSession.deviceId,
|
||||
"-",
|
||||
]),
|
||||
deviceType:
|
||||
payload.deviceType ??
|
||||
savedSource.deviceType ??
|
||||
persistedSession.deviceType,
|
||||
deviceId: normalizeCloudtentaclesDeviceId(
|
||||
pickFirstNonEmpty([
|
||||
payload.deviceId,
|
||||
savedSource.deviceId,
|
||||
persistedSession.deviceId,
|
||||
])
|
||||
),
|
||||
deviceType: normalizeCloudtentaclesDeviceType(
|
||||
payload.deviceType ?? savedSource.deviceType ?? persistedSession.deviceType
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,10 @@ import {
|
||||
maskPhone as maskPhoneValue,
|
||||
maskSecret as maskSecretValue,
|
||||
} from "../../../../utils/masking.js";
|
||||
import {
|
||||
normalizeCloudtentaclesDeviceId,
|
||||
normalizeCloudtentaclesDeviceType,
|
||||
} from "../../../platforms/cloudtentacles/defaults.js";
|
||||
|
||||
type JsonObject = Record<string, any>
|
||||
|
||||
@@ -42,8 +46,8 @@ export function mapAdminCloudtentaclesSourceConfig(config: JsonObject = {}) {
|
||||
username: String(config.username || "").trim(),
|
||||
password: String(config.password || "").trim(),
|
||||
phone: String(config.phone || "").trim(),
|
||||
deviceId: String(config.deviceId || "-").trim() || "-",
|
||||
deviceType: Number(config.deviceType || 0),
|
||||
deviceId: normalizeCloudtentaclesDeviceId(config.deviceId),
|
||||
deviceType: normalizeCloudtentaclesDeviceType(config.deviceType),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -55,8 +59,8 @@ export function mapAdminCloudtentaclesSession(session: JsonObject = {}) {
|
||||
username: String(session.username || "").trim(),
|
||||
phoneMasked: maskPhone(session.phone),
|
||||
loggedInAt: String(session.loggedInAt || "").trim(),
|
||||
deviceId: String(session.deviceId || "-").trim() || "-",
|
||||
deviceType: Number(session.deviceType || 0),
|
||||
deviceId: normalizeCloudtentaclesDeviceId(session.deviceId),
|
||||
deviceType: normalizeCloudtentaclesDeviceType(session.deviceType),
|
||||
hasToken: Boolean(String(session.token || "").trim()),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { getCloudtentaclesSourceByKey } from "../../../platforms/cloudtentacles/source-config-service.js";
|
||||
import { getCloudtentaclesSessionStateByKey } from "../../../platforms/cloudtentacles/session-state-service.js";
|
||||
import {
|
||||
normalizeCloudtentaclesDeviceId,
|
||||
normalizeCloudtentaclesDeviceType,
|
||||
} from "../../../platforms/cloudtentacles/defaults.js";
|
||||
import {
|
||||
pickFirstNonEmpty,
|
||||
resolveCloudtentaclesAdminContext,
|
||||
@@ -34,8 +38,12 @@ export function resolveAdminCloudtentaclesCredentialPayload(
|
||||
username: pickFirstNonEmpty([payload.username, savedSource.username]),
|
||||
password: pickFirstNonEmpty([payload.password, savedSource.password]),
|
||||
phone: pickFirstNonEmpty([payload.phone, savedSource.phone]),
|
||||
deviceId: pickFirstNonEmpty([payload.deviceId, savedSource.deviceId, "-"]),
|
||||
deviceType: payload.deviceType ?? savedSource.deviceType,
|
||||
deviceId: normalizeCloudtentaclesDeviceId(
|
||||
pickFirstNonEmpty([payload.deviceId, savedSource.deviceId])
|
||||
),
|
||||
deviceType: normalizeCloudtentaclesDeviceType(
|
||||
payload.deviceType ?? savedSource.deviceType
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -67,8 +75,12 @@ export function buildAdminCloudtentaclesPersistedSessionPayload(
|
||||
username: pickFirstNonEmpty([options.username, session.username]),
|
||||
phone: pickFirstNonEmpty([options.phone, session.phone]),
|
||||
loggedInAt: String(session.loggedInAt || "").trim(),
|
||||
deviceId: pickFirstNonEmpty([options.deviceId, session.deviceId, "-"]),
|
||||
deviceType: options.deviceType ?? session.deviceType,
|
||||
deviceId: normalizeCloudtentaclesDeviceId(
|
||||
pickFirstNonEmpty([options.deviceId, session.deviceId])
|
||||
),
|
||||
deviceType: normalizeCloudtentaclesDeviceType(
|
||||
options.deviceType ?? session.deviceType
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
import {
|
||||
normalizeCloudtentaclesDeviceId,
|
||||
normalizeCloudtentaclesDeviceType,
|
||||
} from "../../../platforms/cloudtentacles/defaults.js";
|
||||
|
||||
type JsonObject = Record<string, any>;
|
||||
|
||||
export function normalizeAdminCloudtentaclesSourceConfigPayload(
|
||||
@@ -13,7 +18,7 @@ export function normalizeAdminCloudtentaclesSourceConfigPayload(
|
||||
username: String(payload.username || "").trim(),
|
||||
password: String(payload.password || "").trim(),
|
||||
phone: String(payload.phone || "").trim(),
|
||||
deviceId: String(payload.deviceId || "-").trim() || "-",
|
||||
deviceType: Number(payload.deviceType || 0),
|
||||
deviceId: normalizeCloudtentaclesDeviceId(payload.deviceId),
|
||||
deviceType: normalizeCloudtentaclesDeviceType(payload.deviceType),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import { createHttpError } from "../../../utils/http.js";
|
||||
import {
|
||||
normalizeCloudtentaclesDeviceId,
|
||||
normalizeCloudtentaclesDeviceType,
|
||||
} from "../../platforms/cloudtentacles/defaults.js";
|
||||
import { getCloudtentaclesSourceByKey } from "../../platforms/cloudtentacles/source-config-service.js";
|
||||
import { getCloudtentaclesSessionStateByKey } from "../../platforms/cloudtentacles/session-state-service.js";
|
||||
import { normalizeStringArray } from "./domain.js";
|
||||
@@ -53,9 +57,12 @@ export function resolvePersistedCloudtentaclesContextBySourceKeys(
|
||||
String(session.baseUrl || source.baseUrl || "").trim() ||
|
||||
"https://123.207.217.176",
|
||||
token,
|
||||
deviceId:
|
||||
String(session.deviceId || source.deviceId || "-").trim() || "-",
|
||||
deviceType: Number(session.deviceType ?? source.deviceType ?? 0),
|
||||
deviceId: normalizeCloudtentaclesDeviceId(
|
||||
session.deviceId || source.deviceId
|
||||
),
|
||||
deviceType: normalizeCloudtentaclesDeviceType(
|
||||
session.deviceType ?? source.deviceType
|
||||
),
|
||||
resolvedSourceKey: sourceKey,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,6 +4,10 @@ import {
|
||||
import {
|
||||
getCloudtentaclesSessionStateByKey,
|
||||
} from '../platforms/cloudtentacles/session-state-service.js'
|
||||
import {
|
||||
normalizeCloudtentaclesDeviceId,
|
||||
normalizeCloudtentaclesDeviceType,
|
||||
} from '../platforms/cloudtentacles/defaults.js'
|
||||
import {
|
||||
listCloudtentaclesSku,
|
||||
} from '../platforms/cloudtentacles/catalog-service.js'
|
||||
@@ -167,8 +171,8 @@ function buildCloudtentaclesSourceContext(
|
||||
sourceKey,
|
||||
baseUrl: String(session?.baseUrl || source.baseUrl || '').trim(),
|
||||
token,
|
||||
deviceId: String(session?.deviceId || source.deviceId || '-').trim() || '-',
|
||||
deviceType: Number(session?.deviceType ?? source.deviceType ?? 0),
|
||||
deviceId: normalizeCloudtentaclesDeviceId(session?.deviceId || source.deviceId),
|
||||
deviceType: normalizeCloudtentaclesDeviceType(session?.deviceType ?? source.deviceType),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
import {
|
||||
DEFAULT_CLOUDTENTACLES_DEVICE_ID,
|
||||
DEFAULT_CLOUDTENTACLES_DEVICE_TYPE,
|
||||
normalizeCloudtentaclesDeviceId,
|
||||
normalizeCloudtentaclesDeviceType,
|
||||
} from './defaults.js'
|
||||
|
||||
test('normalizeCloudtentaclesDeviceId maps empty and legacy placeholder to default device', () => {
|
||||
assert.equal(normalizeCloudtentaclesDeviceId(''), DEFAULT_CLOUDTENTACLES_DEVICE_ID)
|
||||
assert.equal(normalizeCloudtentaclesDeviceId('-'), DEFAULT_CLOUDTENTACLES_DEVICE_ID)
|
||||
assert.equal(normalizeCloudtentaclesDeviceId(' custom-device '), 'custom-device')
|
||||
})
|
||||
|
||||
test('normalizeCloudtentaclesDeviceType maps empty and legacy zero to default type', () => {
|
||||
assert.equal(normalizeCloudtentaclesDeviceType(undefined), DEFAULT_CLOUDTENTACLES_DEVICE_TYPE)
|
||||
assert.equal(normalizeCloudtentaclesDeviceType(0), DEFAULT_CLOUDTENTACLES_DEVICE_TYPE)
|
||||
assert.equal(normalizeCloudtentaclesDeviceType('2'), 2)
|
||||
})
|
||||
@@ -0,0 +1,17 @@
|
||||
export const DEFAULT_CLOUDTENTACLES_DEVICE_ID =
|
||||
"08bc9d8c-fd15-48ea-bc00-8d754076cafc";
|
||||
export const DEFAULT_CLOUDTENTACLES_DEVICE_TYPE = 1;
|
||||
|
||||
export function normalizeCloudtentaclesDeviceId(value: unknown) {
|
||||
const normalized = String(value || "").trim();
|
||||
return normalized && normalized !== "-"
|
||||
? normalized
|
||||
: DEFAULT_CLOUDTENTACLES_DEVICE_ID;
|
||||
}
|
||||
|
||||
export function normalizeCloudtentaclesDeviceType(value: unknown) {
|
||||
const parsed = Number(value);
|
||||
return Number.isInteger(parsed) && parsed > 0
|
||||
? parsed
|
||||
: DEFAULT_CLOUDTENTACLES_DEVICE_TYPE;
|
||||
}
|
||||
@@ -1,6 +1,12 @@
|
||||
import { runtimeConfig } from '../../../config/runtime.js'
|
||||
|
||||
import type { RuntimeConfig } from '../../../types/runtime-config.js'
|
||||
import {
|
||||
DEFAULT_CLOUDTENTACLES_DEVICE_ID,
|
||||
DEFAULT_CLOUDTENTACLES_DEVICE_TYPE,
|
||||
normalizeCloudtentaclesDeviceId,
|
||||
normalizeCloudtentaclesDeviceType,
|
||||
} from './defaults.js'
|
||||
|
||||
type CloudtentaclesRuntimeConfig = RuntimeConfig['platforms']['cloudtentacles']
|
||||
type JsonObject = Record<string, any>
|
||||
@@ -40,8 +46,8 @@ export function resolveCloudtentaclesConfig(overrides: Partial<CloudtentaclesRun
|
||||
bindUrlProbeExtraCookie: '',
|
||||
publicKeyPem: '',
|
||||
clientSource: 'ct-client',
|
||||
deviceId: '-',
|
||||
deviceType: 0,
|
||||
deviceId: DEFAULT_CLOUDTENTACLES_DEVICE_ID,
|
||||
deviceType: DEFAULT_CLOUDTENTACLES_DEVICE_TYPE,
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -87,8 +93,8 @@ export function resolveCloudtentaclesConfig(overrides: Partial<CloudtentaclesRun
|
||||
bindUrlProbeExtraCookie: String(overrides.bindUrlProbeExtraCookie || baseConfig.bindUrlProbeExtraCookie || '').trim(),
|
||||
publicKeyPem: normalizePem(overrides.publicKeyPem || baseConfig.publicKeyPem),
|
||||
clientSource: String(overrides.clientSource || baseConfig.clientSource || 'ct-client').trim() || 'ct-client',
|
||||
deviceId: String(overrides.deviceId ?? baseConfig.deviceId ?? '-').trim() || '-',
|
||||
deviceType: normalizeInteger(overrides.deviceType ?? baseConfig.deviceType, 0),
|
||||
deviceId: normalizeCloudtentaclesDeviceId(overrides.deviceId ?? baseConfig.deviceId),
|
||||
deviceType: normalizeCloudtentaclesDeviceType(overrides.deviceType ?? baseConfig.deviceType),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,8 +120,8 @@ export function buildCloudtentaclesUrl(
|
||||
export function buildCloudtentaclesHeaders({
|
||||
token = '',
|
||||
contentType = 'application/json',
|
||||
deviceId = '-',
|
||||
deviceType = 0,
|
||||
deviceId = DEFAULT_CLOUDTENTACLES_DEVICE_ID,
|
||||
deviceType = DEFAULT_CLOUDTENTACLES_DEVICE_TYPE,
|
||||
extra = {},
|
||||
}: {
|
||||
token?: unknown
|
||||
@@ -127,8 +133,8 @@ export function buildCloudtentaclesHeaders({
|
||||
const headers: JsonObject = {
|
||||
accept: 'application/json, text/plain, */*',
|
||||
...(contentType ? { 'content-type': contentType } : {}),
|
||||
deviceid: String(deviceId || '-').trim() || '-',
|
||||
devicetype: String(Number(deviceType || 0)),
|
||||
deviceid: normalizeCloudtentaclesDeviceId(deviceId),
|
||||
devicetype: String(normalizeCloudtentaclesDeviceType(deviceType)),
|
||||
...normalizeHeaderMap(extra),
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,12 @@ import path from 'node:path'
|
||||
|
||||
import { PROJECT_ROOT } from '../../../config/runtime.js'
|
||||
import { createHttpError } from '../../../utils/http.js'
|
||||
import {
|
||||
DEFAULT_CLOUDTENTACLES_DEVICE_ID,
|
||||
DEFAULT_CLOUDTENTACLES_DEVICE_TYPE,
|
||||
normalizeCloudtentaclesDeviceId,
|
||||
normalizeCloudtentaclesDeviceType,
|
||||
} from './defaults.js'
|
||||
|
||||
const CLOUDTENTACLES_SESSION_FILE_PATH = path.join(PROJECT_ROOT, 'data', 'cloudtentacles-session.json')
|
||||
|
||||
@@ -166,8 +172,8 @@ function normalizeCloudtentaclesSessionState(rawValue: unknown) {
|
||||
username: String(source.username || '').trim(),
|
||||
phone: String(source.phone || '').trim(),
|
||||
loggedInAt: String(source.loggedInAt || '').trim(),
|
||||
deviceId: String(source.deviceId || '-').trim() || '-',
|
||||
deviceType: normalizeInteger(source.deviceType, 0),
|
||||
deviceId: normalizeCloudtentaclesDeviceId(source.deviceId),
|
||||
deviceType: normalizeCloudtentaclesDeviceType(source.deviceType),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,8 +209,8 @@ function createDefaultCloudtentaclesSessionState() {
|
||||
username: '',
|
||||
phone: '',
|
||||
loggedInAt: '',
|
||||
deviceId: '-',
|
||||
deviceType: 0,
|
||||
deviceId: DEFAULT_CLOUDTENTACLES_DEVICE_ID,
|
||||
deviceType: DEFAULT_CLOUDTENTACLES_DEVICE_TYPE,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,11 +222,6 @@ function createDefaultCloudtentaclesSessionStates(): CloudtentaclesSessionStates
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeInteger(value: unknown, fallback: number) {
|
||||
const parsed = Number(value)
|
||||
return Number.isInteger(parsed) ? parsed : fallback
|
||||
}
|
||||
|
||||
function isPlainObject(value: unknown): value is JsonObject {
|
||||
return Object.prototype.toString.call(value) === '[object Object]'
|
||||
}
|
||||
|
||||
@@ -3,6 +3,10 @@ import path from 'node:path'
|
||||
|
||||
import { PROJECT_ROOT } from '../../../config/runtime.js'
|
||||
import { createHttpError } from '../../../utils/http.js'
|
||||
import {
|
||||
normalizeCloudtentaclesDeviceId,
|
||||
normalizeCloudtentaclesDeviceType,
|
||||
} from './defaults.js'
|
||||
|
||||
const CLOUDTENTACLES_SOURCES_FILE_PATH = path.join(PROJECT_ROOT, 'data', 'cloudtentacles-sources.json')
|
||||
|
||||
@@ -142,8 +146,8 @@ function normalizeCloudtentaclesSourceItem(rawValue: unknown) {
|
||||
username: String(source.username || '').trim(),
|
||||
password: String(source.password || '').trim(),
|
||||
phone: String(source.phone || '').trim(),
|
||||
deviceId: String(source.deviceId || '-').trim() || '-',
|
||||
deviceType: normalizeInteger(source.deviceType, 0),
|
||||
deviceId: normalizeCloudtentaclesDeviceId(source.deviceId),
|
||||
deviceType: normalizeCloudtentaclesDeviceType(source.deviceType),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,11 +188,6 @@ function createDefaultCloudtentaclesSourcesConfig() {
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeInteger(value: unknown, fallback: number) {
|
||||
const parsed = Number(value)
|
||||
return Number.isInteger(parsed) ? parsed : fallback
|
||||
}
|
||||
|
||||
function isPlainObject(value: unknown): value is JsonObject {
|
||||
return Object.prototype.toString.call(value) === '[object Object]'
|
||||
}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import { getCloudtentaclesAsset } from '../platforms/cloudtentacles/catalog-service.js'
|
||||
import {
|
||||
normalizeCloudtentaclesDeviceId,
|
||||
normalizeCloudtentaclesDeviceType,
|
||||
} from '../platforms/cloudtentacles/defaults.js'
|
||||
import {
|
||||
getCloudtentaclesSourceByKey,
|
||||
listCloudtentaclesSources,
|
||||
@@ -134,8 +138,8 @@ async function runCloudtentaclesHealthAccount(
|
||||
accountLabel: label,
|
||||
baseUrl: String(session.baseUrl || source.baseUrl || '').trim() || 'https://123.207.217.176',
|
||||
token,
|
||||
deviceId: String(session.deviceId || source.deviceId || '-').trim() || '-',
|
||||
deviceType: Number(session.deviceType ?? source.deviceType ?? 0),
|
||||
deviceId: normalizeCloudtentaclesDeviceId(session.deviceId || source.deviceId),
|
||||
deviceType: normalizeCloudtentaclesDeviceType(session.deviceType ?? source.deviceType),
|
||||
})
|
||||
const asset = Number(assetResult.asset || 0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user