feat: bibliothek download type

This commit is contained in:
amyavi 2025-01-28 20:50:31 -03:00
parent 5bd6437d60
commit 6243a0705e
Signed by: amy
SSH key fingerprint: SHA256:CoLIqZWDYPZEhs1j1HQWwV0j1JhC3BFWcaUF7ZLZHJA
2 changed files with 38 additions and 5 deletions
scripts/_sources

View file

@ -0,0 +1,31 @@
#!/bin/sh
# Bibliothek is Paper's API for downloading builds
# https://docs.papermc.io/misc/downloads-api
_fetch_latest_build() {
builds_url="$1/builds"
debug "fetch: $builds_url"
BUILD_JSON="$(fetch -so- "$builds_url")"
# We have to read the variables like this because POSIX read
# doesn't support reading multiple variables at a time
for var in LATEST_BUILD LATEST_BUILD_FILENAME; do
read -r "${var?}"
done <<FETCH_LATEST_BUILD_HEREDOC
$(echo "$BUILD_JSON" \
| jq --raw-output --exit-status '.builds[-1] | "\(.build)\n\(.downloads?.application?.name)"')
FETCH_LATEST_BUILD_HEREDOC
}
_download_type_bibliothek() {
read_args endpoint project version
require_args endpoint project version
project_url="${arg_endpoint:?}/v2/projects/${arg_project:?}/versions/${arg_version:?}"
_fetch_latest_build "$project_url"
debug "latest file: $LATEST_BUILD_FILENAME ($LATEST_BUILD)"
download_url="$project_url/builds/$LATEST_BUILD/downloads/$LATEST_BUILD_FILENAME"
download "$download_url" "$1"
}

View file

@ -1,6 +1,7 @@
#!/bin/sh
# shellcheck disable=SC1091
. "$_SCRIPT_PATH"/_sources/_bibliothek.sh
. "$_SCRIPT_PATH"/_sources/_url.sh
. "$_SCRIPT_PATH"/_sources/_zip.sh
@ -59,9 +60,10 @@ download_type() {
# Since the args are part of the function's stdin, they will be
# be propagated into the _download_type_... functions.
case "$1" in
"url") _download_type_url "$2";;
"zip") _download_type_zip "$2";;
*) echo Invalid download type "$1"
return 1;;
"bibliothek") _download_type_bibliothek "$2";;
"url") _download_type_url "$2";;
"zip") _download_type_zip "$2";;
*) echo Invalid download type "$1"
return 1;;
esac
}
}