mirror of
https://github.com/Terncode/pixel.horse.git
synced 2026-12-03 05:10:04 +01:00
Validate hides api parameters
This commit is contained in:
1 parent
566a0d64cc
commit
a0bb9b2fbb
1 file changed
+11
-3
@@ -1,4 +1,5 @@
|
||||
import { formatDistanceToNow } from 'date-fns';
|
||||
import { isValidObjectId } from 'mongoose';
|
||||
import {
|
||||
ACCOUNT_NAME_MAX_LENGTH, ACCOUNT_NAME_MIN_LENGTH, MIN_CHATLOG_RANGE, MAX_CHATLOG_RANGE, HIDES_PER_PAGE, MAX_FILTER_WORDS_LENGTH
|
||||
} from '../../common/constants';
|
||||
@@ -25,6 +26,7 @@ export type RemoveSite = ReturnType<typeof createRemoveSite>;
|
||||
export type GetAccountData = ReturnType<typeof createGetAccountData>;
|
||||
|
||||
const MAX_DEFAULT_SERVER_LENGTH = 100;
|
||||
const MAX_HIDES_PAGE = 100000;
|
||||
const MAX_ACTIONS_SETTING_LENGTH = 20000;
|
||||
|
||||
type LogAccount = (accountId: ID, message: string) => void;
|
||||
@@ -172,11 +174,13 @@ export async function getFriends(account: IAccount) {
|
||||
return findFriends(account._id, true);
|
||||
}
|
||||
|
||||
export async function getHides(account: IAccount, page: number) {
|
||||
export async function getHides(account: IAccount, page: unknown) {
|
||||
const pageIndex = typeof page === 'number' && isFinite(page) ? clamp(Math.floor(page), 0, MAX_HIDES_PAGE) : 0;
|
||||
|
||||
const hideRequests = await HideRequest
|
||||
.find({ source: account._id }, '_id name date')
|
||||
.sort({ date: -1 })
|
||||
.skip(page * HIDES_PER_PAGE)
|
||||
.skip(pageIndex * HIDES_PER_PAGE)
|
||||
.limit(HIDES_PER_PAGE)
|
||||
.lean()
|
||||
.exec();
|
||||
@@ -260,6 +264,10 @@ export const createRemoveSite =
|
||||
return {};
|
||||
};
|
||||
|
||||
export async function removeHide(account: IAccount, hideId: string) {
|
||||
export async function removeHide(account: IAccount, hideId: unknown) {
|
||||
if (typeof hideId !== 'string' || !isValidObjectId(hideId)) {
|
||||
throw new UserError('Invalid hide ID');
|
||||
}
|
||||
|
||||
await HideRequest.deleteOne({ source: account._id, _id: hideId }).exec();
|
||||
}
|
||||
Reference in new issue
Block a user