1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { SystemWebhookEntityService } from '@/core/entities/SystemWebhookEntityService.js';
import { systemWebhookEventTypes } from '@/models/SystemWebhook.js';
import { SystemWebhookService } from '@/core/SystemWebhookService.js';
export const meta = {
tags: ['admin', 'system-webhook'],
requireCredential: true,
requireModerator: true,
secure: true,
kind: 'write:admin:system-webhook',
res: {
type: 'object',
ref: 'SystemWebhook',
},
} as const;
export const paramDef = {
type: 'object',
properties: {
isActive: {
type: 'boolean',
},
name: {
type: 'string',
minLength: 1,
maxLength: 255,
},
on: {
type: 'array',
items: {
type: 'string',
enum: systemWebhookEventTypes,
},
},
url: {
type: 'string',
minLength: 1,
maxLength: 1024,
},
secret: {
type: 'string',
minLength: 1,
maxLength: 1024,
},
},
required: [
'isActive',
'name',
'on',
'url',
'secret',
],
} as const;
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
constructor(
private systemWebhookService: SystemWebhookService,
private systemWebhookEntityService: SystemWebhookEntityService,
) {
super(meta, paramDef, async (ps, me) => {
const result = await this.systemWebhookService.createSystemWebhook(
{
isActive: ps.isActive,
name: ps.name,
on: ps.on,
url: ps.url,
secret: ps.secret,
},
me,
);
return this.systemWebhookEntityService.pack(result);
});
}
}
|