Sharkey/packages/backend/src/server/api/endpoints/admin/queue/inbox-delayed.ts

57 lines
1 KiB
TypeScript
Raw Normal View History

import { URL } from 'url';
import define from '../../../define';
2021-09-23 16:32:16 +03:00
import { inboxQueue } from '@/queue/queues';
export const meta = {
tags: ['admin'],
2020-02-15 14:33:32 +02:00
requireCredential: true as const,
requireModerator: true,
params: {
},
res: {
type: 'array' as const,
optional: false as const, nullable: false as const,
items: {
type: 'array' as const,
optional: false as const, nullable: false as const,
items: {
anyOf: [
{
type: 'string' as const,
},
{
type: 'number' as const,
2021-12-09 16:58:30 +02:00
},
],
},
},
example: [[
'example.com',
2021-12-09 16:58:30 +02:00
12,
]],
},
};
2022-01-02 19:12:50 +02:00
// eslint-disable-next-line import/no-default-export
export default define(meta, async (ps) => {
const jobs = await inboxQueue.getJobs(['delayed']);
const res = [] as [string, number][];
for (const job of jobs) {
const host = new URL(job.data.signature.keyId).host;
if (res.find(x => x[0] === host)) {
res.find(x => x[0] === host)![1]++;
} else {
res.push([host, 1]);
}
}
res.sort((a, b) => b[1] - a[1]);
return res;
});