2 # Copyright (C) 2018 rubenwardy
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 from flask_user import *
21 from app.models import *
22 from app.utils import is_package_page
23 from app.querybuilder import QueryBuilder
25 @app.route("/api/packages/")
26 def api_packages_page():
27 qb = QueryBuilder(request.args)
28 query = qb.buildPackageQuery()
30 pkgs = [package.getAsDictionaryShort(app.config["BASE_URL"]) \
31 for package in query.all() if package.getDownloadRelease() is not None]
34 @app.route("/api/packages/<author>/<name>/")
36 def api_package_page(package):
37 return jsonify(package.getAsDictionary(app.config["BASE_URL"]))
40 @app.route("/api/topics/")
41 def api_topics_page():
42 query = ForumTopic.query \
43 .order_by(db.asc(ForumTopic.wip), db.asc(ForumTopic.name), db.asc(ForumTopic.title))
44 pkgs = [t.getAsDictionary() for t in query.all()]
48 @app.route("/api/topic_discard/", methods=["POST"])
50 def topic_set_discard():
51 tid = request.args.get("tid")
52 discard = request.args.get("discard")
53 if tid is None or discard is None:
56 topic = ForumTopic.query.get(tid)
57 if not topic.checkPerm(current_user, Permission.TOPIC_DISCARD):
60 topic.discarded = discard == "true"
63 return jsonify(topic.getAsDictionary())
66 @app.route("/api/minetest_versions/")
67 def api_minetest_versions_page():
68 return jsonify([{ "name": rel.name, "protocol_version": rel.protocol }\
69 for rel in MinetestRelease.query.all() if rel.getActual() is not None])