feat: Initialize frontend with React, Vite, and Tailwind CSS
- Set up main entry point for React application. - Create About, Home, NotFound, Privacy, and Terms pages with SEO support. - Implement API service for file uploads and task management. - Add global styles using Tailwind CSS. - Create utility functions for SEO and text processing. - Configure Vite for development and production builds. - Set up Nginx configuration for serving frontend and backend. - Add scripts for cleanup of expired files and sitemap generation. - Implement deployment script for production environment.
This commit is contained in:
77
backend/app/utils/sanitizer.py
Normal file
77
backend/app/utils/sanitizer.py
Normal file
@@ -0,0 +1,77 @@
|
||||
"""Filename sanitization and temporary file management."""
|
||||
import os
|
||||
import uuid
|
||||
|
||||
from flask import current_app
|
||||
|
||||
|
||||
def generate_safe_path(extension: str, folder_type: str = "upload") -> tuple[str, str]:
|
||||
"""
|
||||
Generate a safe file path using UUID.
|
||||
|
||||
Args:
|
||||
extension: File extension (without dot)
|
||||
folder_type: "upload" for input files, "output" for processed files
|
||||
|
||||
Returns:
|
||||
tuple: (task_id, full_file_path)
|
||||
"""
|
||||
task_id = str(uuid.uuid4())
|
||||
|
||||
if folder_type == "upload":
|
||||
base_dir = current_app.config["UPLOAD_FOLDER"]
|
||||
else:
|
||||
base_dir = current_app.config["OUTPUT_FOLDER"]
|
||||
|
||||
# Create task-specific directory
|
||||
task_dir = os.path.join(base_dir, task_id)
|
||||
os.makedirs(task_dir, exist_ok=True)
|
||||
|
||||
filename = f"{task_id}.{extension}"
|
||||
file_path = os.path.join(task_dir, filename)
|
||||
|
||||
return task_id, file_path
|
||||
|
||||
|
||||
def get_output_path(task_id: str, extension: str) -> str:
|
||||
"""
|
||||
Get the output file path for a processed file.
|
||||
|
||||
Args:
|
||||
task_id: The task UUID
|
||||
extension: Output file extension
|
||||
|
||||
Returns:
|
||||
Full output file path
|
||||
"""
|
||||
output_dir = current_app.config["OUTPUT_FOLDER"]
|
||||
task_dir = os.path.join(output_dir, task_id)
|
||||
os.makedirs(task_dir, exist_ok=True)
|
||||
|
||||
filename = f"{task_id}.{extension}"
|
||||
return os.path.join(task_dir, filename)
|
||||
|
||||
|
||||
def cleanup_task_files(task_id: str, keep_outputs: bool = False):
|
||||
"""
|
||||
Remove temporary files for a given task.
|
||||
|
||||
Args:
|
||||
task_id: The task UUID
|
||||
keep_outputs: If True, only clean uploads (used in local storage mode)
|
||||
"""
|
||||
import shutil
|
||||
|
||||
upload_dir = current_app.config.get("UPLOAD_FOLDER", "/tmp/uploads")
|
||||
output_dir = current_app.config.get("OUTPUT_FOLDER", "/tmp/outputs")
|
||||
|
||||
# Always clean uploads
|
||||
upload_task_dir = os.path.join(upload_dir, task_id)
|
||||
if os.path.exists(upload_task_dir):
|
||||
shutil.rmtree(upload_task_dir, ignore_errors=True)
|
||||
|
||||
# Only clean outputs when using S3 (files already uploaded to S3)
|
||||
if not keep_outputs:
|
||||
output_task_dir = os.path.join(output_dir, task_id)
|
||||
if os.path.exists(output_task_dir):
|
||||
shutil.rmtree(output_task_dir, ignore_errors=True)
|
||||
Reference in New Issue
Block a user