抽离后台平台配置共享映射逻辑
This commit is contained in:
@@ -0,0 +1,151 @@
|
||||
// @ts-check
|
||||
|
||||
export function maskSecret(value) {
|
||||
const normalized = String(value || '').trim()
|
||||
if (!normalized) {
|
||||
return ''
|
||||
}
|
||||
|
||||
if (normalized.length <= 10) {
|
||||
return `${normalized.slice(0, 2)}****${normalized.slice(-2)}`
|
||||
}
|
||||
|
||||
return `${normalized.slice(0, 6)}****${normalized.slice(-6)}`
|
||||
}
|
||||
|
||||
export function maskPhone(value) {
|
||||
const normalized = String(value || '').trim()
|
||||
if (!normalized) {
|
||||
return ''
|
||||
}
|
||||
|
||||
if (normalized.length < 7) {
|
||||
return normalized
|
||||
}
|
||||
|
||||
return `${normalized.slice(0, 3)}****${normalized.slice(-4)}`
|
||||
}
|
||||
|
||||
export function mapAdminKhhaoSourceConfig(config = {}) {
|
||||
return {
|
||||
enabled: config.enabled !== false,
|
||||
baseUrl: String(config.baseUrl || '').trim(),
|
||||
username: String(config.username || '').trim(),
|
||||
password: String(config.password || '').trim(),
|
||||
maxCaptchaAttempts: Number(config.maxCaptchaAttempts || 3) || 3,
|
||||
autoSync: {
|
||||
enabled: config.autoSync?.enabled === true,
|
||||
intervalMinutes: Number(config.autoSync?.intervalMinutes || 3) || 3,
|
||||
pages: Number(config.autoSync?.pages || 2) || 2,
|
||||
pageSize: Number(config.autoSync?.pageSize || 20) || 20,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export function mapAdminKhhaoSyncState(syncState = {}) {
|
||||
return {
|
||||
syncFromCreatedAt: String(syncState.syncFromCreatedAt || '').trim(),
|
||||
lastRunStartedAt: String(syncState.lastRunStartedAt || '').trim(),
|
||||
lastRunFinishedAt: String(syncState.lastRunFinishedAt || '').trim(),
|
||||
lastRunStatus: String(syncState.lastRunStatus || '').trim(),
|
||||
lastErrorMessage: String(syncState.lastErrorMessage || '').trim(),
|
||||
fetchedCount: Number(syncState.fetchedCount || 0),
|
||||
syncedCount: Number(syncState.syncedCount || 0),
|
||||
ignoredCount: Number(syncState.ignoredCount || 0),
|
||||
watchMode: String(syncState.watchMode || 'normal').trim() || 'normal',
|
||||
watchOrders: Array.isArray(syncState.watchOrders)
|
||||
? syncState.watchOrders.map((item) => ({
|
||||
platformOrderId: String(item?.platformOrderId || '').trim(),
|
||||
shopId: String(item?.shopId || '').trim(),
|
||||
shopName: String(item?.shopName || '').trim(),
|
||||
itemTitle: String(item?.itemTitle || '').trim(),
|
||||
payStatus: String(item?.payStatus || '').trim(),
|
||||
detectedAt: String(item?.detectedAt || '').trim(),
|
||||
lastSeenAt: String(item?.lastSeenAt || '').trim(),
|
||||
}))
|
||||
: [],
|
||||
}
|
||||
}
|
||||
|
||||
export function mapAdminKuaishouEticketShopItem(item = {}) {
|
||||
return {
|
||||
shopId: String(item.shopId || '').trim(),
|
||||
kshopName: String(item.kshopName || '').trim(),
|
||||
cookie: String(item.cookie || '').trim(),
|
||||
cookieMasked: maskSecret(item.cookie),
|
||||
hasCookie: Boolean(String(item.cookie || '').trim()),
|
||||
userAvatar: String(item.userAvatar || '').trim(),
|
||||
enabled: item.enabled !== false,
|
||||
}
|
||||
}
|
||||
|
||||
export function mapAdminKuaishouEticketSourceConfig(config = {}, shops = []) {
|
||||
return {
|
||||
enabled: config.enabled !== false,
|
||||
baseUrl: String(config.baseUrl || '').trim(),
|
||||
shops: shops.map((item) => mapAdminKuaishouEticketShopItem(item)),
|
||||
}
|
||||
}
|
||||
|
||||
export function mapAdminCloudtentaclesSourceConfig(config = {}) {
|
||||
return {
|
||||
enabled: config.enabled !== false,
|
||||
baseUrl: String(config.baseUrl || '').trim(),
|
||||
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),
|
||||
}
|
||||
}
|
||||
|
||||
export function mapAdminCloudtentaclesSession(session = {}) {
|
||||
return {
|
||||
token: String(session.token || '').trim(),
|
||||
tokenMasked: maskSecret(session.token),
|
||||
baseUrl: String(session.baseUrl || '').trim(),
|
||||
username: String(session.username || '').trim(),
|
||||
phoneMasked: maskPhone(session.phone),
|
||||
loggedInAt: String(session.loggedInAt || '').trim(),
|
||||
deviceId: String(session.deviceId || '-').trim() || '-',
|
||||
deviceType: Number(session.deviceType || 0),
|
||||
hasToken: Boolean(String(session.token || '').trim()),
|
||||
}
|
||||
}
|
||||
|
||||
export function mapAdminKuaishouCloudFulfillmentItem(item = {}) {
|
||||
return {
|
||||
id: String(item.id || '').trim(),
|
||||
enabled: item.enabled !== false,
|
||||
priority: Number(item.priority || 100) || 100,
|
||||
provider: String(item.provider || 'khhao').trim() || 'khhao',
|
||||
platform: String(item.platform || 'kuaishou').trim() || 'kuaishou',
|
||||
shopId: String(item.shopId || '').trim(),
|
||||
internalSkuCode: String(item.internalSkuCode || '').trim(),
|
||||
internalSkuName: String(item.internalSkuName || '').trim(),
|
||||
externalSkuCode: String(item.externalSkuCode || '').trim(),
|
||||
externalItemId: String(item.externalItemId || '').trim(),
|
||||
externalSkuName: String(item.externalSkuName || '').trim(),
|
||||
resolvedSkuName: String(item.resolvedSkuName || '').trim(),
|
||||
cloudSourceKey: String(item.cloudSourceKey || 'default').trim() || 'default',
|
||||
cloudSkuId: Number(item.cloudSkuId || 0) || 0,
|
||||
cloudSkuName: String(item.cloudSkuName || '').trim(),
|
||||
vnKey: String(item.vnKey || '').trim(),
|
||||
autoBuyEnabled: item.autoBuyEnabled !== false,
|
||||
minAssetReserve: Number(item.minAssetReserve || 0) || 0,
|
||||
autoReturnNumberAfterDispatch: item.autoReturnNumberAfterDispatch === true,
|
||||
autoConsumeAfterDispatch: item.autoConsumeAfterDispatch === true,
|
||||
kuaishouConsumeShopId: String(item.kuaishouConsumeShopId || '').trim(),
|
||||
kuaishouConsumeShopName: String(item.kuaishouConsumeShopName || '').trim(),
|
||||
notes: String(item.notes || '').trim(),
|
||||
}
|
||||
}
|
||||
|
||||
export function mapAdminKuaishouCloudFulfillmentSource(config = {}) {
|
||||
return {
|
||||
enabled: config.enabled !== false,
|
||||
items: (Array.isArray(config.items) ? config.items : []).map((item) =>
|
||||
mapAdminKuaishouCloudFulfillmentItem(item),
|
||||
),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user