#!/usr/bin/env bash function atfile.get() { key="$1" unset error # shellcheck disable=SC2154 atfile.say.debug "Getting record...\n↳ NSID: $_nsid_upload\n↳ Repo: $_username\n↳ Key: $key" record="$(com.atproto.repo.getRecord "$_username" "$_nsid_upload" "$key")" error="$(atfile.util.get_xrpc_error $? "$record")" [[ -n "$error" ]] && atfile.die.xrpc_error "Unable to get '$key'" "$error" if [[ -z "$error" ]]; then file_type="$(echo "$record" | jq -r '.value.file.mimeType')" did="$(echo "$record" | jq -r ".uri" | cut -d "/" -f 3)" key="$(atfile.util.get_rkey_from_at_uri "$(echo "$record" | jq -r ".uri")")" blob_uri="$(atfile.util.build_blob_uri "$did" "$(echo "$record" | jq -r ".value.blob.ref.\"\$link\"")")" cdn_uri="$(atfile.util.get_cdn_uri "$did" "$(echo "$record" | jq -r ".value.blob.ref.\"\$link\"")" "$file_type")" unset locked unset encrypted # shellcheck disable=SC2154 atfile.say.debug "Getting record...\n↳ NSID: $_nsid_lock\n↳ Repo: $_username\n↳ Key: $key" locked_record="$(com.atproto.repo.getRecord "$_username" "$_nsid_lock" "$key")" # shellcheck disable=SC2181 if [[ $? == 0 ]] && [[ -n "$locked_record" ]]; then if [[ $(echo "$locked_record" | jq -r ".value.lock") == true ]]; then locked="$(atfile.util.get_yn 1)" else locked="$(atfile.util.get_yn 0)" fi fi if [[ "$file_type" == "application/prs.atfile.gpg-crypt" ]]; then encrypted="$(atfile.util.get_yn 1)" else encrypted="$(atfile.util.get_yn 0)" fi # shellcheck disable=SC2154 if [[ $_output_json == 1 ]]; then browser_accessible=$(atfile.util.get_yn "$(atfile.util.is_url_accessible_in_browser "$blob_uri")") echo "{ \"encrypted\": $encrypted, \"locked\": $locked, \"upload\": $(echo "$record" | jq -r ".value"), \"url\": { \"blob\": \"$blob_uri\", \"browser_accessible\": $browser_accessible, \"cdn\": { \"bsky\": \"$cdn_uri\" } } }" | jq else file_date="$(echo "$record" | jq -r '.value.file.modifiedAt')" file_hash="$(echo "$record" | jq -r '.value.checksum.hash')" file_hash_type="$(echo "$record" | jq -r '.value.checksum.algo')" [[ "$file_hash_type" == "null" ]] && file_hash_type="$(echo "$record" | jq -r '.value.checksum.type')" file_hash_pretty="$file_hash ($file_hash_type)" file_name="$(echo "$record" | jq -r '.value.file.name')" file_name_pretty="$(atfile.util.get_file_name_pretty "$(echo "$record" | jq -r '.value')")" file_size="$(echo "$record" | jq -r '.value.file.size')" file_size_pretty="$(atfile.util.get_file_size_pretty "$file_size")" unset finger_type header="$file_name_pretty" if [[ $(atfile.util.is_null_or_empty "$file_hash_type") == 1 ]] || [[ "$file_hash_type" == "md5" && ${#file_hash} != 32 ]] || [[ "$file_hash_type" == "none" ]]; then file_hash_pretty="(None)" fi if [[ "$(echo "$record" | jq -r ".value.finger")" != "null" ]]; then finger_type="$(echo "$record" | jq -r ".value.finger.\"\$type\"" | cut -d "#" -f 2)" fi echo "$header" atfile.util.print_blob_url_output "$blob_uri" [[ -n "$cdn_uri" ]] && echo -e " ↳ CDN: $cdn_uri" # shellcheck disable=SC2154 echo -e "↳ URI: atfile://$_username/$key" echo -e "↳ File: $key" echo -e " ↳ Name: $file_name" echo -e " ↳ Type: $file_type" echo -e " ↳ Size: $file_size_pretty" echo -e " ↳ Date: $(atfile.util.get_date "$file_date" "%Y-%m-%d %H:%M:%S %Z")" echo -e " ↳ Hash: $file_hash_pretty" echo -e "↳ Locked: $locked" echo -e "↳ Encrypted: $encrypted" if [[ -z "$finger_type" ]]; then echo -e "↳ Source: (Unknown)" else case $finger_type in "browser") finger_browser_uas="$(echo "$record" | jq -r ".value.finger.userAgent")" [[ -z $finger_browser_uas || $finger_browser_uas == "null" ]] && finger_browser_uas="(Unknown)" echo -e "↳ Source: $finger_browser_uas" ;; "machine") finger_machine_app="$(echo "$record" | jq -r ".value.finger.app")" finger_machine_host="$(echo "$record" | jq -r ".value.finger.host")" finger_machine_os="$(echo "$record" | jq -r ".value.finger.os")" [[ -z $finger_machine_app || $finger_machine_app == "null" ]] && finger_machine_app="(Unknown)" echo -e "↳ Source: $finger_machine_app" [[ -n $finger_machine_host && $finger_machine_host != "null" ]] && echo -e " ↳ Host: $finger_machine_host" [[ -n $finger_machine_os && $finger_machine_os != "null" ]] && echo -e " ↳ OS: $finger_machine_os" ;; *) echo -e "↳ Source: (Unknown)" ;; esac fi fi fi } function atfile.get_url() { key="$1" unset error # shellcheck disable=SC2154 atfile.say.debug "Getting record...\n↳ NSID: $_nsid_upload\n↳ Repo: $_username\n↳ Key: $key" record="$(com.atproto.repo.getRecord "$_username" "$_nsid_upload" "$key")" error="$(atfile.util.get_xrpc_error $? "$record")" if [[ -z "$error" ]]; then blob_url="$(atfile.util.build_blob_uri "$(echo "$record" | jq -r ".uri" | cut -d "/" -f 3)" "$(echo "$record" | jq -r ".value.blob.ref.\"\$link\"")")" # shellcheck disable=SC2154 if [[ $_output_json == 1 ]]; then echo -e "{\"url\": \"$blob_url\" }" | jq else echo "$blob_url" fi else atfile.die.xrpc_error "Unable to get '$key'" "$error" fi }