feat: moderation
This commit is contained in:
parent
db9c133bbb
commit
2def8d7a00
6 changed files with 61 additions and 4 deletions
|
|
@ -4,6 +4,7 @@ import { db } from '$lib/server/db';
|
|||
import { comment, coin, user, commentLike } from '$lib/server/db/schema';
|
||||
import { eq, and, desc, sql } from 'drizzle-orm';
|
||||
import { redis } from '$lib/server/redis';
|
||||
import { isNameAppropriate } from '$lib/server/moderation';
|
||||
|
||||
export async function GET({ params, request }) {
|
||||
const session = await auth.api.getSession({
|
||||
|
|
@ -73,6 +74,10 @@ export async function POST({ request, params }) {
|
|||
throw error(400, 'Comment must be 500 characters or less');
|
||||
}
|
||||
|
||||
if (!(await isNameAppropriate(content.trim()))) {
|
||||
throw error(400, 'Comment contains inappropriate content');
|
||||
}
|
||||
|
||||
const normalizedSymbol = coinSymbol.toUpperCase();
|
||||
const userId = Number(session.user.id);
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,9 @@ import { coin, userPortfolio, user, priceHistory, transaction } from '$lib/serve
|
|||
import { eq } from 'drizzle-orm';
|
||||
import { uploadCoinIcon } from '$lib/server/s3';
|
||||
import { CREATION_FEE, FIXED_SUPPLY, STARTING_PRICE, INITIAL_LIQUIDITY, TOTAL_COST, MAX_FILE_SIZE } from '$lib/data/constants';
|
||||
import { isNameAppropriate } from '$lib/server/moderation';
|
||||
|
||||
function validateInputs(name: string, symbol: string, iconFile: File | null) {
|
||||
async function validateInputs(name: string, symbol: string, iconFile: File | null) {
|
||||
if (!name || name.length < 2 || name.length > 255) {
|
||||
throw error(400, 'Name must be between 2 and 255 characters');
|
||||
}
|
||||
|
|
@ -15,6 +16,16 @@ function validateInputs(name: string, symbol: string, iconFile: File | null) {
|
|||
throw error(400, 'Symbol must be between 2 and 10 characters');
|
||||
}
|
||||
|
||||
const nameAppropriate = await isNameAppropriate(name);
|
||||
if (!nameAppropriate) {
|
||||
throw error(400, 'Coin name contains inappropriate content');
|
||||
}
|
||||
|
||||
const symbolAppropriate = await isNameAppropriate(symbol);
|
||||
if (!symbolAppropriate) {
|
||||
throw error(400, 'Coin symbol contains inappropriate content');
|
||||
}
|
||||
|
||||
if (iconFile && iconFile.size > MAX_FILE_SIZE) {
|
||||
throw error(400, 'Icon file must be smaller than 1MB');
|
||||
}
|
||||
|
|
@ -77,7 +88,7 @@ export async function POST({ request }) {
|
|||
const normalizedSymbol = symbol?.toUpperCase();
|
||||
const userId = Number(session.user.id);
|
||||
|
||||
validateInputs(name, normalizedSymbol, iconFile);
|
||||
await validateInputs(name, normalizedSymbol, iconFile);
|
||||
|
||||
const [currentBalance] = await Promise.all([
|
||||
validateUserBalance(userId),
|
||||
|
|
|
|||
Reference in a new issue