From 6866c0665d58013106c0f74d9e4e58c4227d4de7 Mon Sep 17 00:00:00 2001
From: Elliu <elliu@hashi.re>
Date: Mon, 1 May 2023 16:24:24 +0200
Subject: [PATCH] stpkg: don't ask multiple times for the token

Tried to modify global STPKG_TOKEN in subshell in __upload_file, so
didn't work
---
 stpkg | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/stpkg b/stpkg
index 875515b..c26f531 100755
--- a/stpkg
+++ b/stpkg
@@ -233,9 +233,9 @@ __upload_file() {
     fi
 
     # TODO: Use jq here
-    curl -s -X POST -H \
+    MXC=$(curl -s -X POST -H \
         "Content-Type: $TYPE" --data-binary "@$FILE" "https://$STPKG_HOMESERV/_matrix/media/r0/upload?access_token=$STPKG_TOKEN" | \
-        tee /tmp/toto | python -c "import sys, json; print(json.load(sys.stdin)['content_uri'])"
+        tee /tmp/toto | python -c "import sys, json; print(json.load(sys.stdin)['content_uri'])")
     [ $? -ne 0 ] && die "Failed to upload sticker $NAME for pack $PACK_NAME to $STPKG_HOMESERV"
 }
 
@@ -686,7 +686,8 @@ process_sticker_file() {
     DEST_HEIGHT=$(file_get_height "$TEMP")
 
     # Upload the transformed file
-    local MXC=$(__upload_file "$DEST_TYPE" "$TEMP" "$NAME")
+    local MXC
+    __upload_file "$DEST_TYPE" "$TEMP" "$NAME"
     rm "$TEMP"
 
     JSON_REF=$(create_sticker_json "$PACK_NAME" "$NAME" "$DEST_WIDTH" "$DEST_HEIGHT" "$DEST_TYPE" "$MXC")
-- 
GitLab