šŸ“¦āž”šŸ¦‹ Store and retrieve files on the Atmosphere

add JWT caching

ducky.ws 32469162 4a732253

Waiting for spindle ...
+33 -11
+2
src/commands/auth.sh
··· 1 1 #!/usr/bin/env bash 2 2 3 + # TODO: Refresh session on old token 4 + 3 5 # shellcheck disable=SC2120 4 6 function atfile.auth() { 5 7 override_username="$1"
+14 -8
src/shared/cache.sh
··· 11 11 } 12 12 13 13 function atfile.cache.del() { 14 - key="$(atfile.util.get_cache_path "$1")" 14 + key="$1" 15 15 16 - atfile.cache.debug "$1" "Deleting" 17 - [[ -f "$key" ]] && rm "$key" 16 + key_path="$(atfile.util.get_cache_path "$key")" 17 + 18 + atfile.cache.debug "$key" "Deleting" 19 + [[ -f "$key_path" ]] && rm "$key_path" 18 20 } 19 21 20 22 function atfile.cache.get() { 21 - key="$(atfile.util.get_cache_path "$1")" 23 + key="$1" 22 24 unset value 23 25 26 + key_path="$(atfile.util.get_cache_path "$key")" 27 + 28 + [[ -f "$key_path" ]] && value="$(cat "$key_path")" 24 29 atfile.cache.debug "$1" "Getting" "$value" 25 - [[ -f "$key" ]] && value="$(cat $key)" 26 30 echo "$value" 27 31 } 28 32 29 33 function atfile.cache.set() { 30 - key="$(atfile.util.get_cache_path "$1")" 34 + key="$1" 31 35 value="$2" 32 36 33 - atfile.cache.debug "$1" "Setting" "$value" 34 37 # shellcheck disable=SC2154 35 38 mkdir -p "$_path_cache" 36 - echo "$value" > "$key" 39 + key_path="$(atfile.util.get_cache_path "$key")" 40 + 41 + atfile.cache.debug "$key" "Setting" "$value" 42 + echo "$value" > "$key_path" 37 43 echo "$value" 38 44 }
+3
src/shared/util.sh
··· 877 877 _fmt_blob_url="$_fmt_blob_url_default" 878 878 879 879 atfile.say.debug "Overridden identity\n↳ DID: $_username\n↳ PDS: $_server\n↳ Blob URL: $_fmt_blob_url" 880 + 881 + atfile.say.debug "Deleting cached JWT for '$_username_original'..." 882 + atfile.cache.del "token" 880 883 } 881 884 882 885 # NOTE: This is to help during sourcing if atfile.uitl.override_actor() has
+14 -3
src/shared/xrpc.sh
··· 32 32 } 33 33 34 34 function atfile.xrpc.pds.jwt() { 35 - atfile.http.post \ 36 - "$_server/xrpc/com.atproto.server.createSession" \ 37 - '{"identifier": "'"$_username"'", "password": "'"$_password"'"}' | jq -r ".accessJwt" 35 + token="$(atfile.cache.get "token")" 36 + 37 + if [[ -z "$token" ]]; then 38 + atfile.say.debug "Generating JWT for '$_username'..." 39 + new_token="$(atfile.http.post \ 40 + "$_server/xrpc/com.atproto.server.createSession" \ 41 + '{"identifier": "'"$_username"'", "password": "'"$_password"'"}' | jq -r ".accessJwt")" 42 + 43 + token="$(atfile.cache.set "token" "$new_token")" 44 + else 45 + atfile.say.debug "Reusing cached JWT for '$_username'..." 46 + fi 47 + 48 + echo "$token" 38 49 } 39 50 40 51 function atfile.xrpc.pds.post() {