Nattiden пре 2 месеци
родитељ
комит
cf3771af77
2 измењених фајлова са 19 додато и 3 уклоњено
  1. 1 0
      .github/workflows/check_mcversion.yml
  2. 18 3
      Actions/upload_header_image.py

+ 1 - 0
.github/workflows/check_mcversion.yml

@@ -23,6 +23,7 @@ jobs:
             pip install botocore
             pip install boto3
             pip install beautifulsoup4
+            pip install Pillow
        - name: 运行更新脚本
          id: run_script
          run: python Actions/check_mcv.py >> "$GITHUB_ENV"

+ 18 - 3
Actions/upload_header_image.py

@@ -5,6 +5,8 @@ import boto3
 import requests
 from bs4 import BeautifulSoup
 from botocore.config import Config
+from io import BytesIO
+from PIL import Image
 
 from minecraft_version import MCVM, MinecraftVersion
 
@@ -131,7 +133,7 @@ def find_hero_image(html: str, page_url: str) -> str:
 
     image_url = urljoin(
         page_url,
-        src,
+        str(src),
     )
 
     #print(f"图片: {image_url}")
@@ -167,7 +169,20 @@ def download_image(
         "application/octet-stream",
     )
 
-    return response.content, content_type
+    image = Image.open(BytesIO(response.content))
+    if image.mode != "RGB":
+        image = image.convert("RGB")
+
+    output = BytesIO()
+    image.save(
+        output,
+        format="JPEG",
+        quality=95,
+        optimize=True,
+    )
+    jpeg_data = output.getvalue()
+
+    return jpeg_data, "image/jpeg"
 
 def upload_to_r2(
     data: bytes,
@@ -203,7 +218,7 @@ def upload_header_image(version):
         change_log_url,
     )
     bucket = "images"
-    object_key = f"news/version/{version.major_version}/{version.id}.webp"
+    object_key = f"news/version/{version.major_version}/{version.id}.jpg"
     upload_to_r2(
         image_data,
         bucket,