Hotfix storing screenshots when igdb fetch fails

This commit is contained in:
Georges-Antoine Assi
2024-02-10 17:44:55 -05:00
parent b29fb42e8f
commit dac701334e

View File

@@ -2,7 +2,7 @@ import os
import shutil
from pathlib import Path
from urllib.parse import quote
from urllib3.exceptions import ProtocolError
import requests
from config import RESOURCES_BASE_PATH
from handler.fs_handler import (
@@ -135,11 +135,13 @@ class FSResourceHandler(FSHandler):
q_rom_name = quote(rom_name)
path_cover_l = f"{fs_slug}/{q_rom_name}/cover/{CoverSize.BIG.value}.{file_ext}"
path_cover_s = f"{fs_slug}/{q_rom_name}/cover/{CoverSize.SMALL.value}.{file_ext}"
path_cover_s = (
f"{fs_slug}/{q_rom_name}/cover/{CoverSize.SMALL.value}.{file_ext}"
)
artwork_path = f"{RESOURCES_BASE_PATH}/{fs_slug}/{rom_name}/cover"
Path(artwork_path).mkdir(parents=True, exist_ok=True)
return path_cover_l, path_cover_s, artwork_path
def _store_screenshot(self, fs_slug: str, rom_name: str, url: str, idx: int):
"""Store roms resources in filesystem
@@ -154,7 +156,10 @@ class FSResourceHandler(FSHandler):
if res.status_code == 200:
Path(screenshot_path).mkdir(parents=True, exist_ok=True)
with open(f"{screenshot_path}/{screenshot_file}", "wb") as f:
shutil.copyfileobj(res.raw, f)
try:
shutil.copyfileobj(res.raw, f)
except ProtocolError:
pass
def _get_screenshot_path(self, fs_slug: str, rom_name: str, idx: str):
"""Returns rom cover filesystem path adapted to frontend folder structure