feat(user): 新增 online-kick 命令 (admin/self 强制下线)
This commit is contained in:
1 parent
c275391ced
commit
67e41a40fa
2 files changed
+47
-7
No files matched your search
@@ -1,16 +1,51 @@
|
||||
/**
|
||||
* commands/user/online-kick.ts — 占位, Task 13 实现
|
||||
* commands/user/online-kick.ts — admin/self 踢下线某 token
|
||||
*
|
||||
* API: DELETE /api/system/OnlineUser/{token}
|
||||
*
|
||||
* web 端触发:
|
||||
* - 个人中心 Account/index.vue: handleExit(token) — 自己退出其他设备
|
||||
* - 在线用户 monitor/userOnline/index.vue — admin 强制下线
|
||||
*/
|
||||
import { Command } from 'commander'
|
||||
import { log } from '../../core/log.ts'
|
||||
import { JnpfClient } from '../../core/client.ts'
|
||||
import { installAiHelpHook } from '../../core/help.ts'
|
||||
import { log } from '../../core/log.ts'
|
||||
|
||||
interface OnlineKickOpts {
|
||||
token: string
|
||||
}
|
||||
|
||||
export function buildUserOnlineKickCommand(): Command {
|
||||
const cmd = new Command('online-kick').description('TODO: implement in Task 13')
|
||||
cmd.action(async () => {
|
||||
log.warn('TODO: implement in Task 13')
|
||||
process.exit(1)
|
||||
const cmd = new Command('online-kick')
|
||||
.description('强制下线某 token (admin/self 操作)')
|
||||
.requiredOption('--token <t>', '要踢的 token (从 onlineUser 列表获取)')
|
||||
.action(async (opts: OnlineKickOpts) => {
|
||||
const c = await JnpfClient.fromToken()
|
||||
// 防自踢: 当前登录 token 不能踢自己
|
||||
if (opts.token === c.getCurrentToken()) {
|
||||
log.error('不能踢自己下线 (当前登录 token), 会立即断连')
|
||||
process.exit(1)
|
||||
}
|
||||
const r = await c.del(`/system/OnlineUser/${opts.token}`)
|
||||
if (r.code !== 200) {
|
||||
log.error(`online-kick 失败 (code=${r.code}): ${r.msg}`)
|
||||
process.exit(1)
|
||||
}
|
||||
log.info(`✓ token=${opts.token.slice(0, 8)}... 已踢下线`)
|
||||
})
|
||||
installAiHelpHook(cmd, {
|
||||
purpose: '强制下线某 token (admin/self 操作, 防自踢)',
|
||||
required: { '--token': '要踢的 token (从 onlineUser 列表获取)' },
|
||||
example: 'dacli user online-kick --token=eyJhbGciOi...',
|
||||
source: {
|
||||
web: 'web/apps/jnpf-web-apps-main/src/views/_core/profile/components/Account/index.vue',
|
||||
api: 'DELETE /api/system/OnlineUser/{token}',
|
||||
},
|
||||
notes: [
|
||||
'**防自踢**: 当前登录 token 触发时拒绝 + exit(1)',
|
||||
'**admin 用**: 配合 `dacli monitor online-user list --token=...` 查 token',
|
||||
],
|
||||
})
|
||||
installAiHelpHook(cmd, { purpose: 'TODO' })
|
||||
return cmd
|
||||
}
|
||||
@@ -129,6 +129,11 @@ export class JnpfClient {
|
||||
saveToken(t)
|
||||
}
|
||||
|
||||
/** 当前登录 token (供 online-kick 等需防自踢/防自调的子命令读) */
|
||||
getCurrentToken(): string | undefined {
|
||||
return this.token || undefined
|
||||
}
|
||||
|
||||
// ----- HTTP -----
|
||||
|
||||
async get<T = unknown>(path: string, query?: Record<string, string | number | undefined>): Promise<JnpfResp<T>> {
|
||||
|
||||
Reference in new issue
Block a user