- Implemented ProtectPdf component for adding password protection to PDFs. - Implemented RotatePdf component for rotating PDF pages by specified angles. - Implemented SplitPdf component for splitting PDFs into individual pages or specified ranges. - Implemented UnlockPdf component for removing password protection from PDFs. - Implemented WatermarkPdf component for adding custom text watermarks to PDFs. - Updated i18n files to include translations for new tools. - Enhanced HomePage to include links to new PDF tools. - Updated Nginx configuration to improve security with CSP and Permissions-Policy headers. - Updated sitemap generation script to include new tools.
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
"""Flask extensions initialization."""
|
|
from celery import Celery
|
|
from flask_cors import CORS
|
|
from flask_limiter import Limiter
|
|
from flask_limiter.util import get_remote_address
|
|
from flask_talisman import Talisman
|
|
|
|
# Initialize extensions (will be bound to app in create_app)
|
|
cors = CORS()
|
|
limiter = Limiter(key_func=get_remote_address)
|
|
talisman = Talisman()
|
|
celery = Celery()
|
|
|
|
|
|
def init_celery(app):
|
|
"""Initialize Celery with Flask app context."""
|
|
celery.conf.broker_url = app.config["CELERY_BROKER_URL"]
|
|
celery.conf.result_backend = app.config["CELERY_RESULT_BACKEND"]
|
|
celery.conf.result_expires = app.config.get("FILE_EXPIRY_SECONDS", 1800)
|
|
celery.conf.task_serializer = "json"
|
|
celery.conf.result_serializer = "json"
|
|
celery.conf.accept_content = ["json"]
|
|
celery.conf.timezone = "UTC"
|
|
celery.conf.task_track_started = True
|
|
|
|
# Set task routes
|
|
celery.conf.task_routes = {
|
|
"app.tasks.convert_tasks.*": {"queue": "convert"},
|
|
"app.tasks.compress_tasks.*": {"queue": "compress"},
|
|
"app.tasks.image_tasks.*": {"queue": "image"},
|
|
"app.tasks.video_tasks.*": {"queue": "video"},
|
|
"app.tasks.pdf_tools_tasks.*": {"queue": "pdf_tools"},
|
|
}
|
|
|
|
class ContextTask(celery.Task):
|
|
"""Make Celery tasks work with Flask app context."""
|
|
abstract = True
|
|
|
|
def __call__(self, *args, **kwargs):
|
|
with app.app_context():
|
|
return self.run(*args, **kwargs)
|
|
|
|
celery.Task = ContextTask
|
|
return celery
|