Skip to content

Commit

Permalink
feat(api): implement login.get
Browse files Browse the repository at this point in the history
  • Loading branch information
ilharp committed Mar 7, 2024
1 parent 3c7c3e1 commit 0b9e697
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
18 changes: 18 additions & 0 deletions packages/engine-chronocat-api/src/api/login/get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { ChronocatContext, Login } from '@chronocat/shell'
import { LoginStatus } from '@chronocat/shell'

export const buildLoginGet = (ctx: ChronocatContext) => async () => {
const authData = await ctx.chronocat.getAuthData()

const result: Login = {
user: {
id: authData.uin,
avatar: `http://thirdqq.qlogo.cn/headimg_dl?dst_uin=${authData.uin}&spec=640`,
},
self_id: authData.uin,
platform: ctx.chronocat.platform,
status: LoginStatus.ONLINE,
}

return result
}
2 changes: 2 additions & 0 deletions packages/engine-chronocat-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { ChronocatContext } from '@chronocat/shell'
import { ipcMan } from 'ipcman'
import { buildAssetsGet } from './api/internal/assets/get'
import { qfaceGet, qfaceList } from './api/internal/qface'
import { buildLoginGet } from './api/login/get'
import { buildMessageCreate } from './api/message/create'
import { buildHandler } from './handler'

Expand All @@ -20,6 +21,7 @@ export const apply = async (ctx: ChronocatContext) => {
const register = ctx.chronocat.api.register(name)
register('chronocat.internal.assets.get', buildAssetsGet(ctx))
register('message.create', buildMessageCreate(ctx))
register('login.get', buildLoginGet(ctx))
register('chronocat.internal.message.create.forward', buildMessageCreate(ctx))

await ctx.chronocat.whenReady()
Expand Down
4 changes: 4 additions & 0 deletions packages/shell/src/satori/routes/login/get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import type { RouteContext } from '../types'

export const loginGet = ({ cctx }: RouteContext) =>
cctx.chronocat.api['login.get']()
9 changes: 8 additions & 1 deletion packages/shell/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import type { QFace, RedMessage } from '@chronocat/red'
import type h from '@satorijs/element'
import type styles from 'ansi-styles'
import type { O } from 'ts-toolbelt'
import type { Event, Message, MessageCreatePayload } from './satori/types'
import type {
Event,
Login,
Message,
MessageCreatePayload,
} from './satori/types'
import type { api } from './services/api'
import type { getAuthData } from './services/authData'
import type { baseDir } from './services/baseDir'
Expand Down Expand Up @@ -74,6 +79,8 @@ export interface Methods {
Message[],
]

'login.get': [[], Login]

// Internal

'chronocat.internal.notimpl': [[], never]
Expand Down

0 comments on commit 0b9e697

Please sign in to comment.