feat(shell): add uix svc

This commit is contained in:
Il Harper 2024-03-05 19:04:14 +08:00
parent 93aa0b9bcb
commit fd187e84b3
No known key found for this signature in database
GPG Key ID: 4B71FCA698E7E8EC
3 changed files with 41 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import type { ChronocatLogCurrentConfig } from './services/config/configEntity'
import { emitter } from './services/emitter' import { emitter } from './services/emitter'
import { l } from './services/logger' import { l } from './services/logger'
import { getSelfProfile, setSelfProfile } from './services/selfProfile' import { getSelfProfile, setSelfProfile } from './services/selfProfile'
import { uix } from './services/uix'
import { validate } from './services/validate' import { validate } from './services/validate'
import type { ChronocatContext, Engine } from './types' import type { ChronocatContext, Engine } from './types'
import { PLATFORM } from './utils/consts' import { PLATFORM } from './utils/consts'
@ -39,6 +40,7 @@ export const chronocat = async () => {
getSelfProfile, getSelfProfile,
l, l,
platform: PLATFORM, platform: PLATFORM,
uix,
validate, validate,
whenReady: () => readyPromise, whenReady: () => readyPromise,
}, },

View File

@ -0,0 +1,37 @@
const uinRegex = /\d+/
const isUin = (uin: unknown) => typeof uin === 'string' && uinRegex.test(uin)
const isUid = (uid: unknown) =>
typeof uid === 'string' && uid.length === 24 && uid.startsWith('u_')
const map: Record<string, string> = {}
const add = (uid: string, uin: string) => {
if (!uid || !uin) return
map[uid] = uin
map[uin] = uid
}
const getUin = (uid: string) => {
if (!isUid(uid)) return undefined
const uin = map[uid]
if (!isUin(uin)) return undefined
return uin
}
const getUid = (uin: string) => {
if (!isUin(uin)) return undefined
const uid = map[uin]
if (!isUid(uid)) return undefined
return uid
}
export const uix = {
map,
add,
isUin,
isUid,
getUin,
getUid,
}

View File

@ -10,6 +10,7 @@ import type {
} from './services/config/configEntity' } from './services/config/configEntity'
import type { l } from './services/logger' import type { l } from './services/logger'
import type { getSelfProfile } from './services/selfProfile' import type { getSelfProfile } from './services/selfProfile'
import type { uix } from './services/uix'
import type { validate } from './services/validate' import type { validate } from './services/validate'
import type { PLATFORM } from './utils/consts' import type { PLATFORM } from './utils/consts'
@ -23,6 +24,7 @@ export interface ChronocatContext {
getSelfProfile: typeof getSelfProfile getSelfProfile: typeof getSelfProfile
l: typeof l l: typeof l
platform: typeof PLATFORM platform: typeof PLATFORM
uix: typeof uix
validate: typeof validate validate: typeof validate
whenReady: () => Promise<void> whenReady: () => Promise<void>
} }