Mise en place d'une toolbox pour lire les ressources compilées et les retourner sous forme de base64
This commit is contained in:
Generated
+1
-1
@@ -5,7 +5,7 @@
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.13 (Lataniere_ui_1)" jdkType="Python SDK" />
|
||||
<orderEntry type="jdk" jdkName="uv (PyQt6_LaTaniere)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
Generated
+1
-1
@@ -3,5 +3,5 @@
|
||||
<component name="Black">
|
||||
<option name="sdkName" value="uv (PyQt6_LaTaniere)" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.13 (Lataniere_ui_1)" project-jdk-type="Python SDK" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="uv (PyQt6_LaTaniere)" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
@@ -13,11 +13,11 @@ AUTENTICATION_SUCCESS_MESSAGE = """
|
||||
<meta content="utf-8" http-equiv="encoding">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Authentication réussie</h1>
|
||||
<h1><img src="$LOGO$" /> La Tenière : Authentication réussie</h1>
|
||||
<p>Vous pouvez maintenant fermer cette fenêtre et revenir au launcher de La Tanière.</p>
|
||||
</body>
|
||||
</html>
|
||||
""".encode('utf-8')
|
||||
"""
|
||||
# ---------------------------------------------------------------------------
|
||||
# ENUMS
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import os
|
||||
import webbrowser
|
||||
import base64
|
||||
import resources
|
||||
from tools.qt_resources import get_resource_as_data_url
|
||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||
from urllib.parse import parse_qs, urlencode, urlparse
|
||||
|
||||
@@ -36,7 +39,7 @@ class OAuthCallbackHandler(BaseHTTPRequestHandler):
|
||||
self.send_response(200)
|
||||
self.send_header("Content-type", "text/html")
|
||||
self.end_headers()
|
||||
self.wfile.write(AUTENTICATION_SUCCESS_MESSAGE)
|
||||
self.wfile.write(AUTENTICATION_SUCCESS_MESSAGE.replace("$LOGO$", get_resource_as_data_url(":/assets/logo.png")).encode('utf-8'))
|
||||
|
||||
# return discord application id (client id)
|
||||
def get_discord_client_id() -> str:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from config.constants import ApiEndPoints
|
||||
from config.constants import PlayerServerInfo
|
||||
from tools.http_client import ApiError, http_get
|
||||
from config.constants import ApiEndPoints
|
||||
|
||||
|
||||
class WhiteList:
|
||||
@staticmethod
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import base64
|
||||
from PySide6.QtCore import QFile
|
||||
|
||||
|
||||
def get_resource_as_base64(resource_path: str) -> str:
|
||||
"""
|
||||
Extrait une ressource Qt et la retourne encodée en base64.
|
||||
|
||||
:param resource_path: Chemin de la ressource (ex: ":/assets/logo_rond.png")
|
||||
:return: Chaîne base64 de la ressource
|
||||
:raises FileNotFoundError: Si la ressource n'existe pas
|
||||
:raises RuntimeError: Si la ressource ne peut pas être lue
|
||||
"""
|
||||
file = QFile(resource_path)
|
||||
|
||||
if not file.exists():
|
||||
raise FileNotFoundError(f"Ressource Qt introuvable : {resource_path}")
|
||||
|
||||
if not file.open(QFile.OpenModeFlag.ReadOnly):
|
||||
raise RuntimeError(f"Impossible d'ouvrir la ressource Qt : {resource_path}")
|
||||
|
||||
try:
|
||||
data = bytes(file.readAll())
|
||||
finally:
|
||||
file.close()
|
||||
|
||||
if not data:
|
||||
raise RuntimeError(f"Ressource vide : {resource_path}")
|
||||
|
||||
return base64.b64encode(data).decode("utf-8")
|
||||
|
||||
|
||||
def get_resource_as_data_url(resource_path: str, mime_type: str = None) -> str:
|
||||
"""
|
||||
Extrait une ressource Qt et la retourne sous forme de data URL utilisable en HTML.
|
||||
|
||||
:param resource_path: Chemin de la ressource (ex: ":/assets/logo.png")
|
||||
:param mime_type: Type MIME (ex: "image/png"). Déduit depuis l'extension si non fourni.
|
||||
:return: Data URL (ex: "data:image/png;base64,...")
|
||||
"""
|
||||
if mime_type is None:
|
||||
mime_type = _guess_mime_type(resource_path)
|
||||
|
||||
b64 = get_resource_as_base64(resource_path)
|
||||
return f"data:{mime_type};base64,{b64}"
|
||||
|
||||
|
||||
def _guess_mime_type(resource_path: str) -> str:
|
||||
"""Déduit le type MIME depuis l'extension du fichier."""
|
||||
MIME_TYPES = {
|
||||
".png": "image/png",
|
||||
".jpg": "image/jpeg",
|
||||
".jpeg": "image/jpeg",
|
||||
".gif": "image/gif",
|
||||
".svg": "image/svg+xml",
|
||||
".webp": "image/webp",
|
||||
".ico": "image/x-icon",
|
||||
".pdf": "application/pdf",
|
||||
".json": "application/json",
|
||||
".txt": "text/plain",
|
||||
}
|
||||
ext = "." + resource_path.rsplit(".", 1)[-1].lower() if "." in resource_path else ""
|
||||
return MIME_TYPES.get(ext, "application/octet-stream")
|
||||
Reference in New Issue
Block a user