diff --git a/model.py b/model.py index a3448e4..8f2562a 100644 --- a/model.py +++ b/model.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- import json -from datetime import datetime +from datetime import datetime, timedelta from sqlalchemy import desc from sqlalchemy import text @@ -49,6 +49,7 @@ class ModelFreeGameItem(ModelBase): return [] def as_dict(self): + is_new = bool(self.created_time and self.created_time >= datetime.now() - timedelta(hours=48)) return { "id": self.id, "external_id": self.external_id, @@ -66,6 +67,8 @@ class ModelFreeGameItem(ModelBase): "metacritic_score": self.metacritic_score, "metacritic_url": self.metacritic_url, "genres": self.genres, + "is_new": is_new, + "created_time": self.created_time.strftime("%Y-%m-%d %H:%M:%S") if self.created_time else "", "updated_time": self.updated_time.strftime("%Y-%m-%d %H:%M:%S") if self.updated_time else "", } @@ -127,8 +130,16 @@ class ModelFreeGameItem(ModelBase): @classmethod def replace_source_items(cls, source_name, items): with F.app.app_context(): - F.db.session.query(cls).filter_by(platform=source_name).delete(synchronize_session=False) - F.db.session.commit() + incoming_ids = { + str(item.get("external_id") or "") + for item in items + if str(item.get("external_id") or "") + } + query = F.db.session.query(cls).filter_by(platform=source_name) + if incoming_ids: + query.filter(~cls.external_id.in_(incoming_ids)).delete(synchronize_session=False) + else: + query.delete(synchronize_session=False) for item in items: cls.upsert(item) F.db.session.commit() diff --git a/templates/ff_freegame_main_list.html b/templates/ff_freegame_main_list.html index 8aa4418..b3a19f5 100644 --- a/templates/ff_freegame_main_list.html +++ b/templates/ff_freegame_main_list.html @@ -83,6 +83,13 @@ background: #16a34a; color: #fff; } + .ffg-badge-new { + left: 10px; + bottom: 10px; + background: #ef4444; + color: #fff; + box-shadow: 0 0 0 2px rgba(0, 0, 0, .18); + } .ffg-platform-epic { background: #2f313a; } .ffg-platform-steam { background: #1b4b91; color: #fff; } .ffg-platform-gog { background: #4a2876; } @@ -249,6 +256,9 @@ function gameCard(item) { const mcHtml = mcScore > 0 ? `MC ${Math.round(mcScore)}` : ""; + const newHtml = item.is_new + ? `NEW` + : ""; return `
@@ -256,6 +266,7 @@ function gameCard(item) { ${imageHtml} ${platformLabel(item.platform)} FREE + ${newHtml}
${escapeHtml(item.title)}