Marthee commited on
Commit
10e618d
·
verified ·
1 Parent(s): 651be42

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -46,17 +46,19 @@ def home():
46
  PROCESSED_PDF_PATH = "static/processed.pdf"
47
 
48
  def getpdfcontent(pdf_path):
49
- # Optimized URL handling
50
  if pdf_path and ('http' in pdf_path or 'dropbox' in pdf_path):
51
  pdf_path = pdf_path.replace('dl=0', 'dl=1')
52
 
53
- # Cache frequently used values
54
  response = requests.get(pdf_path)
55
- pdf_content = BytesIO(response.content)
56
- if not pdf_content:
 
57
  raise ValueError("No valid PDF content found.")
58
 
59
- return pdf_content
 
60
 
61
  @app.route('/view-pdf', methods=['GET'])
62
  def view_pdf():
 
46
  PROCESSED_PDF_PATH = "static/processed.pdf"
47
 
48
  def getpdfcontent(pdf_path):
49
+ # Handle Dropbox URLs
50
  if pdf_path and ('http' in pdf_path or 'dropbox' in pdf_path):
51
  pdf_path = pdf_path.replace('dl=0', 'dl=1')
52
 
53
+ # Get the PDF bytes
54
  response = requests.get(pdf_path)
55
+ pdf_bytes = response.content
56
+
57
+ if not pdf_bytes or not pdf_bytes.startswith(b"%PDF"):
58
  raise ValueError("No valid PDF content found.")
59
 
60
+ # Convert to BytesIO only after validation
61
+ return BytesIO(pdf_bytes)
62
 
63
  @app.route('/view-pdf', methods=['GET'])
64
  def view_pdf():