mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-23 06:22: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 import csrf
|
||||||
from app.utils.markdown import render_markdown
|
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.querybuilder import QueryBuilder
|
||||||
from app.utils import is_package_page
|
from app.utils import is_package_page
|
||||||
from . import bp
|
from . import bp
|
||||||
@ -142,6 +142,28 @@ def markdown():
|
|||||||
return render_markdown(request.data.decode("utf-8"))
|
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/")
|
@bp.route("/api/packages/<author>/<name>/releases/")
|
||||||
@is_package_page
|
@is_package_page
|
||||||
def list_releases(package):
|
def list_releases(package):
|
||||||
|
@ -70,7 +70,7 @@ Tokens can be attained by visiting [Settings > API Tokens](/user/tokens/).
|
|||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Edit packages
|
# Edit package
|
||||||
curl -X PUT http://localhost:5123/api/packages/username/name/ \
|
curl -X PUT http://localhost:5123/api/packages/username/name/ \
|
||||||
-H "Authorization: Bearer YOURTOKEN" -H "Content-Type: application/json" \
|
-H "Authorization: Bearer YOURTOKEN" -H "Content-Type: application/json" \
|
||||||
-d '{ "title": "Foo bar", "tags": ["pvp", "survival"], "license": "MIT" }'
|
-d '{ "title": "Foo bar", "tags": ["pvp", "survival"], "license": "MIT" }'
|
||||||
@ -107,7 +107,11 @@ Supported query parameters:
|
|||||||
|
|
||||||
## Releases
|
## 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:
|
* Returns array of release dictionaries with keys:
|
||||||
* `id`: release ID
|
* `id`: release ID
|
||||||
* `title`: human-readable title
|
* `title`: human-readable title
|
||||||
@ -117,6 +121,12 @@ Supported query parameters:
|
|||||||
* `downloads`: number of downloads
|
* `downloads`: number of downloads
|
||||||
* `min_minetest_version`: dict or null, minimum supported minetest version (inclusive).
|
* `min_minetest_version`: dict or null, minimum supported minetest version (inclusive).
|
||||||
* `max_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)
|
* GET `/api/packages/<username>/<name>/releases/<id>/` (Read)
|
||||||
* POST `/api/packages/<username>/<name>/releases/new/` (Create)
|
* POST `/api/packages/<username>/<name>/releases/new/` (Create)
|
||||||
* Requires authentication.
|
* Requires authentication.
|
||||||
|
@ -835,6 +835,19 @@ class PackageRelease(db.Model):
|
|||||||
"max_minetest_version": self.max_rel and self.max_rel.getAsDictionary(),
|
"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):
|
def getEditURL(self):
|
||||||
return url_for("packages.edit_release",
|
return url_for("packages.edit_release",
|
||||||
author=self.package.author.username,
|
author=self.package.author.username,
|
||||||
|
Loading…
Reference in New Issue
Block a user