summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLizzy Fleckenstein <lizzy@vlhl.dev>2026-05-26 01:52:31 +0200
committerLizzy Fleckenstein <lizzy@vlhl.dev>2026-05-26 01:52:31 +0200
commit6a8406c5b17cf9bc170b309dc8e58cffa244307e (patch)
tree6e6bad16f593c86bd95d2868a50e1325d0da4d9e
downloaddrasl-heads-main.tar.xz
-rwxr-xr-xcache.sh16
-rwxr-xr-xdrasl-heads.cgi31
-rwxr-xr-xhead.sh8
3 files changed, 55 insertions, 0 deletions
diff --git a/cache.sh b/cache.sh
new file mode 100755
index 0000000..c84fe71
--- /dev/null
+++ b/cache.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+set -o pipefail
+: "${CACHE_AGE:=300}"
+test -n "$CACHE_DIR" || exit 1
+cache="$CACHE_DIR/$(echo "$*" | base64)"
+if test -f "$cache"; then
+ now="$(date +%s)"
+ mod="$(stat -c %Y "$cache")"
+ if test $((mod + CACHE_AGE)) -gt "$now"; then
+ if ! test -s "$cache"; then
+ exit 1
+ fi
+ exec cat "$cache"
+ fi
+fi
+"$@" | tee "$cache"
diff --git a/drasl-heads.cgi b/drasl-heads.cgi
new file mode 100755
index 0000000..a6423b7
--- /dev/null
+++ b/drasl-heads.cgi
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+finish() {
+ echo "Status: $1"
+ echo "Content-type: $2"
+ echo
+ cat -
+ exit
+}
+
+echo "$REQUEST_URI" \
+ | sed -nE "s#$DRASL_HEADS_ROOT/([[:xdigit:]]{32})/([[:digit:]]+)#\1 \2#p" \
+ | {
+ IFS=' '
+ if ! read -r uuid size; then
+ echo "Bad Request" | finish "400 Bad Request" "text/plain"
+ fi
+
+ if test "$size" -gt 64; then
+ echo "Size Limit Exceeded" | finish "403 Forbidden" "text/plain"
+ fi
+
+ image="$(mktemp)"
+ trap 'rm $image' EXIT
+
+ if ./cache.sh ./head.sh "$uuid" "$size" 2>/dev/null > "$image"; then
+ finish "200 OK" "image/png" < "$image"
+ else
+ echo "Not Found" | finish "404 Not Found" "text/plain"
+ fi
+ }
diff --git a/head.sh b/head.sh
new file mode 100755
index 0000000..ccccb85
--- /dev/null
+++ b/head.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+set -o pipefail
+curl "$DRASL_BACKEND/session/minecraft/profile/$1" \
+ | jq -r '.properties[] | select(.name == "textures") | .value' \
+ | base64 -d \
+ | jq -r '.textures.SKIN.url' \
+ | xargs -n1 curl \
+ | magick - -scale $(($2 * 8)) -crop "$2"x"$2"+"$2"+"$2" -