fix: maybe there was some problem
This commit is contained in:
parent
7e7e06ccac
commit
4bd35d3390
3 changed files with 37 additions and 16 deletions
|
@ -3,7 +3,7 @@
|
|||
* @author Xeltica
|
||||
*/
|
||||
|
||||
import { BadRequestError, Body, CurrentUser, Delete, Get, JsonController, NotFoundError, OnUndefined, Param, Post, Put } from 'routing-controllers';
|
||||
import { BadRequestError, ForbiddenError, Body, CurrentUser, Delete, Get, JsonController, NotFoundError, OnUndefined, Param, Post, Put } from 'routing-controllers';
|
||||
import { IUser } from '../../common/types/user.js';
|
||||
import { Announcements } from '../models/index.js';
|
||||
import { AnnounceCreate } from './body/announce-create.js';
|
||||
|
@ -22,7 +22,7 @@ export class AnnouncementController {
|
|||
@OnUndefined(204)
|
||||
@Post() async post(@CurrentUser({ required: true }) user: IUser, @Body({required: true}) {title, body}: AnnounceCreate) {
|
||||
if (!user.isAdmin) {
|
||||
throw new BadRequestError('Not an Admin');
|
||||
throw new ForbiddenError('Not an Admin');
|
||||
}
|
||||
if (!title || !body) {
|
||||
throw new BadRequestError();
|
||||
|
@ -37,12 +37,19 @@ export class AnnouncementController {
|
|||
@OnUndefined(204)
|
||||
@Put() async update(@CurrentUser({ required: true }) user: IUser, @Body() {id, title, body}: AnnounceUpdate) {
|
||||
if (!user.isAdmin) {
|
||||
throw new BadRequestError('Not an Admin');
|
||||
throw new ForbiddenError('Not an Admin');
|
||||
}
|
||||
|
||||
if (!id || !title || !body) {
|
||||
throw new BadRequestError();
|
||||
}
|
||||
if (!(await Announcements.findOne(id))) {
|
||||
|
||||
const idNumber = Number(id);
|
||||
if (isNaN(idNumber)) {
|
||||
throw new BadRequestError();
|
||||
}
|
||||
|
||||
if (!(await Announcements.findOne(idNumber))) {
|
||||
throw new NotFoundError();
|
||||
}
|
||||
|
||||
|
@ -55,18 +62,19 @@ export class AnnouncementController {
|
|||
@OnUndefined(204)
|
||||
@Post('/like/:id') async like(@CurrentUser({ required: true }) user: IUser, @Param('id') id: string) {
|
||||
if (!user.isAdmin) {
|
||||
throw new BadRequestError('Not an Admin');
|
||||
}
|
||||
const idNumber = Number(id);
|
||||
if (isNaN(idNumber)) {
|
||||
throw new NotFoundError();
|
||||
throw new ForbiddenError('Not an Admin');
|
||||
}
|
||||
|
||||
if (!id) {
|
||||
throw new BadRequestError();
|
||||
}
|
||||
|
||||
const announcement = await Announcements.findOne(Number(idNumber));
|
||||
const idNumber = Number(id);
|
||||
if (isNaN(idNumber)) {
|
||||
throw new BadRequestError();
|
||||
}
|
||||
|
||||
const announcement = await Announcements.findOne(idNumber);
|
||||
if (!announcement) {
|
||||
throw new NotFoundError();
|
||||
}
|
||||
|
@ -80,20 +88,34 @@ export class AnnouncementController {
|
|||
|
||||
@Delete() async delete(@CurrentUser({ required: true }) user: IUser, @Body() {id}: IdProp) {
|
||||
if (!user.isAdmin) {
|
||||
throw new BadRequestError('Not an Admin');
|
||||
throw new ForbiddenError('Not an Admin');
|
||||
}
|
||||
|
||||
if (!id) {
|
||||
throw new BadRequestError();
|
||||
}
|
||||
|
||||
const idNumber = Number(id);
|
||||
if (isNaN(idNumber)) {
|
||||
throw new BadRequestError();
|
||||
}
|
||||
|
||||
const announcement = await Announcements.findOne(idNumber);
|
||||
if (!announcement) {
|
||||
throw new NotFoundError();
|
||||
}
|
||||
|
||||
await Announcements.delete(id);
|
||||
}
|
||||
|
||||
@Get('/:id') async getDetail(@Param('id') id: string) {
|
||||
if (!id) {
|
||||
throw new BadRequestError();
|
||||
}
|
||||
|
||||
const idNumber = Number(id);
|
||||
if (isNaN(idNumber)) {
|
||||
throw new NotFoundError();
|
||||
throw new BadRequestError();
|
||||
}
|
||||
const announcement = await Announcements.findOne(idNumber);
|
||||
if (!announcement) {
|
||||
|
|
|
@ -18,7 +18,7 @@ export const api = async <T extends Record<string, unknown> = Record<string, unk
|
|||
try {
|
||||
data = await axios.post<T>(`https://${host}/api/${endpoint}`, a).then(res => res.data);
|
||||
} catch (e) {
|
||||
printLog(`전송 오류: ${host}/api/${endpoint} - 재시도 중 (${i + 1} / ${RETRY_COUNT})\n${e}`, 'error');
|
||||
printLog(`API 오류: ${host}/api/${endpoint} - 재시도 중 (${i + 1} / ${RETRY_COUNT})\n${e}`, 'error');
|
||||
await delay(3000);
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -34,9 +34,8 @@ export const sendAlert = async (user: User) => {
|
|||
export const sendNoteAlert = async (text: string, user: User) => {
|
||||
const res = await api<Record<string, unknown>>(user.host, 'notes/create', {
|
||||
text,
|
||||
visibility: user.visibility,
|
||||
localOnly: user.localOnly,
|
||||
remoteFollowersOnly: user.remoteFollowersOnly,
|
||||
visibility: user.visibility === 'users' ? 'specified' : user.visibility,
|
||||
localOnly: user.localOnly
|
||||
}, user.token);
|
||||
|
||||
if (res.error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue