(20241213) Mail Module Reworked!

This commit is contained in:
2024-12-13 14:14:15 +05:30
parent a702e5ca20
commit e8ddffbdfe
12 changed files with 297 additions and 175 deletions
+16 -22
View File
@@ -42,29 +42,21 @@ import os
import psutil
# For using Quart:
from quart import Quart, request, current_app
from quart import Quart, current_app
from quart_cors import cors
# Common:
from shared import constants
# My utils:
from utils_v2.string import json
from utils_v2.api import async_quart
from utils_v2.date_time import date_time
from utils_v2.database.async_mongo_v2 import AsyncMongo, AsyncMongoStorage
from utils_v2.database.async_mongo_v2 import AsyncMongo
from utils_v2.database.async_mysql_v2 import AsyncMySQL
from utils_v2.cache.async_redis_cache_v2 import AsyncRedisCache
from utils_v2.serialization.json_serializer import JSONSerializer
from utils_v2.api.async_quart import (
set_api_version,
read_input,
log_request_to_mongo,
should_not_be_under_maintenance,
only_whitelisted_ips,
limit_rate,
validate_input,
handle_cancelled_request
log_request_to_mongo
)
# GMail-related utils:
@@ -92,11 +84,12 @@ import httpx
from icecream import IceCreamDebugger
# All the blueprints:
from api.blueprints.mail.oauth_request import mail_oauth_bp
from api.blueprints.mail.oauth_callback import mail_callback_bp
from api.blueprints.mail.sync_v2 import mail_sync_bp
# from api.blueprints.mail.list import mail_list_bp
# from api.blueprints.mail.retrieve import mail_retrieve_bp
from api.blueprints.mail.oauth.request import mail_oauth_request_bp
from api.blueprints.mail.oauth.callback import mail_oauth_callback_bp
from api.blueprints.mail.sync.sync_v2 import mail_sync_bp
from api.blueprints.mail.retrieve.list import mail_list_bp
from api.blueprints.mail.retrieve.get import mail_get_bp
from api.blueprints.mail.tags.update import mail_tags_update_bp
# from api.blueprints.sms.auth import sms_auth_bp
# from api.blueprints.sms.send import sms_send_bp
# from api.blueprints.chat.auth import chat_auth_bp
@@ -131,11 +124,12 @@ APP_VERSION = constants.APP_VERSION
# The Quart app:
app = Quart(__name__, template_folder = r"../views")
app = cors(app)
app.register_blueprint(mail_oauth_bp, url_prefix = f"/{MODULE_BASE}/mail")
app.register_blueprint(mail_callback_bp, url_prefix = f"/{MODULE_BASE}/mail")
app.register_blueprint(mail_oauth_request_bp, url_prefix = f"/{MODULE_BASE}/mail")
app.register_blueprint(mail_oauth_callback_bp, url_prefix = f"/{MODULE_BASE}/mail")
app.register_blueprint(mail_sync_bp, url_prefix = f"/{MODULE_BASE}/mail")
# app.register_blueprint(mail_list_bp, url_prefix = f"/{MODULE_BASE}/mail")
# app.register_blueprint(mail_retrieve_bp, url_prefix = f"/{MODULE_BASE}/mail")
app.register_blueprint(mail_list_bp, url_prefix = f"/{MODULE_BASE}/mail")
app.register_blueprint(mail_get_bp, url_prefix = f"/{MODULE_BASE}/mail")
app.register_blueprint(mail_tags_update_bp, url_prefix = f"/{MODULE_BASE}/mail")
# app.register_blueprint(sms_auth_bp, url_prefix = f"/{MODULE_BASE}/sms")
# app.register_blueprint(sms_send_bp, url_prefix = f"/{MODULE_BASE}/sms")
# app.register_blueprint(chat_auth_bp, url_prefix = f"/{MODULE_BASE}/chat")
@@ -329,7 +323,7 @@ async def app_startup(**kwargs):
# ┃ ┏┓┏┓┏┓ ┃┃┃┏┓┏┫┏┓┃┏
# ┗┛┗┛┛ ┗ ┛ ┗┗┛┗┻┗ ┗┛
current_app.core_message_controller = MessageController(
current_app.core_auth_token_controller = AuthTokenController(
cache = current_app.module_cache,
alert_url = current_app.script_data["alerts"]["url"],
http_client = current_app.http_client,
@@ -337,7 +331,7 @@ async def app_startup(**kwargs):
debug_prefix = "Message (CM) | ",
debug_only_errors = True
)
current_app.core_auth_token_controller = AuthTokenController(
current_app.core_message_controller = MessageController(
cache = current_app.module_cache,
alert_url = current_app.script_data["alerts"]["url"],
http_client = current_app.http_client,