fix: apply Phase 1-2 correctness and constant extraction from PR #273

- Replace datetime.utcnow() with datetime.now(timezone.utc) in 4 files
- Extract duplicate literals to constants in 5 files
  - models.py: "files.id" → _FILES_ID_FK
  - upload_to_email.py: "logo.png" → _LOGO_FILENAME
  - general.py: "%B %d, %Y" → _DATE_DISPLAY_FORMAT
  - files.py: "File not found" → _FILE_NOT_FOUND
  - upload_to_google_drive.py: Google token URL → _GOOGLE_TOKEN_URL

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-13 11:25:30 +00:00
parent fe32302adb
commit 4897cb6655
9 changed files with 38 additions and 23 deletions
+7 -4
View File
@@ -13,6 +13,9 @@ from app.views.base import APIRouter, get_db, logger, require_login, templates
router = APIRouter()
# Error message constants
_FILE_NOT_FOUND = "File not found"
@router.get("/files")
@require_login
@@ -433,7 +436,7 @@ def preview_original_file(request: Request, file_id: int, db: Session = Depends(
file_record = db.query(FileRecord).filter(FileRecord.id == file_id).first()
if not file_record:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="File not found")
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=_FILE_NOT_FOUND)
if not file_record.original_file_path or not os.path.exists(file_record.original_file_path):
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Original file not found on disk")
@@ -460,7 +463,7 @@ def preview_processed_file(request: Request, file_id: int, db: Session = Depends
file_record = db.query(FileRecord).filter(FileRecord.id == file_id).first()
if not file_record:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="File not found")
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=_FILE_NOT_FOUND)
if not file_record.processed_file_path or not os.path.exists(file_record.processed_file_path):
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Processed file not found on disk")
@@ -487,7 +490,7 @@ def get_original_text(request: Request, file_id: int, db: Session = Depends(get_
file_record = db.query(FileRecord).filter(FileRecord.id == file_id).first()
if not file_record:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="File not found")
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=_FILE_NOT_FOUND)
if not file_record.original_file_path or not os.path.exists(file_record.original_file_path):
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Original file not found on disk")
@@ -527,7 +530,7 @@ def get_processed_text(request: Request, file_id: int, db: Session = Depends(get
file_record = db.query(FileRecord).filter(FileRecord.id == file_id).first()
if not file_record:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="File not found")
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=_FILE_NOT_FOUND)
if not file_record.processed_file_path or not os.path.exists(file_record.processed_file_path):
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Processed file not found on disk")
+6 -3
View File
@@ -14,6 +14,9 @@ from app.views.base import APIRouter, get_db, logger, require_login, templates
router = APIRouter()
# Date format constant
_DATE_DISPLAY_FORMAT = "%B %d, %Y"
@router.get("/", include_in_schema=False)
async def serve_index(request: Request, db: Session = Depends(get_db)):
@@ -82,7 +85,7 @@ async def serve_about(request: Request):
async def serve_privacy(request: Request):
"""Serve the privacy policy page."""
# Pass the current date for the "Last Updated" field
current_date = date.today().strftime("%B %d, %Y")
current_date = date.today().strftime(_DATE_DISPLAY_FORMAT)
return templates.TemplateResponse("privacy.html", {"request": request, "current_date": current_date})
@@ -148,12 +151,12 @@ Please visit http://www.apache.org/licenses/LICENSE-2.0 for the complete license
@router.get("/cookies", include_in_schema=False)
async def serve_cookies(request: Request):
"""Serve the cookie policy page."""
current_date = date.today().strftime("%B %d, %Y")
current_date = date.today().strftime(_DATE_DISPLAY_FORMAT)
return templates.TemplateResponse("cookies.html", {"request": request, "current_date": current_date})
@router.get("/terms", include_in_schema=False)
async def serve_terms(request: Request):
"""Serve the terms of service page."""
current_date = date.today().strftime("%B %d, %Y")
current_date = date.today().strftime(_DATE_DISPLAY_FORMAT)
return templates.TemplateResponse("terms.html", {"request": request, "current_date": current_date})