mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-22 22:12:24 +01:00
Add all releases API
This commit is contained in:
parent
adcbf7455e
commit
4d2833de88
@ -20,7 +20,7 @@ from sqlalchemy.sql.expression import func
|
||||
|
||||
from app import csrf
|
||||
from app.utils.markdown import render_markdown
|
||||
from app.models import Tag, PackageState, PackageType, Package, db, PackageRelease, Permission, ForumTopic, MinetestRelease, APIToken, PackageScreenshot, License, ContentWarning
|
||||
from app.models import Tag, PackageState, PackageType, Package, db, PackageRelease, Permission, ForumTopic, MinetestRelease, APIToken, PackageScreenshot, License, ContentWarning, User
|
||||
from app.querybuilder import QueryBuilder
|
||||
from app.utils import is_package_page
|
||||
from . import bp
|
||||
@ -142,6 +142,28 @@ def markdown():
|
||||
return render_markdown(request.data.decode("utf-8"))
|
||||
|
||||
|
||||
@bp.route("/api/releases/")
|
||||
def list_all_releases():
|
||||
query = PackageRelease.query.filter_by(approved=True) \
|
||||
.filter(PackageRelease.package.has(state=PackageState.APPROVED)) \
|
||||
.order_by(db.desc(PackageRelease.releaseDate))
|
||||
|
||||
if "author" in request.args:
|
||||
author = User.query.filter_by(username=request.args["author"]).first()
|
||||
if author is None:
|
||||
abort(404)
|
||||
query = query.filter(PackageRelease.package.has(author=author))
|
||||
|
||||
if "maintainer" in request.args:
|
||||
maintainer = User.query.filter_by(username=request.args["maintainer"]).first()
|
||||
if maintainer is None:
|
||||
abort(404)
|
||||
query = query.join(Package)
|
||||
query = query.filter(Package.maintainers.any(id=maintainer.id))
|
||||
|
||||
return jsonify([ rel.getLongAsDictionary() for rel in query.limit(30).all() ])
|
||||
|
||||
|
||||
@bp.route("/api/packages/<author>/<name>/releases/")
|
||||
@is_package_page
|
||||
def list_releases(package):
|
||||
|
@ -70,7 +70,7 @@ Tokens can be attained by visiting [Settings > API Tokens](/user/tokens/).
|
||||
Examples:
|
||||
|
||||
```bash
|
||||
# Edit packages
|
||||
# Edit package
|
||||
curl -X PUT http://localhost:5123/api/packages/username/name/ \
|
||||
-H "Authorization: Bearer YOURTOKEN" -H "Content-Type: application/json" \
|
||||
-d '{ "title": "Foo bar", "tags": ["pvp", "survival"], "license": "MIT" }'
|
||||
@ -107,7 +107,11 @@ Supported query parameters:
|
||||
|
||||
## Releases
|
||||
|
||||
* GET `/api/packages/<username>/<name>/releases/` (List)
|
||||
* GET `/api/releases/` (List)
|
||||
* Limited to 30 most recent releases.
|
||||
* Optional arguments:
|
||||
* `author`: Filter by author
|
||||
* `maintainer`: Filter by maintainer
|
||||
* Returns array of release dictionaries with keys:
|
||||
* `id`: release ID
|
||||
* `title`: human-readable title
|
||||
@ -117,6 +121,12 @@ Supported query parameters:
|
||||
* `downloads`: number of downloads
|
||||
* `min_minetest_version`: dict or null, minimum supported minetest version (inclusive).
|
||||
* `max_minetest_version`: dict or null, minimum supported minetest version (inclusive).
|
||||
* `package`
|
||||
* `author`: author username.
|
||||
* `name`
|
||||
* `type`: `mod`, `game`, or `txp`
|
||||
* GET `/api/packages/<username>/<name>/releases/` (List)
|
||||
* Returns array of release dictionaries, see above, but without package info.
|
||||
* GET `/api/packages/<username>/<name>/releases/<id>/` (Read)
|
||||
* POST `/api/packages/<username>/<name>/releases/new/` (Create)
|
||||
* Requires authentication.
|
||||
|
@ -835,6 +835,19 @@ class PackageRelease(db.Model):
|
||||
"max_minetest_version": self.max_rel and self.max_rel.getAsDictionary(),
|
||||
}
|
||||
|
||||
def getLongAsDictionary(self):
|
||||
return {
|
||||
"id": self.id,
|
||||
"title": self.title,
|
||||
"url": self.url if self.url != "" else None,
|
||||
"release_date": self.releaseDate.isoformat(),
|
||||
"commit": self.commit_hash,
|
||||
"downloads": self.downloads,
|
||||
"min_minetest_version": self.min_rel and self.min_rel.getAsDictionary(),
|
||||
"max_minetest_version": self.max_rel and self.max_rel.getAsDictionary(),
|
||||
"package": self.package.getAsDictionaryKey()
|
||||
}
|
||||
|
||||
def getEditURL(self):
|
||||
return url_for("packages.edit_release",
|
||||
author=self.package.author.username,
|
||||
|
Loading…
Reference in New Issue
Block a user