
* wip * Update read-announcement.ts * wip * wip * wip * Update index.d.ts * wip * Create 1691649257651-refine-announcement.js * wip * wip * wip * wip * wip * wip * Update announcements.vue * wip * wip * Update announcements.vue * wip * Update announcements.vue * wip * Update misskey-js.api.md * Update users.ts * Create MkAnnouncementDialog.stories.impl.ts * wip * wip * Create AnnouncementService.ts
90 lines
2.3 KiB
TypeScript
90 lines
2.3 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import { Injectable } from '@nestjs/common';
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
import { AnnouncementService } from '@/core/AnnouncementService.js';
|
|
|
|
export const meta = {
|
|
tags: ['admin'],
|
|
|
|
requireCredential: true,
|
|
requireModerator: true,
|
|
|
|
res: {
|
|
type: 'object',
|
|
optional: false, nullable: false,
|
|
properties: {
|
|
id: {
|
|
type: 'string',
|
|
optional: false, nullable: false,
|
|
format: 'id',
|
|
example: 'xxxxxxxxxx',
|
|
},
|
|
createdAt: {
|
|
type: 'string',
|
|
optional: false, nullable: false,
|
|
format: 'date-time',
|
|
},
|
|
updatedAt: {
|
|
type: 'string',
|
|
optional: false, nullable: true,
|
|
format: 'date-time',
|
|
},
|
|
title: {
|
|
type: 'string',
|
|
optional: false, nullable: false,
|
|
},
|
|
text: {
|
|
type: 'string',
|
|
optional: false, nullable: false,
|
|
},
|
|
imageUrl: {
|
|
type: 'string',
|
|
optional: false, nullable: true,
|
|
},
|
|
},
|
|
},
|
|
} as const;
|
|
|
|
export const paramDef = {
|
|
type: 'object',
|
|
properties: {
|
|
title: { type: 'string', minLength: 1 },
|
|
text: { type: 'string', minLength: 1 },
|
|
imageUrl: { type: 'string', nullable: true, minLength: 1 },
|
|
icon: { type: 'string', enum: ['info', 'warning', 'error', 'success'], default: 'info' },
|
|
display: { type: 'string', enum: ['normal', 'banner', 'dialog'], default: 'normal' },
|
|
forExistingUsers: { type: 'boolean', default: false },
|
|
needConfirmationToRead: { type: 'boolean', default: false },
|
|
userId: { type: 'string', format: 'misskey:id', nullable: true, default: null },
|
|
},
|
|
required: ['title', 'text', 'imageUrl'],
|
|
} as const;
|
|
|
|
// eslint-disable-next-line import/no-default-export
|
|
@Injectable()
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|
constructor(
|
|
private announcementService: AnnouncementService,
|
|
) {
|
|
super(meta, paramDef, async (ps, me) => {
|
|
const { raw, packed } = await this.announcementService.create({
|
|
createdAt: new Date(),
|
|
updatedAt: null,
|
|
title: ps.title,
|
|
text: ps.text,
|
|
imageUrl: ps.imageUrl,
|
|
icon: ps.icon,
|
|
display: ps.display,
|
|
forExistingUsers: ps.forExistingUsers,
|
|
needConfirmationToRead: ps.needConfirmationToRead,
|
|
userId: ps.userId,
|
|
});
|
|
|
|
return packed;
|
|
});
|
|
}
|
|
}
|