Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/aws/lambda/template_params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Globals:
SIDEKICK_PREPROCESS_TOPIC: "{{resolve:ssm:/dc/{$ENV$}/lambdas/sidekick_preprocess/topic:latest}}"
RETRY_ERROR_TOPIC: "{{resolve:ssm:/dc/{$ENV$}/lambdas/retry_errors/topic:latest}}"
PDF_SIZE_LIMIT: "{{resolve:ssm:/dc/{$ENV$}/params/pdf_size_limit:latest}}"
PAGE_COUNT_LIMIT: "{{resolve:ssm:/dc/{$ENV$}/params/page_count_limit:latest}}"
BLOCK_SIZE: "{{resolve:ssm:/dc/{$ENV$}/params/block_size:latest}}"
IMPORT_DIR: "{{resolve:ssm:/dc/{$ENV$}/lambdas/config/import_dir:latest}}"
IMPORT_BUCKET: "{{resolve:ssm:/dc/{$ENV$}/lambdas/config/import_bucket:latest}}"
Expand Down
18 changes: 18 additions & 0 deletions documentcloud/documents/processing/info_and_image/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@
TEXT_POSITION_BATCH = env.int(
"TEXT_POSITION_BATCH", 3
) # Number of pages to pull text positions from with each function

# PDF upload size limit is 500MB
PDF_SIZE_LIMIT = env.int("PDF_SIZE_LIMIT", 501 * 1024 * 1024)
# PDF page count limit
PAGE_COUNT_LIMIT = env.int("PAGE_COUNT_LIMIT", 2000)

BLOCK_SIZE = env.int(
"BLOCK_SIZE", 8 * 1024 * 1024
) # Block size to use for reading chunks of the PDF
Expand Down Expand Up @@ -170,6 +175,10 @@ class PdfSizeError(Exception):
pass


class PageCountError(Exception):
pass


def initialize_redis_page_data(doc_id, page_count):
"""Initialize Redis fields to manage page dimensions and processing"""
dimensions_field = redis_fields.dimensions(doc_id)
Expand Down Expand Up @@ -719,6 +728,15 @@ def process_pdf(data, _context=None):

# Extract the page count and store it in Redis
page_count = extract_pagecount(doc_id, slug)

# Ensure page count is within the limit
if page_count > PAGE_COUNT_LIMIT:
# If it is beyond the limit
# delete it from storage
# and raise PageCountError
storage.delete(path.path(doc_id))
raise PageCountError()

initialize_redis_page_data(doc_id, page_count)

# Update the model with the page count
Expand Down
Loading