Add process view
This commit is contained in:
@@ -57,6 +57,69 @@ export function validateMethodArgs(method, args = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
case 'listProcesses': {
|
||||
const sort = String(args.sort || 'cpu').toLowerCase()
|
||||
const allowedSort = [
|
||||
'cpu',
|
||||
'rss',
|
||||
'pid',
|
||||
'name',
|
||||
'io',
|
||||
'threads',
|
||||
'age',
|
||||
'fds',
|
||||
'state',
|
||||
]
|
||||
if (!allowedSort.includes(sort)) {
|
||||
return { ok: false, error: `sort must be ${allowedSort.join('|')}` }
|
||||
}
|
||||
const order = String(args.order || 'desc').toLowerCase() === 'asc' ? 'asc' : 'desc'
|
||||
const filter = String(args.filter || 'all').toLowerCase()
|
||||
const allowedFilter = [
|
||||
'all',
|
||||
'running',
|
||||
'sleeping',
|
||||
'zombie',
|
||||
'stopped',
|
||||
'highcpu',
|
||||
'highmem',
|
||||
'hasio',
|
||||
'kernel',
|
||||
'user',
|
||||
]
|
||||
if (!allowedFilter.includes(filter)) {
|
||||
return { ok: false, error: `filter must be ${allowedFilter.join('|')}` }
|
||||
}
|
||||
const limit = args.limit == null ? 250 : Number(args.limit)
|
||||
if (!Number.isFinite(limit) || limit < 1 || limit > 2000) {
|
||||
return { ok: false, error: 'limit must be 1..2000' }
|
||||
}
|
||||
const offset = args.offset == null ? 0 : Number(args.offset)
|
||||
if (!Number.isFinite(offset) || offset < 0) {
|
||||
return { ok: false, error: 'offset must be ≥ 0' }
|
||||
}
|
||||
const pid =
|
||||
args.pid == null || args.pid === ''
|
||||
? null
|
||||
: Number(args.pid)
|
||||
if (pid != null && (!Number.isFinite(pid) || pid < 1)) {
|
||||
return { ok: false, error: 'pid must be a positive number' }
|
||||
}
|
||||
return {
|
||||
ok: true,
|
||||
args: {
|
||||
...args,
|
||||
sort,
|
||||
order,
|
||||
filter,
|
||||
limit: Math.floor(limit),
|
||||
offset: Math.floor(offset),
|
||||
q: args.q != null ? String(args.q) : '',
|
||||
pid,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
case 'setDisplayName': {
|
||||
const name = String(args.name ?? '').trim()
|
||||
if (!name) return { ok: false, error: 'name is required' }
|
||||
|
||||
Reference in New Issue
Block a user