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

Configure Feed

Select the types of activity you want to include in your feed.

refactor error handling

Ducky a1fa28eb 268a96f0

+38 -35
+6 -1
src/commands/blob.sh
··· 81 81 fi 82 82 83 83 atfile.say.debug "Uploading blob...\n↳ File: $file" 84 - com.atproto.sync.uploadBlob "$file" | jq 84 + result="$(com.atproto.sync.uploadBlob "$file")" 85 + error="$(atfile.util.get_xrpc_error $? "$result")" 86 + 87 + [[ -n "$error" ]] && atfile.die.xrpc_error "Unable to upload blob" "$error" 88 + 89 + echo "$result" | jq 85 90 }
+23 -25
src/commands/download.sh
··· 3 3 function atfile.download() { 4 4 key="$1" 5 5 decrypt=$2 6 - success=1 7 6 downloaded_file="" 8 7 9 8 # shellcheck disable=SC2154 10 9 atfile.say.debug "Getting record...\n↳ NSID: $_nsid_upload\n↳ Repo: $_username\n↳ Key: $key" 11 10 record="$(com.atproto.repo.getRecord "$_username" "$_nsid_upload" "$key")" 12 - [[ $? != 0 || -z "$record" || "$record" == "{}" || "$record" == *"\"error\":"* ]] && success=0 11 + error="$(atfile.util.get_xrpc_error $? "$record")" 13 12 14 - if [[ $success == 1 ]]; then 15 - blob_uri="$(atfile.util.build_blob_uri "$(echo "$record" | jq -r ".uri" | cut -d "/" -f 3)" "$(echo "$record" | jq -r ".value.blob.ref.\"\$link\"")")" 16 - file_name="$(echo "$record" | jq -r '.value.file.name')" 17 - key="$(atfile.util.get_rkey_from_at_uri "$(echo "$record" | jq -r ".uri")")" 18 - downloaded_file="$(atfile.util.build_out_filename "$key" "$file_name")" 13 + [[ -n "$error" ]] && atfile.die.xrpc_error "Unable to download '$key'" "$error" 19 14 20 - curl -H "User-Agent: $(atfile.util.get_uas)" --silent "$blob_uri" -o "$downloaded_file" 21 - # shellcheck disable=SC2181 22 - [[ $? != 0 ]] && success=0 15 + blob_uri="$(atfile.util.build_blob_uri "$(echo "$record" | jq -r ".uri" | cut -d "/" -f 3)" "$(echo "$record" | jq -r ".value.blob.ref.\"\$link\"")")" 16 + file_name="$(echo "$record" | jq -r '.value.file.name')" 17 + key="$(atfile.util.get_rkey_from_at_uri "$(echo "$record" | jq -r ".uri")")" 18 + downloaded_file="$(atfile.util.build_out_filename "$key" "$file_name")" 19 + 20 + curl -H "User-Agent: $(atfile.util.get_uas)" --silent "$blob_uri" -o "$downloaded_file" 21 + # shellcheck disable=SC2181 22 + if [[ $? != 0 ]]; then 23 + [[ -f "$downloaded_file" ]] && rm -f "$downloaded_file" 24 + atfile.die "Unable to download '$key'" 23 25 fi 24 26 25 - if [[ $decrypt == 1 && $success == 1 ]]; then 27 + if [[ $decrypt == 1 ]]; then 26 28 new_downloaded_file="$(echo "$downloaded_file" | sed -s s/.gpg//)" 27 29 28 30 gpg --quiet --output "$new_downloaded_file" --decrypt "$downloaded_file" 29 31 30 32 # shellcheck disable=SC2181 31 33 if [[ $? != 0 ]]; then 32 - success=0 34 + [[ -f "$downloaded_file" ]] && rm -f "$downloaded_file" 35 + atfile.die "Unable to decrypt '$key'" 33 36 else 34 37 rm -f "$downloaded_file" 35 38 downloaded_file="$new_downloaded_file" 36 39 fi 37 40 fi 38 41 39 - if [[ $success == 1 ]]; then 40 - # shellcheck disable=SC2154 41 - if [[ $_output_json == 1 ]]; then 42 - is_decrypted="false" 43 - [[ $decrypt == 1 ]] && is_decrypted="true" 44 - echo -e "{ \"decrypted\": $is_decrypted, \"name\": \"$(basename "${downloaded_file}")\", \"path\": \"$(atfile.util.get_realpath "${downloaded_file}")\" }" | jq 45 - else 46 - echo -e "Downloaded: $key" 47 - [[ $decrypt == 1 ]] && echo "Decrypted: $downloaded_file" 48 - echo -e "↳ Path: $(atfile.util.get_realpath "$downloaded_file")" 49 - fi 42 + # shellcheck disable=SC2154 43 + if [[ $_output_json == 1 ]]; then 44 + is_decrypted="false" 45 + [[ $decrypt == 1 ]] && is_decrypted="true" 46 + echo -e "{ \"decrypted\": $is_decrypted, \"name\": \"$(basename "${downloaded_file}")\", \"path\": \"$(atfile.util.get_realpath "${downloaded_file}")\" }" | jq 50 47 else 51 - [[ -f "$downloaded_file" ]] && rm -f "$downloaded_file" 52 - atfile.die "Unable to download '$key'" 48 + echo -e "Downloaded: $key" 49 + [[ $decrypt == 1 ]] && echo "Decrypted: $downloaded_file" 50 + echo -e "↳ Path: $(atfile.util.get_realpath "$downloaded_file")" 53 51 fi 54 52 }
+5 -5
src/commands/get.sh
··· 2 2 3 3 function atfile.get() { 4 4 key="$1" 5 - success=1 5 + unset error 6 6 7 7 # shellcheck disable=SC2154 8 8 atfile.say.debug "Getting record...\n↳ NSID: $_nsid_upload\n↳ Repo: $_username\n↳ Key: $key" 9 9 record="$(com.atproto.repo.getRecord "$_username" "$_nsid_upload" "$key")" 10 - [[ $? != 0 || -z "$record" || "$record" == "{}" || "$record" == *"\"error\":"* ]] && success=0 10 + error="$(atfile.util.get_xrpc_error $? "$record")" 11 11 12 - if [[ $success == 1 ]]; then 12 + [[ -n "$error" ]] && atfile.die.xrpc_error "Unable to get '$key'" "$error" 13 + 14 + if [[ -z "$error" ]]; then 13 15 file_type="$(echo "$record" | jq -r '.value.file.mimeType')" 14 16 did="$(echo "$record" | jq -r ".uri" | cut -d "/" -f 3)" 15 17 key="$(atfile.util.get_rkey_from_at_uri "$(echo "$record" | jq -r ".uri")")" ··· 105 107 esac 106 108 fi 107 109 fi 108 - else 109 - atfile.die "Unable to get '$key'" 110 110 fi 111 111 } 112 112
+4 -4
src/commands/lock.sh
··· 8 8 # shellcheck disable=SC2154 9 9 atfile.say.debug "Getting record...\n↳ NSID: $_nsid_upload\n↳ Repo: $_username\n↳ Key: $key" 10 10 upload_record="$(com.atproto.repo.getRecord "$_username" "$_nsid_upload" "$key")" 11 - error=$(atfile.util.get_xrpc_error $? "$upload_record") 11 + error="$(atfile.util.get_xrpc_error $? "$upload_record")" 12 12 13 13 if [[ -z "$error" ]]; then 14 14 if [[ $locked == 1 ]]; then ··· 22 22 # shellcheck disable=SC2154 23 23 atfile.say.debug "Updating record...\n↳ NSID: $_nsid_lock\n↳ Repo: $_username\n↳ Key: $key" 24 24 record="$(com.atproto.repo.putRecord "$_username" "$_nsid_lock" "$key" "$lock_record")" 25 - error=$(atfile.util.get_xrpc_error $? "$record") 25 + error="$(atfile.util.get_xrpc_error $? "$record")" 26 26 fi 27 27 28 28 if [[ -z "$error" ]]; then ··· 38 38 fi 39 39 else 40 40 if [[ $locked == true ]]; then 41 - atfile.die "Unable to lock '$key'" "$error" 41 + atfile.die.xrpc_error "Unable to lock '$key'" "$error" 42 42 else 43 - atfile.die "Unable to unlock '$key'" "$error" 43 + atfile.die.xrpc_error "Unable to unlock '$key'" "$error" 44 44 fi 45 45 fi 46 46 }