max content length = 10MB
This commit is contained in:
@ -27,6 +27,8 @@ import {
|
||||
SearchResponse,
|
||||
} from './types'
|
||||
|
||||
const MAX_CONTENT_LENGTH = 10 * 1024 * 1024 // 10MB
|
||||
|
||||
const appendQuery = (builder: ESBuilder, query: string): ESBuilder => {
|
||||
interface Field {
|
||||
field: string
|
||||
@ -404,6 +406,17 @@ export const createPage = async (
|
||||
ctx: PageContext
|
||||
): Promise<string | undefined> => {
|
||||
try {
|
||||
// max 10MB
|
||||
if (page.content.length > MAX_CONTENT_LENGTH) {
|
||||
logger.info('page content is too large', {
|
||||
pageId: page.id,
|
||||
contentLength: page.content.length,
|
||||
})
|
||||
|
||||
page.content = 'Your page content is too large to be saved.'
|
||||
page.state = ArticleSavingRequestStatus.Failed
|
||||
}
|
||||
|
||||
const { body } = await client.index({
|
||||
id: page.id || undefined,
|
||||
index: INDEX_ALIAS,
|
||||
@ -432,6 +445,17 @@ export const updatePage = async (
|
||||
ctx: PageContext
|
||||
): Promise<boolean> => {
|
||||
try {
|
||||
// max 10MB
|
||||
if (page.content && page.content.length > MAX_CONTENT_LENGTH) {
|
||||
logger.info('page content is too large', {
|
||||
pageId: page.id,
|
||||
contentLength: page.content.length,
|
||||
})
|
||||
|
||||
page.content = 'Your page content is too large to be saved.'
|
||||
page.state = ArticleSavingRequestStatus.Failed
|
||||
}
|
||||
|
||||
await client.update({
|
||||
index: INDEX_ALIAS,
|
||||
id,
|
||||
@ -519,6 +543,7 @@ export const getPageByParam = async <K extends keyof ParamSet>(
|
||||
const { body } = await client.search<SearchResponse<Page>>({
|
||||
index: INDEX_ALIAS,
|
||||
body: builder.build(),
|
||||
track_total_hits: true,
|
||||
})
|
||||
|
||||
if (body.hits.total.value === 0) {
|
||||
|
||||
@ -160,7 +160,7 @@ export function newsletterServiceRouter() {
|
||||
|
||||
res.status(200).send('newsletter created')
|
||||
} catch (e) {
|
||||
logger.info(e)
|
||||
logger.error(e)
|
||||
if (e instanceof SyntaxError) {
|
||||
// when message is not a valid json string
|
||||
res.status(400).send(e)
|
||||
|
||||
Reference in New Issue
Block a user