2023-07-27 07:31:52 +02:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
2022-09-20 22:33:11 +02:00
|
|
|
import type { WebhooksRepository } from '@/models/index.js';
|
2022-09-17 20:27:08 +02:00
|
|
|
import { GlobalEventService } from '@/core/GlobalEventService.js';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2022-04-02 08:28:49 +02:00
|
|
|
import { ApiError } from '../../../error.js';
|
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['webhooks'],
|
|
|
|
|
|
|
|
requireCredential: true,
|
|
|
|
|
|
|
|
kind: 'write:account',
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchWebhook: {
|
|
|
|
message: 'No such webhook.',
|
|
|
|
code: 'NO_SUCH_WEBHOOK',
|
|
|
|
id: 'bae73e5a-5522-4965-ae19-3a8688e71d82',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
} as const;
|
|
|
|
|
|
|
|
export const paramDef = {
|
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
webhookId: { type: 'string', format: 'misskey:id' },
|
|
|
|
},
|
|
|
|
required: ['webhookId'],
|
|
|
|
} as const;
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
// TODO: ロジックをサービスに切り出す
|
|
|
|
|
|
|
|
@Injectable()
|
2023-08-17 14:20:58 +02:00
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
|
2022-09-17 20:27:08 +02:00
|
|
|
constructor(
|
|
|
|
@Inject(DI.webhooksRepository)
|
|
|
|
private webhooksRepository: WebhooksRepository,
|
|
|
|
|
|
|
|
private globalEventService: GlobalEventService,
|
|
|
|
) {
|
|
|
|
super(meta, paramDef, async (ps, me) => {
|
|
|
|
const webhook = await this.webhooksRepository.findOneBy({
|
|
|
|
id: ps.webhookId,
|
|
|
|
userId: me.id,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (webhook == null) {
|
|
|
|
throw new ApiError(meta.errors.noSuchWebhook);
|
|
|
|
}
|
|
|
|
|
|
|
|
await this.webhooksRepository.delete(webhook.id);
|
|
|
|
|
|
|
|
this.globalEventService.publishInternalEvent('webhookDeleted', webhook);
|
|
|
|
});
|
2022-04-02 08:28:49 +02:00
|
|
|
}
|
2022-09-17 20:27:08 +02:00
|
|
|
}
|