mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-24 23:11:33 +01:00
parent
9c2c8c21f1
commit
4c109d6bd3
@ -417,21 +417,23 @@ class Package(db.Model):
|
|||||||
for e in PackagePropertyKey:
|
for e in PackagePropertyKey:
|
||||||
setattr(self, e.name, getattr(package, e.name))
|
setattr(self, e.name, getattr(package, e.name))
|
||||||
|
|
||||||
def getAsDictionaryShort(self, base_url, protonum=None):
|
def getAsDictionaryShort(self, base_url, version=None, protonum=None):
|
||||||
tnurl = self.getThumbnailURL(1)
|
tnurl = self.getThumbnailURL(1)
|
||||||
|
release = self.getDownloadRelease(version=version, protonum=protonum)
|
||||||
return {
|
return {
|
||||||
"name": self.name,
|
"name": self.name,
|
||||||
"title": self.title,
|
"title": self.title,
|
||||||
"author": self.author.display_name,
|
"author": self.author.display_name,
|
||||||
"short_description": self.short_desc,
|
"short_description": self.short_desc,
|
||||||
"type": self.type.toName(),
|
"type": self.type.toName(),
|
||||||
"release": self.getDownloadRelease(protonum).id if self.getDownloadRelease(protonum) is not None else None,
|
"release": release and release.id,
|
||||||
"thumbnail": (base_url + tnurl) if tnurl is not None else None,
|
"thumbnail": (base_url + tnurl) if tnurl is not None else None,
|
||||||
"score": round(self.score * 10) / 10
|
"score": round(self.score * 10) / 10
|
||||||
}
|
}
|
||||||
|
|
||||||
def getAsDictionary(self, base_url, protonum=None):
|
def getAsDictionary(self, base_url, version=None, protonum=None):
|
||||||
tnurl = self.getThumbnailURL(1)
|
tnurl = self.getThumbnailURL(1)
|
||||||
|
release = self.getDownloadRelease(version=version, protonum=protonum)
|
||||||
return {
|
return {
|
||||||
"author": self.author.display_name,
|
"author": self.author.display_name,
|
||||||
"name": self.name,
|
"name": self.name,
|
||||||
@ -454,7 +456,7 @@ class Package(db.Model):
|
|||||||
"screenshots": [base_url + ss.url for ss in self.screenshots],
|
"screenshots": [base_url + ss.url for ss in self.screenshots],
|
||||||
|
|
||||||
"url": base_url + self.getDownloadURL(),
|
"url": base_url + self.getDownloadURL(),
|
||||||
"release": self.getDownloadRelease(protonum).id if self.getDownloadRelease(protonum) is not None else None,
|
"release": release and release.id,
|
||||||
|
|
||||||
"score": round(self.score * 10) / 10
|
"score": round(self.score * 10) / 10
|
||||||
}
|
}
|
||||||
@ -503,9 +505,8 @@ class Package(db.Model):
|
|||||||
return url_for("package_download_page",
|
return url_for("package_download_page",
|
||||||
author=self.author.username, name=self.name)
|
author=self.author.username, name=self.name)
|
||||||
|
|
||||||
def getDownloadRelease(self, protonum=None):
|
def getDownloadRelease(self, version=None, protonum=None):
|
||||||
version = None
|
if version is None and protonum is not None:
|
||||||
if protonum is not None:
|
|
||||||
version = MinetestRelease.query.filter(MinetestRelease.protocol >= int(protonum)).first()
|
version = MinetestRelease.query.filter(MinetestRelease.protocol >= int(protonum)).first()
|
||||||
if version is not None:
|
if version is not None:
|
||||||
version = version.id
|
version = version.id
|
||||||
@ -514,7 +515,7 @@ class Package(db.Model):
|
|||||||
|
|
||||||
|
|
||||||
for rel in self.releases:
|
for rel in self.releases:
|
||||||
if rel.approved and (protonum is None or
|
if rel.approved and (version is None or
|
||||||
((rel.min_rel is None or rel.min_rel_id <= version) and \
|
((rel.min_rel is None or rel.min_rel_id <= version) and \
|
||||||
(rel.max_rel is None or rel.max_rel_id >= version))):
|
(rel.max_rel is None or rel.max_rel_id >= version))):
|
||||||
return rel
|
return rel
|
||||||
|
@ -35,6 +35,17 @@ class QueryBuilder:
|
|||||||
if self.search is not None and self.search.strip() == "":
|
if self.search is not None and self.search.strip() == "":
|
||||||
self.search = None
|
self.search = None
|
||||||
|
|
||||||
|
def getMinetestVersion(self):
|
||||||
|
if not self.protocol_version:
|
||||||
|
return None
|
||||||
|
|
||||||
|
self.protocol_version = int(self.protocol_version)
|
||||||
|
version = MinetestRelease.query.filter(MinetestRelease.protocol>=self.protocol_version).first()
|
||||||
|
if version is not None:
|
||||||
|
return version.id
|
||||||
|
else:
|
||||||
|
return 10000000
|
||||||
|
|
||||||
def buildPackageQuery(self):
|
def buildPackageQuery(self):
|
||||||
query = Package.query.filter_by(soft_deleted=False, approved=True)
|
query = Package.query.filter_by(soft_deleted=False, approved=True)
|
||||||
|
|
||||||
@ -69,14 +80,9 @@ class QueryBuilder:
|
|||||||
query = query.filter(Package.media_license.has(License.is_foss == True))
|
query = query.filter(Package.media_license.has(License.is_foss == True))
|
||||||
|
|
||||||
if self.protocol_version:
|
if self.protocol_version:
|
||||||
self.protocol_version = int(self.protocol_version)
|
version = self.getMinetestVersion()
|
||||||
version = MinetestRelease.query.filter(MinetestRelease.protocol>=self.protocol_version).first()
|
|
||||||
if version is not None:
|
|
||||||
version = version.id
|
|
||||||
else:
|
|
||||||
version = 10000000
|
|
||||||
|
|
||||||
query = query.join(Package.releases) \
|
query = query.join(Package.releases) \
|
||||||
|
.filter(PackageRelease.approved==True) \
|
||||||
.filter(or_(PackageRelease.min_rel_id==None, PackageRelease.min_rel_id<=version)) \
|
.filter(or_(PackageRelease.min_rel_id==None, PackageRelease.min_rel_id<=version)) \
|
||||||
.filter(or_(PackageRelease.max_rel_id==None, PackageRelease.max_rel_id>=version))
|
.filter(or_(PackageRelease.max_rel_id==None, PackageRelease.max_rel_id>=version))
|
||||||
|
|
||||||
|
@ -26,9 +26,10 @@ from app.querybuilder import QueryBuilder
|
|||||||
def api_packages_page():
|
def api_packages_page():
|
||||||
qb = QueryBuilder(request.args)
|
qb = QueryBuilder(request.args)
|
||||||
query = qb.buildPackageQuery()
|
query = qb.buildPackageQuery()
|
||||||
|
ver = qb.getMinetestVersion()
|
||||||
|
|
||||||
pkgs = [package.getAsDictionaryShort(app.config["BASE_URL"], request.args.get("protocol_version")) \
|
pkgs = [package.getAsDictionaryShort(app.config["BASE_URL"], version=ver) \
|
||||||
for package in query.all() if package.getDownloadRelease() is not None]
|
for package in query.all()]
|
||||||
return jsonify(pkgs)
|
return jsonify(pkgs)
|
||||||
|
|
||||||
@app.route("/api/packages/<author>/<name>/")
|
@app.route("/api/packages/<author>/<name>/")
|
||||||
|
Loading…
Reference in New Issue
Block a user