fix(demo): switch to fruit content filter
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import {Controller} from '@blitzjs/core'
|
||||
import alex from 'alex'
|
||||
import {validContent} from '../utils/contentFilter'
|
||||
|
||||
export const CommentsController = Controller(({db}) => ({
|
||||
name: 'CommentsController',
|
||||
@@ -7,8 +7,8 @@ export const CommentsController = Controller(({db}) => ({
|
||||
permit: ['content'],
|
||||
|
||||
async create(params, newData) {
|
||||
if (alex(newData.content).messages.length || newData.content?.toLowerCase().includes('4chan')) {
|
||||
newData.content = 'Be nice'
|
||||
if (!validContent(newData.content)) {
|
||||
newData.content = 'Fruit'
|
||||
}
|
||||
|
||||
const data = await db.comment.create({
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {Controller} from '@blitzjs/core'
|
||||
import alex from 'alex'
|
||||
import {validContent} from '../utils/contentFilter'
|
||||
|
||||
export const PostsController = Controller(({db}) => ({
|
||||
name: 'PostsController',
|
||||
@@ -7,7 +7,7 @@ export const PostsController = Controller(({db}) => ({
|
||||
permit: ['title', 'content'],
|
||||
|
||||
async index() {
|
||||
const posts = await db.post.findMany({orderBy: {id: 'asc'}})
|
||||
const posts = await db.post.findMany({orderBy: {id: 'desc'}, first: 20})
|
||||
|
||||
return {
|
||||
data: {posts},
|
||||
@@ -23,11 +23,11 @@ export const PostsController = Controller(({db}) => ({
|
||||
},
|
||||
|
||||
async create(params, newData) {
|
||||
if (alex(newData.title).messages.length || newData.title?.toLowerCase().includes('4chan')) {
|
||||
newData.title = 'Be nice'
|
||||
if (!validContent(newData.title)) {
|
||||
newData.title = 'Fruit'
|
||||
}
|
||||
if (alex(newData.content).messages.length || newData.content?.toLowerCase().includes('4chan')) {
|
||||
newData.content = 'Be nice'
|
||||
if (!validContent(newData.content)) {
|
||||
newData.content = 'Fruit'
|
||||
}
|
||||
|
||||
const data = await db.post.create({
|
||||
@@ -44,11 +44,11 @@ export const PostsController = Controller(({db}) => ({
|
||||
},
|
||||
|
||||
async update(params, newData) {
|
||||
if (alex(newData.title).messages.length || newData.title?.toLowerCase().includes('4chan')) {
|
||||
newData.title = 'Be nice'
|
||||
if (!validContent(newData.title)) {
|
||||
newData.title = 'Fruit'
|
||||
}
|
||||
if (alex(newData.content).messages.length || newData.content?.toLowerCase().includes('4chan')) {
|
||||
newData.content = 'Be nice'
|
||||
if (!validContent(newData.content)) {
|
||||
newData.content = 'Fruit'
|
||||
}
|
||||
|
||||
const data = await db.post.update({
|
||||
|
||||
@@ -63,6 +63,8 @@ function Page({post}) {
|
||||
</button>
|
||||
</div>
|
||||
</Form>
|
||||
|
||||
<p className="py-3">For your safety, content can only be the name of a fruit</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ function Page({post}) {
|
||||
|
||||
<h1 className="text-3xl">{post.title}</h1>
|
||||
|
||||
<p className="py-3">For your safety, content can only be the name of a fruit</p>
|
||||
|
||||
<Form action={`/api/posts/${post.id}`} method="PATCH" className="min-w-full">
|
||||
<div className="mb-4">
|
||||
<label className="block text-gray-700 text-sm font-bold mb-2">Title</label>
|
||||
|
||||
@@ -15,7 +15,7 @@ function Page({posts}) {
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<h1 className="text-3xl">{posts.length} Posts</h1>
|
||||
<h1 className="text-3xl">First {posts.length} Posts</h1>
|
||||
<p className="mt-5">
|
||||
<Link href="/">
|
||||
<a className="underline text-purple-700 text-sm">Back Home</a>
|
||||
|
||||
@@ -14,6 +14,8 @@ function Page() {
|
||||
|
||||
<h1 className="text-3xl">New Post</h1>
|
||||
|
||||
<p className="py-3">For your safety, content can only be the name of a fruit</p>
|
||||
|
||||
<Form action={`/api/posts`} method="POST" className="min-w-full">
|
||||
<div className="mb-4">
|
||||
<label className="block text-gray-700 text-sm font-bold mb-2">Title</label>
|
||||
|
||||
34
examples/first-demo/utils/contentFilter.ts
Normal file
34
examples/first-demo/utils/contentFilter.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
const fruits = [
|
||||
'Apple',
|
||||
'Watermelon',
|
||||
'Orange',
|
||||
'Pear',
|
||||
'Cherry',
|
||||
'Strawberry',
|
||||
'Nectarine',
|
||||
'Grape',
|
||||
'Mango',
|
||||
'Blueberry',
|
||||
'Pomegranate',
|
||||
'Plum',
|
||||
'Banana',
|
||||
'Raspberry',
|
||||
'Mandarin',
|
||||
'Jackfruit',
|
||||
'Papaya',
|
||||
'Kiwi',
|
||||
'Pineapple',
|
||||
'Lime',
|
||||
'Lemon',
|
||||
'Apricot',
|
||||
'Grapefruit',
|
||||
'Melon',
|
||||
'Coconut',
|
||||
'Peach',
|
||||
'Tomato',
|
||||
].map(f => f.toLowerCase())
|
||||
|
||||
export function validContent(str?: string) {
|
||||
if (!str) return true
|
||||
return fruits.includes(str.toLowerCase().trim())
|
||||
}
|
||||
Reference in New Issue
Block a user