mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-22 22:12:24 +01:00
for-client API: Make screenshots a list of objects not URLs
This commit is contained in:
parent
1be4155ab0
commit
47b2d07e89
@ -129,7 +129,7 @@ def package_view_client(package: Package):
|
|||||||
allowed_languages = set([x[0] for x in db.session.query(Language.id).all()])
|
allowed_languages = set([x[0] for x in db.session.query(Language.id).all()])
|
||||||
lang = request.accept_languages.best_match(allowed_languages)
|
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"])
|
formspec_version = get_int_or_abort(request.args["formspec_version"])
|
||||||
include_images = is_yes(request.args.get("include_images", "true"))
|
include_images = is_yes(request.args.get("include_images", "true"))
|
||||||
|
@ -578,11 +578,16 @@ class Package(db.Model):
|
|||||||
|
|
||||||
return ret
|
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")
|
tnurl = self.get_thumb_url(1, format="png")
|
||||||
release = self.get_download_release(version=version)
|
release = self.get_download_release(version=version)
|
||||||
meta = self.get_translated(lang)
|
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 {
|
return {
|
||||||
"author": self.author.username,
|
"author": self.author.username,
|
||||||
"maintainers": [x.username for x in self.maintainers],
|
"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]),
|
"provides": sorted([x.name for x in self.provides]),
|
||||||
"thumbnail": (base_url + tnurl) if tnurl is not None else None,
|
"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"),
|
"url": base_url + self.get_url("packages.download"),
|
||||||
"release": release and release.id,
|
"release": release and release.id,
|
||||||
@ -1196,6 +1201,12 @@ class PackageScreenshot(db.Model):
|
|||||||
"is_cover_image": self.package.cover_image == self,
|
"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):
|
class PackageUpdateTrigger(enum.Enum):
|
||||||
COMMIT = "New Commit"
|
COMMIT = "New Commit"
|
||||||
|
Loading…
Reference in New Issue
Block a user