This commit is contained in:
1 parent
b2ab347129
commit
adc832c042
14 files changed
+336
-24
No files matched your search
+33
-5
@@ -34,6 +34,7 @@ for stream in (sys.stdout, sys.stderr):
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
import covers
|
||||
import db
|
||||
import reco
|
||||
import steam_source
|
||||
@@ -95,6 +96,7 @@ CONTENT_TYPES = {
|
||||
".jpg": "image/jpeg",
|
||||
".jpeg": "image/jpeg",
|
||||
".ico": "image/x-icon",
|
||||
".webp": "image/webp",
|
||||
".webmanifest": "application/manifest+json; charset=utf-8",
|
||||
}
|
||||
|
||||
@@ -624,22 +626,39 @@ class Handler(BaseHTTPRequestHandler):
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
def _preview_for(self, app_cache, source):
|
||||
if not covers.can_optimize():
|
||||
return None
|
||||
preview = os.path.join(app_cache, covers.PREVIEW_NAME)
|
||||
if os.path.isfile(preview):
|
||||
return preview
|
||||
with IMAGE_LOCK:
|
||||
if not os.path.isfile(preview):
|
||||
covers.make_preview(source, preview)
|
||||
return preview if os.path.isfile(preview) else None
|
||||
|
||||
def _cover(self, appid):
|
||||
app_cache = os.path.join(CACHE_DIR, str(appid))
|
||||
|
||||
preview = os.path.join(app_cache, covers.PREVIEW_NAME)
|
||||
if os.path.isfile(preview):
|
||||
self._clear_cover_missing(appid)
|
||||
self._serve_image(preview)
|
||||
return
|
||||
|
||||
# 1. our own cache (including new-style names)
|
||||
for name in CACHE_COVER_NAMES:
|
||||
path = os.path.join(app_cache, name)
|
||||
if os.path.isfile(path):
|
||||
self._clear_cover_missing(appid)
|
||||
self._serve_image(path)
|
||||
self._serve_image(self._preview_for(app_cache, path) or path)
|
||||
return
|
||||
|
||||
# 2. art already downloaded by the Steam client (old and new layout)
|
||||
local = steam_source.find_cover(appid, LIB_CACHE)
|
||||
if local:
|
||||
self._clear_cover_missing(appid)
|
||||
self._serve_image(local)
|
||||
self._serve_image(self._preview_for(app_cache, local) or local)
|
||||
return
|
||||
|
||||
# Do not hammer Steam CDN for apps known to have no cover.
|
||||
@@ -656,10 +675,15 @@ class Handler(BaseHTTPRequestHandler):
|
||||
finally:
|
||||
con.close()
|
||||
if row:
|
||||
data = self._download_cover(row["header_image"], os.path.join(app_cache, "header.jpg"))
|
||||
path = os.path.join(app_cache, "header.jpg")
|
||||
data = self._download_cover(row["header_image"], path)
|
||||
if data:
|
||||
self._clear_cover_missing(appid)
|
||||
self._send(200, data, "image/jpeg", cache=True, max_age=2592000)
|
||||
preview = self._preview_for(app_cache, path)
|
||||
if preview:
|
||||
self._serve_image(preview)
|
||||
else:
|
||||
self._send(200, data, "image/jpeg", cache=True, max_age=2592000)
|
||||
return
|
||||
|
||||
# 4. legacy CDN names, kept on disk
|
||||
@@ -669,7 +693,11 @@ class Handler(BaseHTTPRequestHandler):
|
||||
data = self._download_cover(url, path)
|
||||
if data:
|
||||
self._clear_cover_missing(appid)
|
||||
self._send(200, data, "image/jpeg", cache=True, max_age=2592000)
|
||||
preview = self._preview_for(app_cache, path)
|
||||
if preview:
|
||||
self._serve_image(preview)
|
||||
else:
|
||||
self._send(200, data, "image/jpeg", cache=True, max_age=2592000)
|
||||
return
|
||||
|
||||
self._mark_cover_missing(appid)
|
||||
|
||||
Reference in new issue
Block a user