From 8606f596f38719d62d0f79fdb897ae3cea28c8e3 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sat, 16 Dec 2023 00:46:11 +0000 Subject: [PATCH] Package API: Add option to return desc as hypertext --- app/blueprints/api/endpoints.py | 11 +++++++++-- app/flatpages/help/api.md | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/blueprints/api/endpoints.py b/app/blueprints/api/endpoints.py index 7e86e826..19c2be56 100644 --- a/app/blueprints/api/endpoints.py +++ b/app/blueprints/api/endpoints.py @@ -33,11 +33,11 @@ from app.models import Tag, PackageState, PackageType, Package, db, PackageRelea PackageAlias from app.querybuilder import QueryBuilder from app.utils import is_package_page, get_int_or_abort, url_set_query, abs_url, is_yes, get_request_date +from app.utils.minetest_hypertext import html_to_minetest from . import bp from .auth import is_api_authd from .support import error, api_create_vcs_release, api_create_zip_release, api_create_screenshot, \ api_order_screenshots, api_edit_package, api_set_cover_image -from app.utils.minetest_hypertext import html_to_minetest def cors_allowed(f): @@ -99,7 +99,14 @@ def packages(): @is_package_page @cors_allowed def package_view(package): - return jsonify(package.as_dict(current_app.config["BASE_URL"])) + data = package.as_dict(current_app.config["BASE_URL"]) + if "formspec_version" in request.args: + formspec_version = request.args["formspec_version"] + include_images = is_yes(request.args.get("include_images", "true")) + html = render_markdown(package.desc) + data["long_description"] = html_to_minetest(html, formspec_version, include_images) + + return jsonify(data) @bp.route("/api/packages///hypertext/") diff --git a/app/flatpages/help/api.md b/app/flatpages/help/api.md index 6c13005a..6d2aadf0 100644 --- a/app/flatpages/help/api.md +++ b/app/flatpages/help/api.md @@ -78,6 +78,9 @@ curl -X DELETE https://content.minetest.net/api/delete-token/ \ * GET `/api/packages/` (List) * See [Package Queries](#package-queries) * GET `/api/packages///` (Read) + * Query arguments + * `formspec_version`: Optional. If present, `long_description` is returned a hypertext (see /hypertext/ below). + * `include_images`: Optional, defaults to true. Only used if `formspec_version` is provided. * PUT `/api/packages///` (Update) * Requires authentication. * JSON dictionary with any of these keys (all are optional, null to delete Nullables):