#!/usr/bin/env bash # PDS function atfile.xrpc.pds.blob() { file="$1" type="$2" lexi="$3" [[ -z $lexi ]] && lexi="com.atproto.repo.uploadBlob" [[ -z $type ]] && type="*/*" atfile.http.upload \ "$_server/xrpc/$lexi" \ "$file" \ "Bearer $(atfile.xrpc.pds.jwt)" \ "$type" | jq } function atfile.xrpc.pds.get() { lexi="$1" query="$2" type="$3" endpoint="$4" [[ -z $endpoint ]] && endpoint="$_server" atfile.http.get \ "$endpoint/xrpc/$lexi?$query" \ "Bearer $(atfile.xrpc.pds.jwt)" \ "$type" | jq } # shellcheck disable=SC2120 function atfile.xrpc.pds.jwt() { token="$1" [[ -z "$token" ]] && token="$(atfile.util.get_token_cache "access")" if [[ -z "$token" ]]; then atfile.say.debug "Generating JWT for '$_username'..." new_session="$(atfile.http.post \ "$_server/xrpc/com.atproto.server.createSession" \ '{"identifier": "'"$_username"'", "password": "'"$_password"'"}')" token_access="$(echo "$new_session" | jq -r ".accessJwt")" token_refresh="$(echo "$new_session" | jq -r ".refreshJwt")" atfile.say.debug "Generated JWT\n↳ DID: $_username\n↳ Access: $token_access\n↳ Refresh: $token_refresh" atfile.util.set_token_cache "$_username" "$token_access" "$token_refresh" > /dev/null token="$token_access" else if [[ $_username == "$(atfile.util.get_token_cache "did")" ]]; then atfile.say.debug "Reusing cached JWT for '$_username'..." else atfile.say.debug "Deleting JWT cache (DID does not match)..." atfile.cache.del "token" atfile.xrpc.pds.jwt fi fi echo "$token" } function atfile.xrpc.pds.post() { lexi="$1" data="$2" type="$3" auth="$4" [[ -z $type ]] && type="application/json" [[ -z $auth ]] && auth="Bearer $(atfile.xrpc.pds.jwt)" curl -s -X POST "$_server/xrpc/$lexi" \ -H "Authorization: $auth" \ -H "Content-Type: $type" \ -H "User-Agent: $(atfile.util.get_uas)" \ -d "$data" | jq } # AppView ## Bluesky function atfile.xrpc.bsky.get() { lexi="$1" query="$2" type="$3" appview="$4" # shellcheck disable=SC2154 [[ -z "$appview" ]] && appview="$_endpoint_appview" atfile.http.get \ "$appview/xrpc/$lexi?$query" \ "" \ "$type" | jq }