From 47b2d07e8979979eee6ed368c7da013f642c2649 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Mon, 1 Apr 2024 17:43:16 +0100 Subject: [PATCH] for-client API: Make screenshots a list of objects not URLs --- app/blueprints/api/endpoints.py | 2 +- app/models/packages.py | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/blueprints/api/endpoints.py b/app/blueprints/api/endpoints.py index f0a25dc2..fa646143 100644 --- a/app/blueprints/api/endpoints.py +++ b/app/blueprints/api/endpoints.py @@ -129,7 +129,7 @@ def package_view_client(package: Package): allowed_languages = set([x[0] for x in db.session.query(Language.id).all()]) lang = request.accept_languages.best_match(allowed_languages) - data = package.as_dict(current_app.config["BASE_URL"], version, lang=lang) + data = package.as_dict(current_app.config["BASE_URL"], version, lang=lang, screenshots_dict=True) formspec_version = get_int_or_abort(request.args["formspec_version"]) include_images = is_yes(request.args.get("include_images", "true")) diff --git a/app/models/packages.py b/app/models/packages.py index 38d1e9ed..d5218bf8 100644 --- a/app/models/packages.py +++ b/app/models/packages.py @@ -578,11 +578,16 @@ class Package(db.Model): return ret - def as_dict(self, base_url, version=None, lang="en"): + def as_dict(self, base_url, version=None, lang="en", screenshots_dict=False): tnurl = self.get_thumb_url(1, format="png") release = self.get_download_release(version=version) meta = self.get_translated(lang) + if screenshots_dict: + screenshots = [ss.as_short_dict(base_url) for ss in self.screenshots] + else: + screenshots = [base_url + ss.url for ss in self.screenshots] + return { "author": self.author.username, "maintainers": [x.username for x in self.maintainers], @@ -613,7 +618,7 @@ class Package(db.Model): "provides": sorted([x.name for x in self.provides]), "thumbnail": (base_url + tnurl) if tnurl is not None else None, - "screenshots": [base_url + ss.url for ss in self.screenshots], + "screenshots": screenshots, "url": base_url + self.get_url("packages.download"), "release": release and release.id, @@ -1196,6 +1201,12 @@ class PackageScreenshot(db.Model): "is_cover_image": self.package.cover_image == self, } + def as_short_dict(self, base_url=""): + return { + "title": self.title, + "url": base_url + self.url, + } + class PackageUpdateTrigger(enum.Enum): COMMIT = "New Commit"