设置云触手默认登录设备

This commit is contained in:
yml
2026-05-28 13:05:44 +08:00
parent e4c9873c8d
commit e8ba48d74f
22 changed files with 198 additions and 79 deletions
+4
View File
@@ -28,3 +28,7 @@ ADMIN_DEFAULT_USERS_JSON=[{"username":"admin","password":"dev-admin-123456","rol
# 91Kaquan # 91Kaquan
KAQUAN91_USER_ID= KAQUAN91_USER_ID=
KAQUAN91_SECRET= KAQUAN91_SECRET=
# Cloudtentacles
CLOUDTENTACLES_DEVICE_ID=08bc9d8c-fd15-48ea-bc00-8d754076cafc
CLOUDTENTACLES_DEVICE_TYPE=1
+4
View File
@@ -27,3 +27,7 @@ ADMIN_DEFAULT_USERS_JSON=[{"username":"admin","password":"change-me-admin-passwo
# 91Kaquan # 91Kaquan
KAQUAN91_USER_ID= KAQUAN91_USER_ID=
KAQUAN91_SECRET= KAQUAN91_SECRET=
# Cloudtentacles
CLOUDTENTACLES_DEVICE_ID=08bc9d8c-fd15-48ea-bc00-8d754076cafc
CLOUDTENTACLES_DEVICE_TYPE=1
@@ -9,8 +9,8 @@
"username": "", "username": "",
"password": "", "password": "",
"phone": "", "phone": "",
"deviceId": "-", "deviceId": "08bc9d8c-fd15-48ea-bc00-8d754076cafc",
"deviceType": 0 "deviceType": 1
} }
] ]
} }
+2 -2
View File
@@ -79,8 +79,8 @@ export function createDefaultRuntimeConfig(projectRoot: string): RuntimeConfig {
bindUrlProbeReferer: "https://gp.qq.com/", bindUrlProbeReferer: "https://gp.qq.com/",
bindUrlProbeExtraCookie: "", bindUrlProbeExtraCookie: "",
clientSource: "ct-client", clientSource: "ct-client",
deviceId: "-", deviceId: "08bc9d8c-fd15-48ea-bc00-8d754076cafc",
deviceType: 0, deviceType: 1,
publicKeyPem: `-----BEGIN PUBLIC KEY----- publicKeyPem: `-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsSzjk+9st2f8IpYqYaM5 MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsSzjk+9st2f8IpYqYaM5
F7K27ZR2IvzxTr2w4zgZAS2+BRdgMvXUOITdFQT+ytYF/r3pIgTkL7MF9UQuylmb F7K27ZR2IvzxTr2w4zgZAS2+BRdgMvXUOITdFQT+ytYF/r3pIgTkL7MF9UQuylmb
@@ -142,8 +142,8 @@ function createRuntimeConfig(): RuntimeConfig {
bindUrlProbeExtraCookie: '', bindUrlProbeExtraCookie: '',
publicKeyPem: '', publicKeyPem: '',
clientSource: 'ct-client', clientSource: 'ct-client',
deviceId: '-', deviceId: '08bc9d8c-fd15-48ea-bc00-8d754076cafc',
deviceType: 0, deviceType: 1,
}, },
}, },
} }
@@ -182,8 +182,8 @@ function createRuntimeConfig(overrides: Record<string, unknown> = {}): RuntimeCo
bindUrlProbeExtraCookie: '', bindUrlProbeExtraCookie: '',
publicKeyPem: '', publicKeyPem: '',
clientSource: 'ct-client', clientSource: 'ct-client',
deviceId: '-', deviceId: '08bc9d8c-fd15-48ea-bc00-8d754076cafc',
deviceType: 0, deviceType: 1,
}, },
}, },
}, overrides) as RuntimeConfig }, overrides) as RuntimeConfig
@@ -43,6 +43,10 @@ export function resolveKuaishouEticketAdminContext(payload: JsonObject = {}, opt
import { getCloudtentaclesSourceByKey } from "../../../platforms/cloudtentacles/source-config-service.js"; import { getCloudtentaclesSourceByKey } from "../../../platforms/cloudtentacles/source-config-service.js";
import { getCloudtentaclesSessionStateByKey } from "../../../platforms/cloudtentacles/session-state-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 = {}) { export function resolveCloudtentaclesAdminContext(payload: JsonObject = {}, options: JsonObject = {}) {
const sourceKey = String( const sourceKey = String(
@@ -63,16 +67,16 @@ export function resolveCloudtentaclesAdminContext(payload: JsonObject = {}, opti
defaultBaseUrl, defaultBaseUrl,
]), ]),
token: pickFirstNonEmpty([payload.token, persistedSession.token]), token: pickFirstNonEmpty([payload.token, persistedSession.token]),
deviceId: pickFirstNonEmpty([ deviceId: normalizeCloudtentaclesDeviceId(
payload.deviceId, pickFirstNonEmpty([
savedSource.deviceId, payload.deviceId,
persistedSession.deviceId, savedSource.deviceId,
"-", persistedSession.deviceId,
]), ])
deviceType: ),
payload.deviceType ?? deviceType: normalizeCloudtentaclesDeviceType(
savedSource.deviceType ?? payload.deviceType ?? savedSource.deviceType ?? persistedSession.deviceType
persistedSession.deviceType, ),
}; };
} }
@@ -2,6 +2,10 @@ import {
maskPhone as maskPhoneValue, maskPhone as maskPhoneValue,
maskSecret as maskSecretValue, maskSecret as maskSecretValue,
} from "../../../../utils/masking.js"; } from "../../../../utils/masking.js";
import {
normalizeCloudtentaclesDeviceId,
normalizeCloudtentaclesDeviceType,
} from "../../../platforms/cloudtentacles/defaults.js";
type JsonObject = Record<string, any> type JsonObject = Record<string, any>
@@ -42,8 +46,8 @@ export function mapAdminCloudtentaclesSourceConfig(config: JsonObject = {}) {
username: String(config.username || "").trim(), username: String(config.username || "").trim(),
password: String(config.password || "").trim(), password: String(config.password || "").trim(),
phone: String(config.phone || "").trim(), phone: String(config.phone || "").trim(),
deviceId: String(config.deviceId || "-").trim() || "-", deviceId: normalizeCloudtentaclesDeviceId(config.deviceId),
deviceType: Number(config.deviceType || 0), deviceType: normalizeCloudtentaclesDeviceType(config.deviceType),
}; };
} }
@@ -55,8 +59,8 @@ export function mapAdminCloudtentaclesSession(session: JsonObject = {}) {
username: String(session.username || "").trim(), username: String(session.username || "").trim(),
phoneMasked: maskPhone(session.phone), phoneMasked: maskPhone(session.phone),
loggedInAt: String(session.loggedInAt || "").trim(), loggedInAt: String(session.loggedInAt || "").trim(),
deviceId: String(session.deviceId || "-").trim() || "-", deviceId: normalizeCloudtentaclesDeviceId(session.deviceId),
deviceType: Number(session.deviceType || 0), deviceType: normalizeCloudtentaclesDeviceType(session.deviceType),
hasToken: Boolean(String(session.token || "").trim()), hasToken: Boolean(String(session.token || "").trim()),
}; };
} }
@@ -1,5 +1,9 @@
import { getCloudtentaclesSourceByKey } from "../../../platforms/cloudtentacles/source-config-service.js"; import { getCloudtentaclesSourceByKey } from "../../../platforms/cloudtentacles/source-config-service.js";
import { getCloudtentaclesSessionStateByKey } from "../../../platforms/cloudtentacles/session-state-service.js"; import { getCloudtentaclesSessionStateByKey } from "../../../platforms/cloudtentacles/session-state-service.js";
import {
normalizeCloudtentaclesDeviceId,
normalizeCloudtentaclesDeviceType,
} from "../../../platforms/cloudtentacles/defaults.js";
import { import {
pickFirstNonEmpty, pickFirstNonEmpty,
resolveCloudtentaclesAdminContext, resolveCloudtentaclesAdminContext,
@@ -34,8 +38,12 @@ export function resolveAdminCloudtentaclesCredentialPayload(
username: pickFirstNonEmpty([payload.username, savedSource.username]), username: pickFirstNonEmpty([payload.username, savedSource.username]),
password: pickFirstNonEmpty([payload.password, savedSource.password]), password: pickFirstNonEmpty([payload.password, savedSource.password]),
phone: pickFirstNonEmpty([payload.phone, savedSource.phone]), phone: pickFirstNonEmpty([payload.phone, savedSource.phone]),
deviceId: pickFirstNonEmpty([payload.deviceId, savedSource.deviceId, "-"]), deviceId: normalizeCloudtentaclesDeviceId(
deviceType: payload.deviceType ?? savedSource.deviceType, pickFirstNonEmpty([payload.deviceId, savedSource.deviceId])
),
deviceType: normalizeCloudtentaclesDeviceType(
payload.deviceType ?? savedSource.deviceType
),
}; };
} }
@@ -67,8 +75,12 @@ export function buildAdminCloudtentaclesPersistedSessionPayload(
username: pickFirstNonEmpty([options.username, session.username]), username: pickFirstNonEmpty([options.username, session.username]),
phone: pickFirstNonEmpty([options.phone, session.phone]), phone: pickFirstNonEmpty([options.phone, session.phone]),
loggedInAt: String(session.loggedInAt || "").trim(), loggedInAt: String(session.loggedInAt || "").trim(),
deviceId: pickFirstNonEmpty([options.deviceId, session.deviceId, "-"]), deviceId: normalizeCloudtentaclesDeviceId(
deviceType: options.deviceType ?? session.deviceType, 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>; type JsonObject = Record<string, any>;
export function normalizeAdminCloudtentaclesSourceConfigPayload( export function normalizeAdminCloudtentaclesSourceConfigPayload(
@@ -13,7 +18,7 @@ export function normalizeAdminCloudtentaclesSourceConfigPayload(
username: String(payload.username || "").trim(), username: String(payload.username || "").trim(),
password: String(payload.password || "").trim(), password: String(payload.password || "").trim(),
phone: String(payload.phone || "").trim(), phone: String(payload.phone || "").trim(),
deviceId: String(payload.deviceId || "-").trim() || "-", deviceId: normalizeCloudtentaclesDeviceId(payload.deviceId),
deviceType: Number(payload.deviceType || 0), deviceType: normalizeCloudtentaclesDeviceType(payload.deviceType),
}; };
} }
@@ -1,4 +1,8 @@
import { createHttpError } from "../../../utils/http.js"; import { createHttpError } from "../../../utils/http.js";
import {
normalizeCloudtentaclesDeviceId,
normalizeCloudtentaclesDeviceType,
} from "../../platforms/cloudtentacles/defaults.js";
import { getCloudtentaclesSourceByKey } from "../../platforms/cloudtentacles/source-config-service.js"; import { getCloudtentaclesSourceByKey } from "../../platforms/cloudtentacles/source-config-service.js";
import { getCloudtentaclesSessionStateByKey } from "../../platforms/cloudtentacles/session-state-service.js"; import { getCloudtentaclesSessionStateByKey } from "../../platforms/cloudtentacles/session-state-service.js";
import { normalizeStringArray } from "./domain.js"; import { normalizeStringArray } from "./domain.js";
@@ -53,9 +57,12 @@ export function resolvePersistedCloudtentaclesContextBySourceKeys(
String(session.baseUrl || source.baseUrl || "").trim() || String(session.baseUrl || source.baseUrl || "").trim() ||
"https://123.207.217.176", "https://123.207.217.176",
token, token,
deviceId: deviceId: normalizeCloudtentaclesDeviceId(
String(session.deviceId || source.deviceId || "-").trim() || "-", session.deviceId || source.deviceId
deviceType: Number(session.deviceType ?? source.deviceType ?? 0), ),
deviceType: normalizeCloudtentaclesDeviceType(
session.deviceType ?? source.deviceType
),
resolvedSourceKey: sourceKey, resolvedSourceKey: sourceKey,
}; };
} }
@@ -4,6 +4,10 @@ import {
import { import {
getCloudtentaclesSessionStateByKey, getCloudtentaclesSessionStateByKey,
} from '../platforms/cloudtentacles/session-state-service.js' } from '../platforms/cloudtentacles/session-state-service.js'
import {
normalizeCloudtentaclesDeviceId,
normalizeCloudtentaclesDeviceType,
} from '../platforms/cloudtentacles/defaults.js'
import { import {
listCloudtentaclesSku, listCloudtentaclesSku,
} from '../platforms/cloudtentacles/catalog-service.js' } from '../platforms/cloudtentacles/catalog-service.js'
@@ -167,8 +171,8 @@ function buildCloudtentaclesSourceContext(
sourceKey, sourceKey,
baseUrl: String(session?.baseUrl || source.baseUrl || '').trim(), baseUrl: String(session?.baseUrl || source.baseUrl || '').trim(),
token, token,
deviceId: String(session?.deviceId || source.deviceId || '-').trim() || '-', deviceId: normalizeCloudtentaclesDeviceId(session?.deviceId || source.deviceId),
deviceType: Number(session?.deviceType ?? source.deviceType ?? 0), 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 { runtimeConfig } from '../../../config/runtime.js'
import type { RuntimeConfig } from '../../../types/runtime-config.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 CloudtentaclesRuntimeConfig = RuntimeConfig['platforms']['cloudtentacles']
type JsonObject = Record<string, any> type JsonObject = Record<string, any>
@@ -40,8 +46,8 @@ export function resolveCloudtentaclesConfig(overrides: Partial<CloudtentaclesRun
bindUrlProbeExtraCookie: '', bindUrlProbeExtraCookie: '',
publicKeyPem: '', publicKeyPem: '',
clientSource: 'ct-client', clientSource: 'ct-client',
deviceId: '-', deviceId: DEFAULT_CLOUDTENTACLES_DEVICE_ID,
deviceType: 0, deviceType: DEFAULT_CLOUDTENTACLES_DEVICE_TYPE,
} }
return { return {
@@ -87,8 +93,8 @@ export function resolveCloudtentaclesConfig(overrides: Partial<CloudtentaclesRun
bindUrlProbeExtraCookie: String(overrides.bindUrlProbeExtraCookie || baseConfig.bindUrlProbeExtraCookie || '').trim(), bindUrlProbeExtraCookie: String(overrides.bindUrlProbeExtraCookie || baseConfig.bindUrlProbeExtraCookie || '').trim(),
publicKeyPem: normalizePem(overrides.publicKeyPem || baseConfig.publicKeyPem), publicKeyPem: normalizePem(overrides.publicKeyPem || baseConfig.publicKeyPem),
clientSource: String(overrides.clientSource || baseConfig.clientSource || 'ct-client').trim() || 'ct-client', clientSource: String(overrides.clientSource || baseConfig.clientSource || 'ct-client').trim() || 'ct-client',
deviceId: String(overrides.deviceId ?? baseConfig.deviceId ?? '-').trim() || '-', deviceId: normalizeCloudtentaclesDeviceId(overrides.deviceId ?? baseConfig.deviceId),
deviceType: normalizeInteger(overrides.deviceType ?? baseConfig.deviceType, 0), deviceType: normalizeCloudtentaclesDeviceType(overrides.deviceType ?? baseConfig.deviceType),
} }
} }
@@ -114,8 +120,8 @@ export function buildCloudtentaclesUrl(
export function buildCloudtentaclesHeaders({ export function buildCloudtentaclesHeaders({
token = '', token = '',
contentType = 'application/json', contentType = 'application/json',
deviceId = '-', deviceId = DEFAULT_CLOUDTENTACLES_DEVICE_ID,
deviceType = 0, deviceType = DEFAULT_CLOUDTENTACLES_DEVICE_TYPE,
extra = {}, extra = {},
}: { }: {
token?: unknown token?: unknown
@@ -127,8 +133,8 @@ export function buildCloudtentaclesHeaders({
const headers: JsonObject = { const headers: JsonObject = {
accept: 'application/json, text/plain, */*', accept: 'application/json, text/plain, */*',
...(contentType ? { 'content-type': contentType } : {}), ...(contentType ? { 'content-type': contentType } : {}),
deviceid: String(deviceId || '-').trim() || '-', deviceid: normalizeCloudtentaclesDeviceId(deviceId),
devicetype: String(Number(deviceType || 0)), devicetype: String(normalizeCloudtentaclesDeviceType(deviceType)),
...normalizeHeaderMap(extra), ...normalizeHeaderMap(extra),
} }
@@ -3,6 +3,12 @@ import path from 'node:path'
import { PROJECT_ROOT } from '../../../config/runtime.js' import { PROJECT_ROOT } from '../../../config/runtime.js'
import { createHttpError } from '../../../utils/http.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') 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(), username: String(source.username || '').trim(),
phone: String(source.phone || '').trim(), phone: String(source.phone || '').trim(),
loggedInAt: String(source.loggedInAt || '').trim(), loggedInAt: String(source.loggedInAt || '').trim(),
deviceId: String(source.deviceId || '-').trim() || '-', deviceId: normalizeCloudtentaclesDeviceId(source.deviceId),
deviceType: normalizeInteger(source.deviceType, 0), deviceType: normalizeCloudtentaclesDeviceType(source.deviceType),
} }
} }
@@ -203,8 +209,8 @@ function createDefaultCloudtentaclesSessionState() {
username: '', username: '',
phone: '', phone: '',
loggedInAt: '', loggedInAt: '',
deviceId: '-', deviceId: DEFAULT_CLOUDTENTACLES_DEVICE_ID,
deviceType: 0, 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 { function isPlainObject(value: unknown): value is JsonObject {
return Object.prototype.toString.call(value) === '[object Object]' 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 { PROJECT_ROOT } from '../../../config/runtime.js'
import { createHttpError } from '../../../utils/http.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') 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(), username: String(source.username || '').trim(),
password: String(source.password || '').trim(), password: String(source.password || '').trim(),
phone: String(source.phone || '').trim(), phone: String(source.phone || '').trim(),
deviceId: String(source.deviceId || '-').trim() || '-', deviceId: normalizeCloudtentaclesDeviceId(source.deviceId),
deviceType: normalizeInteger(source.deviceType, 0), 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 { function isPlainObject(value: unknown): value is JsonObject {
return Object.prototype.toString.call(value) === '[object Object]' return Object.prototype.toString.call(value) === '[object Object]'
} }
@@ -1,4 +1,8 @@
import { getCloudtentaclesAsset } from '../platforms/cloudtentacles/catalog-service.js' import { getCloudtentaclesAsset } from '../platforms/cloudtentacles/catalog-service.js'
import {
normalizeCloudtentaclesDeviceId,
normalizeCloudtentaclesDeviceType,
} from '../platforms/cloudtentacles/defaults.js'
import { import {
getCloudtentaclesSourceByKey, getCloudtentaclesSourceByKey,
listCloudtentaclesSources, listCloudtentaclesSources,
@@ -134,8 +138,8 @@ async function runCloudtentaclesHealthAccount(
accountLabel: label, accountLabel: label,
baseUrl: String(session.baseUrl || source.baseUrl || '').trim() || 'https://123.207.217.176', baseUrl: String(session.baseUrl || source.baseUrl || '').trim() || 'https://123.207.217.176',
token, token,
deviceId: String(session.deviceId || source.deviceId || '-').trim() || '-', deviceId: normalizeCloudtentaclesDeviceId(session.deviceId || source.deviceId),
deviceType: Number(session.deviceType ?? source.deviceType ?? 0), deviceType: normalizeCloudtentaclesDeviceType(session.deviceType ?? source.deviceType),
}) })
const asset = Number(assetResult.asset || 0) const asset = Number(assetResult.asset || 0)
@@ -261,12 +261,15 @@ const {
<el-form label-width="auto" label-position="top"> <el-form label-width="auto" label-position="top">
<div class="form-grid"> <div class="form-grid">
<el-form-item label="deviceId"> <el-form-item label="deviceId">
<el-input v-model="cloudtentaclesForm.deviceId" placeholder="默认 -" /> <el-input
v-model="cloudtentaclesForm.deviceId"
placeholder="默认 08bc9d8c-fd15-48ea-bc00-8d754076cafc"
/>
</el-form-item> </el-form-item>
<el-form-item label="deviceType"> <el-form-item label="deviceType">
<el-input-number <el-input-number
v-model="cloudtentaclesForm.deviceType" v-model="cloudtentaclesForm.deviceType"
:min="0" :min="1"
controls-position="right" controls-position="right"
class="w-full" class="w-full"
/> />
@@ -0,0 +1,13 @@
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
}
@@ -20,6 +20,12 @@ import type {
} from '@/types/admin' } from '@/types/admin'
import type { CloudtentaclesForm } from './useCloudtentaclesDebugActions' import type { CloudtentaclesForm } from './useCloudtentaclesDebugActions'
import {
DEFAULT_CLOUDTENTACLES_DEVICE_ID,
DEFAULT_CLOUDTENTACLES_DEVICE_TYPE,
normalizeCloudtentaclesDeviceId,
normalizeCloudtentaclesDeviceType,
} from './cloudtentaclesDefaults'
import { useCloudtentaclesDebugActions } from './useCloudtentaclesDebugActions' import { useCloudtentaclesDebugActions } from './useCloudtentaclesDebugActions'
export function useAdminCloudtentaclesPlatform() { export function useAdminCloudtentaclesPlatform() {
@@ -41,8 +47,8 @@ export function useAdminCloudtentaclesPlatform() {
vnId: 0, vnId: 0,
skuId: 5, skuId: 5,
skuCount: 1, skuCount: 1,
deviceId: '-', deviceId: DEFAULT_CLOUDTENTACLES_DEVICE_ID,
deviceType: 0, deviceType: DEFAULT_CLOUDTENTACLES_DEVICE_TYPE,
}) })
const cloudtentaclesSaving = ref(false) const cloudtentaclesSaving = ref(false)
const cloudtentaclesSendingSms = ref(false) const cloudtentaclesSendingSms = ref(false)
@@ -109,8 +115,8 @@ export function useAdminCloudtentaclesPlatform() {
username: '', username: '',
password: '', password: '',
phone: '', phone: '',
deviceId: '-', deviceId: DEFAULT_CLOUDTENTACLES_DEVICE_ID,
deviceType: 0, deviceType: DEFAULT_CLOUDTENTACLES_DEVICE_TYPE,
} satisfies AdminCloudtentaclesSourceItem } satisfies AdminCloudtentaclesSourceItem
} }
@@ -129,8 +135,8 @@ export function useAdminCloudtentaclesPlatform() {
source.username = cloudtentaclesForm.value.username.trim() source.username = cloudtentaclesForm.value.username.trim()
source.password = cloudtentaclesForm.value.password.trim() source.password = cloudtentaclesForm.value.password.trim()
source.phone = cloudtentaclesForm.value.phone.trim() source.phone = cloudtentaclesForm.value.phone.trim()
source.deviceId = cloudtentaclesForm.value.deviceId.trim() || '-' source.deviceId = normalizeCloudtentaclesDeviceId(cloudtentaclesForm.value.deviceId)
source.deviceType = Number(cloudtentaclesForm.value.deviceType || 0) source.deviceType = normalizeCloudtentaclesDeviceType(cloudtentaclesForm.value.deviceType)
} }
function selectFallbackSource(preferredKey = '') { function selectFallbackSource(preferredKey = '') {
@@ -170,8 +176,8 @@ export function useAdminCloudtentaclesPlatform() {
vnId: 0, vnId: 0,
skuId: 5, skuId: 5,
skuCount: 1, skuCount: 1,
deviceId: source.deviceId || '-', deviceId: normalizeCloudtentaclesDeviceId(source.deviceId),
deviceType: source.deviceType || 0, deviceType: normalizeCloudtentaclesDeviceType(source.deviceType),
} }
} }
cloudtentaclesPersistedSession.value = session || null cloudtentaclesPersistedSession.value = session || null
@@ -288,8 +294,8 @@ export function useAdminCloudtentaclesPlatform() {
username: cloudtentaclesForm.value.username.trim(), username: cloudtentaclesForm.value.username.trim(),
password: cloudtentaclesForm.value.password.trim(), password: cloudtentaclesForm.value.password.trim(),
phone: cloudtentaclesForm.value.phone.trim(), phone: cloudtentaclesForm.value.phone.trim(),
deviceId: cloudtentaclesForm.value.deviceId.trim() || '-', deviceId: normalizeCloudtentaclesDeviceId(cloudtentaclesForm.value.deviceId),
deviceType: Number(cloudtentaclesForm.value.deviceType || 0), deviceType: normalizeCloudtentaclesDeviceType(cloudtentaclesForm.value.deviceType),
sourceKey: selectedSourceKey.value, sourceKey: selectedSourceKey.value,
} }
} }
@@ -383,8 +389,8 @@ export function useAdminCloudtentaclesPlatform() {
username: response.data.username, username: response.data.username,
phoneMasked: response.data.phoneMasked, phoneMasked: response.data.phoneMasked,
loggedInAt: response.data.loggedInAt, loggedInAt: response.data.loggedInAt,
deviceId: cloudtentaclesForm.value.deviceId.trim() || '-', deviceId: normalizeCloudtentaclesDeviceId(cloudtentaclesForm.value.deviceId),
deviceType: Number(cloudtentaclesForm.value.deviceType || 0), deviceType: normalizeCloudtentaclesDeviceType(cloudtentaclesForm.value.deviceType),
hasToken: Boolean(response.data.token), hasToken: Boolean(response.data.token),
} }
// Update sessions map // Update sessions map
@@ -413,8 +419,8 @@ export function useAdminCloudtentaclesPlatform() {
const response = await validateAdminCloudtentaclesSession({ const response = await validateAdminCloudtentaclesSession({
baseUrl: cloudtentaclesForm.value.baseUrl.trim() || 'https://123.207.217.176', baseUrl: cloudtentaclesForm.value.baseUrl.trim() || 'https://123.207.217.176',
token, token,
deviceId: cloudtentaclesForm.value.deviceId.trim() || '-', deviceId: normalizeCloudtentaclesDeviceId(cloudtentaclesForm.value.deviceId),
deviceType: Number(cloudtentaclesForm.value.deviceType || 0), deviceType: normalizeCloudtentaclesDeviceType(cloudtentaclesForm.value.deviceType),
sourceKey: selectedSourceKey.value, sourceKey: selectedSourceKey.value,
}) })
cloudtentaclesValidateResult.value = response.data cloudtentaclesValidateResult.value = response.data
@@ -427,8 +433,8 @@ export function useAdminCloudtentaclesPlatform() {
cloudtentaclesForm.value.username.trim(), cloudtentaclesForm.value.username.trim(),
phoneMasked: cloudtentaclesPersistedSession.value?.phoneMasked || '', phoneMasked: cloudtentaclesPersistedSession.value?.phoneMasked || '',
loggedInAt: response.data.loggedInAt, loggedInAt: response.data.loggedInAt,
deviceId: cloudtentaclesForm.value.deviceId.trim() || '-', deviceId: normalizeCloudtentaclesDeviceId(cloudtentaclesForm.value.deviceId),
deviceType: Number(cloudtentaclesForm.value.deviceType || 0), deviceType: normalizeCloudtentaclesDeviceType(cloudtentaclesForm.value.deviceType),
hasToken: Boolean(token), hasToken: Boolean(token),
} }
// Update sessions map // Update sessions map
@@ -17,6 +17,11 @@ import {
verifyAdminCloudtentaclesVnCode, verifyAdminCloudtentaclesVnCode,
} from '@/services/admin' } from '@/services/admin'
import {
normalizeCloudtentaclesDeviceId,
normalizeCloudtentaclesDeviceType,
} from './cloudtentaclesDefaults'
export type CloudtentaclesForm = { export type CloudtentaclesForm = {
baseUrl: string baseUrl: string
username: string username: string
@@ -44,8 +49,8 @@ export function useCloudtentaclesDebugActions(
return { return {
baseUrl: cloudtentaclesForm.value.baseUrl.trim() || 'https://123.207.217.176', baseUrl: cloudtentaclesForm.value.baseUrl.trim() || 'https://123.207.217.176',
token: cloudtentaclesForm.value.token.trim(), token: cloudtentaclesForm.value.token.trim(),
deviceId: cloudtentaclesForm.value.deviceId.trim() || '-', deviceId: normalizeCloudtentaclesDeviceId(cloudtentaclesForm.value.deviceId),
deviceType: Number(cloudtentaclesForm.value.deviceType || 0), deviceType: normalizeCloudtentaclesDeviceType(cloudtentaclesForm.value.deviceType),
sourceKey: selectedSourceKey.value, sourceKey: selectedSourceKey.value,
} }
} }