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 = [
|
||||
pkgs.curl
|
||||
pkgs.coreutils
|
||||
pkgs.python3
|
||||
pkgs.librsvg
|
||||
];
|
||||
script = ''
|
||||
ICON=/etc/hyperhive/icon.svg
|
||||
|
|
@ -452,9 +452,16 @@
|
|||
exit 0
|
||||
fi
|
||||
TOKEN=$(cat "$TOKEN_FILE")
|
||||
# Base64-encode the SVG and wrap in a data URI.
|
||||
IMAGE=$(base64 -w 0 < "$ICON")
|
||||
DATA_URI="data:image/svg+xml;base64,$IMAGE"
|
||||
# Rasterize SVG → PNG (Forgejo's Go image library can't decode SVG).
|
||||
PNG=$(mktemp --suffix=.png)
|
||||
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 \
|
||||
-X POST "$FORGE_URL/api/v1/user/avatar" \
|
||||
-H "Authorization: token $TOKEN" \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue