harness: rasterize SVG icon to PNG for Forgejo avatar upload (fixes #197)
This commit is contained in:
parent
03fec39405
commit
94f5f53ca9
1 changed files with 11 additions and 4 deletions
|
|
@ -431,7 +431,7 @@
|
||||||
path = [
|
path = [
|
||||||
pkgs.curl
|
pkgs.curl
|
||||||
pkgs.coreutils
|
pkgs.coreutils
|
||||||
pkgs.python3
|
pkgs.librsvg
|
||||||
];
|
];
|
||||||
script = ''
|
script = ''
|
||||||
ICON=/etc/hyperhive/icon.svg
|
ICON=/etc/hyperhive/icon.svg
|
||||||
|
|
@ -452,9 +452,16 @@
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
TOKEN=$(cat "$TOKEN_FILE")
|
TOKEN=$(cat "$TOKEN_FILE")
|
||||||
# Base64-encode the SVG and wrap in a data URI.
|
# Rasterize SVG → PNG (Forgejo's Go image library can't decode SVG).
|
||||||
IMAGE=$(base64 -w 0 < "$ICON")
|
PNG=$(mktemp --suffix=.png)
|
||||||
DATA_URI="data:image/svg+xml;base64,$IMAGE"
|
if ! rsvg-convert -f png -w 256 -h 256 "$ICON" -o "$PNG" 2>/dev/null; then
|
||||||
|
echo "forge-avatar-sync: rsvg-convert failed; skipping"
|
||||||
|
rm -f "$PNG"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
IMAGE=$(base64 -w 0 < "$PNG")
|
||||||
|
rm -f "$PNG"
|
||||||
|
DATA_URI="data:image/png;base64,$IMAGE"
|
||||||
RESP=$(curl -sf --max-time 10 \
|
RESP=$(curl -sf --max-time 10 \
|
||||||
-X POST "$FORGE_URL/api/v1/user/avatar" \
|
-X POST "$FORGE_URL/api/v1/user/avatar" \
|
||||||
-H "Authorization: token $TOKEN" \
|
-H "Authorization: token $TOKEN" \
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue