๐Ÿ“ฆโž”๐Ÿฆ‹ Store and retrieve files on the Atmosphere
35
fork

Configure Feed

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

split up old_cmds

Ducky 268a96f0 f4ae9c9c

+621 -588
+85
src/commands/blob.sh
··· 1 + #!/usr/bin/env bash 2 + 3 + function atfile.blob_list() { 4 + cursor="$1" 5 + unset error 6 + 7 + # shellcheck disable=SC2154 8 + atfile.say.debug "Getting blobs...\nโ†ณ Repo: $_username" 9 + blobs="$(com.atproto.sync.listBlobs "$_username" "$cursor")" 10 + error="$(atfile.util.get_xrpc_error $? "$blobs")" 11 + 12 + if [[ -z "$error" ]]; then 13 + records="$(echo "$blobs" | jq -c '.cids[]')" 14 + if [[ -z "$records" ]]; then 15 + if [[ -n "$cursor" ]]; then 16 + atfile.die "No more blobs for '$_username'" 17 + else 18 + atfile.die "No blobs for '$_username'" 19 + fi 20 + fi 21 + 22 + unset first_cid 23 + unset last_cid 24 + unset browser_accessible 25 + unset record_count 26 + unset json_output 27 + 28 + # shellcheck disable=SC2154 29 + if [[ $_output_json == 0 ]]; then 30 + echo -e "Blob" 31 + echo -e "----" 32 + else 33 + json_output="{\"blobs\":[" 34 + fi 35 + 36 + while IFS=$'\n' read -r c; do 37 + cid="$(echo "$c" | jq -r ".")" 38 + blob_uri="$(atfile.util.build_blob_uri "$_username" "$cid")" 39 + last_cid="$cid" 40 + ((record_count++)) 41 + 42 + if [[ -z $first_cid ]]; then 43 + first_cid="$cid" 44 + browser_accessible=$(atfile.util.is_url_accessible_in_browser "$blob_uri") 45 + fi 46 + 47 + if [[ -n $cid ]]; then 48 + if [[ $_output_json == 1 ]]; then 49 + json_output+="{ \"cid\": \"$cid\", \"url\": \"$blob_uri\" }," 50 + else 51 + if [[ $browser_accessible == 1 ]]; then 52 + echo "$blob_uri" 53 + else 54 + echo "$cid" 55 + fi 56 + fi 57 + fi 58 + done <<< "$records" 59 + 60 + if [[ $_output_json == 0 ]]; then 61 + atfile.util.print_table_paginate_hint "$last_cid" $record_count 62 + else 63 + json_output="${json_output::-1}" 64 + json_output+="]," 65 + json_output+="\"browser_accessible\": $(atfile.util.get_yn "$browser_accessible")," 66 + json_output+="\"cursor\": \"$last_cid\"}" 67 + echo -e "$json_output" | jq 68 + fi 69 + else 70 + atfile.die "Unable to list blobs" 71 + fi 72 + } 73 + 74 + function atfile.blob_upload() { 75 + file="$1" 76 + 77 + if [[ ! -f "$file" ]]; then 78 + atfile.die "File '$file' does not exist" 79 + else 80 + file="$(atfile.util.get_realpath "$file")" 81 + fi 82 + 83 + atfile.say.debug "Uploading blob...\nโ†ณ File: $file" 84 + com.atproto.sync.uploadBlob "$file" | jq 85 + }
+1 -1
src/commands/build.sh
··· 196 196 [[ $_version == *"+"* ]] && atfile.die "Cannot publish a Git version ($_version)" 197 197 198 198 atfile.say "โ†ณ Uploading '$dist_path'..." 199 - atfile.invoke.upload "$dist_path" "" "$version_record_id" 199 + atfile.upload "$dist_path" "" "$version_record_id" 200 200 # shellcheck disable=SC2181 201 201 [[ $? != 0 ]] && atfile.die "Unable to upload '$dist_path'" 202 202
+30
src/commands/delete.sh
··· 1 + #!/usr/bin/env bash 2 + 3 + function atfile.delete() { 4 + key="$1" 5 + success=1 6 + unset error 7 + 8 + # shellcheck disable=SC2154 9 + lock_record="$(com.atproto.repo.getRecord "$_username" "blue.zio.atfile.lock" "$key")" 10 + 11 + if [[ $(echo "$lock_record" | jq -r ".value.lock") == true ]]; then 12 + # shellcheck disable=SC2154 13 + atfile.die "Unable to delete '$key' โ€” file is locked\n Run \`$_prog unlock $key\` to unlock file" 14 + fi 15 + 16 + # shellcheck disable=SC2154 17 + record="$(com.atproto.repo.deleteRecord "$_username" "$_nsid_upload" "$key")" 18 + error="$(atfile.util.get_xrpc_error $? "$record")" 19 + 20 + if [[ -z "$error" ]]; then 21 + # shellcheck disable=SC2154 22 + if [[ $_output_json == 1 ]]; then 23 + echo "{ \"deleted\": true }" | jq 24 + else 25 + echo "Deleted: $key" 26 + fi 27 + else 28 + atfile.die.xrpc_error "Unable to delete '$key'" "$error" 29 + fi 30 + }
+54
src/commands/download.sh
··· 1 + #!/usr/bin/env bash 2 + 3 + function atfile.download() { 4 + key="$1" 5 + decrypt=$2 6 + success=1 7 + downloaded_file="" 8 + 9 + # shellcheck disable=SC2154 10 + atfile.say.debug "Getting record...\nโ†ณ NSID: $_nsid_upload\nโ†ณ Repo: $_username\nโ†ณ Key: $key" 11 + record="$(com.atproto.repo.getRecord "$_username" "$_nsid_upload" "$key")" 12 + [[ $? != 0 || -z "$record" || "$record" == "{}" || "$record" == *"\"error\":"* ]] && success=0 13 + 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")" 19 + 20 + curl -H "User-Agent: $(atfile.util.get_uas)" --silent "$blob_uri" -o "$downloaded_file" 21 + # shellcheck disable=SC2181 22 + [[ $? != 0 ]] && success=0 23 + fi 24 + 25 + if [[ $decrypt == 1 && $success == 1 ]]; then 26 + new_downloaded_file="$(echo "$downloaded_file" | sed -s s/.gpg//)" 27 + 28 + gpg --quiet --output "$new_downloaded_file" --decrypt "$downloaded_file" 29 + 30 + # shellcheck disable=SC2181 31 + if [[ $? != 0 ]]; then 32 + success=0 33 + else 34 + rm -f "$downloaded_file" 35 + downloaded_file="$new_downloaded_file" 36 + fi 37 + fi 38 + 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 50 + else 51 + [[ -f "$downloaded_file" ]] && rm -f "$downloaded_file" 52 + atfile.die "Unable to download '$key'" 53 + fi 54 + }
+134
src/commands/get.sh
··· 1 + #!/usr/bin/env bash 2 + 3 + function atfile.get() { 4 + key="$1" 5 + success=1 6 + 7 + # shellcheck disable=SC2154 8 + atfile.say.debug "Getting record...\nโ†ณ NSID: $_nsid_upload\nโ†ณ Repo: $_username\nโ†ณ Key: $key" 9 + record="$(com.atproto.repo.getRecord "$_username" "$_nsid_upload" "$key")" 10 + [[ $? != 0 || -z "$record" || "$record" == "{}" || "$record" == *"\"error\":"* ]] && success=0 11 + 12 + if [[ $success == 1 ]]; then 13 + file_type="$(echo "$record" | jq -r '.value.file.mimeType')" 14 + did="$(echo "$record" | jq -r ".uri" | cut -d "/" -f 3)" 15 + key="$(atfile.util.get_rkey_from_at_uri "$(echo "$record" | jq -r ".uri")")" 16 + blob_uri="$(atfile.util.build_blob_uri "$did" "$(echo "$record" | jq -r ".value.blob.ref.\"\$link\"")")" 17 + cdn_uri="$(atfile.util.get_cdn_uri "$did" "$(echo "$record" | jq -r ".value.blob.ref.\"\$link\"")" "$file_type")" 18 + 19 + unset locked 20 + unset encrypted 21 + 22 + # shellcheck disable=SC2154 23 + atfile.say.debug "Getting record...\nโ†ณ NSID: $_nsid_lock\nโ†ณ Repo: $_username\nโ†ณ Key: $key" 24 + locked_record="$(com.atproto.repo.getRecord "$_username" "$_nsid_lock" "$key")" 25 + # shellcheck disable=SC2181 26 + if [[ $? == 0 ]] && [[ -n "$locked_record" ]]; then 27 + if [[ $(echo "$locked_record" | jq -r ".value.lock") == true ]]; then 28 + locked="$(atfile.util.get_yn 1)" 29 + else 30 + locked="$(atfile.util.get_yn 0)" 31 + fi 32 + fi 33 + 34 + if [[ "$file_type" == "application/prs.atfile.gpg-crypt" ]]; then 35 + encrypted="$(atfile.util.get_yn 1)" 36 + else 37 + encrypted="$(atfile.util.get_yn 0)" 38 + fi 39 + 40 + # shellcheck disable=SC2154 41 + if [[ $_output_json == 1 ]]; then 42 + browser_accessible=$(atfile.util.get_yn "$(atfile.util.is_url_accessible_in_browser "$blob_uri")") 43 + 44 + echo "{ \"encrypted\": $encrypted, \"locked\": $locked, \"upload\": $(echo "$record" | jq -r ".value"), \"url\": { \"blob\": \"$blob_uri\", \"browser_accessible\": $browser_accessible, \"cdn\": { \"bsky\": \"$cdn_uri\" } } }" | jq 45 + else 46 + file_date="$(echo "$record" | jq -r '.value.file.modifiedAt')" 47 + file_hash="$(echo "$record" | jq -r '.value.checksum.hash')" 48 + file_hash_type="$(echo "$record" | jq -r '.value.checksum.algo')" 49 + [[ "$file_hash_type" == "null" ]] && file_hash_type="$(echo "$record" | jq -r '.value.checksum.type')" 50 + file_hash_pretty="$file_hash ($file_hash_type)" 51 + file_name="$(echo "$record" | jq -r '.value.file.name')" 52 + file_name_pretty="$(atfile.util.get_file_name_pretty "$(echo "$record" | jq -r '.value')")" 53 + file_size="$(echo "$record" | jq -r '.value.file.size')" 54 + file_size_pretty="$(atfile.util.get_file_size_pretty "$file_size")" 55 + 56 + unset finger_type 57 + header="$file_name_pretty" 58 + 59 + if [[ $(atfile.util.is_null_or_empty "$file_hash_type") == 1 ]] || [[ "$file_hash_type" == "md5" && ${#file_hash} != 32 ]] || [[ "$file_hash_type" == "none" ]]; then 60 + file_hash_pretty="(None)" 61 + fi 62 + 63 + if [[ "$(echo "$record" | jq -r ".value.finger")" != "null" ]]; then 64 + finger_type="$(echo "$record" | jq -r ".value.finger.\"\$type\"" | cut -d "#" -f 2)" 65 + fi 66 + 67 + echo "$header" 68 + atfile.util.print_blob_url_output "$blob_uri" 69 + [[ -n "$cdn_uri" ]] && echo -e " โ†ณ CDN: $cdn_uri" 70 + # shellcheck disable=SC2154 71 + echo -e "โ†ณ URI: atfile://$_username/$key" 72 + echo -e "โ†ณ File: $key" 73 + echo -e " โ†ณ Name: $file_name" 74 + echo -e " โ†ณ Type: $file_type" 75 + echo -e " โ†ณ Size: $file_size_pretty" 76 + echo -e " โ†ณ Date: $(atfile.util.get_date "$file_date" "%Y-%m-%d %H:%M:%S %Z")" 77 + echo -e " โ†ณ Hash: $file_hash_pretty" 78 + echo -e "โ†ณ Locked: $locked" 79 + echo -e "โ†ณ Encrypted: $encrypted" 80 + if [[ -z "$finger_type" ]]; then 81 + echo -e "โ†ณ Source: (Unknown)" 82 + else 83 + case $finger_type in 84 + "browser") 85 + finger_browser_uas="$(echo "$record" | jq -r ".value.finger.userAgent")" 86 + 87 + [[ -z $finger_browser_uas || $finger_browser_uas == "null" ]] && finger_browser_uas="(Unknown)" 88 + 89 + echo -e "โ†ณ Source: $finger_browser_uas" 90 + ;; 91 + "machine") 92 + finger_machine_app="$(echo "$record" | jq -r ".value.finger.app")" 93 + finger_machine_host="$(echo "$record" | jq -r ".value.finger.host")" 94 + finger_machine_os="$(echo "$record" | jq -r ".value.finger.os")" 95 + 96 + [[ -z $finger_machine_app || $finger_machine_app == "null" ]] && finger_machine_app="(Unknown)" 97 + 98 + echo -e "โ†ณ Source: $finger_machine_app" 99 + [[ -n $finger_machine_host && $finger_machine_host != "null" ]] && echo -e " โ†ณ Host: $finger_machine_host" 100 + [[ -n $finger_machine_os && $finger_machine_os != "null" ]] && echo -e " โ†ณ OS: $finger_machine_os" 101 + ;; 102 + *) 103 + echo -e "โ†ณ Source: (Unknown)" 104 + ;; 105 + esac 106 + fi 107 + fi 108 + else 109 + atfile.die "Unable to get '$key'" 110 + fi 111 + } 112 + 113 + function atfile.get_url() { 114 + key="$1" 115 + unset error 116 + 117 + # shellcheck disable=SC2154 118 + atfile.say.debug "Getting record...\nโ†ณ NSID: $_nsid_upload\nโ†ณ Repo: $_username\nโ†ณ Key: $key" 119 + record="$(com.atproto.repo.getRecord "$_username" "$_nsid_upload" "$key")" 120 + error="$(atfile.util.get_xrpc_error $? "$record")" 121 + 122 + if [[ -z "$error" ]]; then 123 + blob_url="$(atfile.util.build_blob_uri "$(echo "$record" | jq -r ".uri" | cut -d "/" -f 3)" "$(echo "$record" | jq -r ".value.blob.ref.\"\$link\"")")" 124 + 125 + # shellcheck disable=SC2154 126 + if [[ $_output_json == 1 ]]; then 127 + echo -e "{\"url\": \"$blob_url\" }" | jq 128 + else 129 + echo "$blob_url" 130 + fi 131 + else 132 + atfile.die.xrpc_error "Unable to get '$key'" "$error" 133 + fi 134 + }
+67
src/commands/list.sh
··· 1 + #!/usr/bin/env bash 2 + 3 + function atfile.list() { 4 + cursor="$1" 5 + unset error 6 + 7 + # shellcheck disable=SC2154 8 + atfile.say.debug "Getting records...\nโ†ณ NSID: $_nsid_upload\nโ†ณ Repo: $_username" 9 + records="$(com.atproto.repo.listRecords "$_username" "$_nsid_upload" "$cursor")" 10 + error="$(atfile.util.get_xrpc_error $? "$records")" 11 + 12 + if [[ -z "$error" ]]; then 13 + records="$(echo "$records" | jq -c '.records[]')" 14 + if [[ -z "$records" ]]; then 15 + if [[ -n "$cursor" ]]; then 16 + atfile.die "No more files for '$_username'" 17 + else 18 + atfile.die "No files for '$_username'" 19 + fi 20 + fi 21 + 22 + unset last_key 23 + unset record_count 24 + unset json_output 25 + 26 + # shellcheck disable=SC2154 27 + if [[ $_output_json == 0 ]]; then 28 + echo -e "Key\t\tFile" 29 + echo -e "---\t\t----" 30 + else 31 + json_output="{\"uploads\":[" 32 + fi 33 + 34 + while IFS=$'\n' read -r c; do 35 + key=$(atfile.util.get_rkey_from_at_uri "$(echo "$c" | jq -r ".uri")") 36 + name="$(echo "$c" | jq -r '.value.file.name')" 37 + type_emoji="$(atfile.util.get_file_type_emoji "$(echo "$c" | jq -r '.value.file.mimeType')")" 38 + last_key="$key" 39 + ((record_count++)) 40 + 41 + if [[ -n $key ]]; then 42 + if [[ $_output_json == 1 ]]; then 43 + json_output+="$c," 44 + else 45 + # shellcheck disable=SC2154 46 + if [[ $_os == "haiku" ]]; then 47 + # BUG: Haiku Terminal has issues with emojis 48 + echo -e "$key\t$name" 49 + else 50 + echo -e "$key\t$type_emoji $name" 51 + fi 52 + fi 53 + fi 54 + done <<< "$records" 55 + 56 + if [[ $_output_json == 0 ]]; then 57 + atfile.util.print_table_paginate_hint "$last_key" $record_count 58 + else 59 + json_output="${json_output::-1}" 60 + json_output+="]," 61 + json_output+="\"cursor\": \"$last_key\"}" 62 + echo -e "$json_output" | jq 63 + fi 64 + else 65 + atfile.die.xrpc_error "Unable to list files" "$error" 66 + fi 67 + }
+46
src/commands/lock.sh
··· 1 + #!/usr/bin/env bash 2 + 3 + function atfile.lock() { 4 + key="$1" 5 + locked=$2 6 + unset error 7 + 8 + # shellcheck disable=SC2154 9 + atfile.say.debug "Getting record...\nโ†ณ NSID: $_nsid_upload\nโ†ณ Repo: $_username\nโ†ณ Key: $key" 10 + upload_record="$(com.atproto.repo.getRecord "$_username" "$_nsid_upload" "$key")" 11 + error=$(atfile.util.get_xrpc_error $? "$upload_record") 12 + 13 + if [[ -z "$error" ]]; then 14 + if [[ $locked == 1 ]]; then 15 + locked=true 16 + else 17 + locked=false 18 + fi 19 + 20 + lock_record="$(blue.zio.atfile.lock $locked)" 21 + 22 + # shellcheck disable=SC2154 23 + atfile.say.debug "Updating record...\nโ†ณ NSID: $_nsid_lock\nโ†ณ Repo: $_username\nโ†ณ Key: $key" 24 + record="$(com.atproto.repo.putRecord "$_username" "$_nsid_lock" "$key" "$lock_record")" 25 + error=$(atfile.util.get_xrpc_error $? "$record") 26 + fi 27 + 28 + if [[ -z "$error" ]]; then 29 + # shellcheck disable=SC2154 30 + if [[ $_output_json == 1 ]]; then 31 + echo -e "{ \"locked\": $locked }" | jq 32 + else 33 + if [[ $locked == true ]]; then 34 + echo "Locked: $key" 35 + else 36 + echo "Unlocked: $key" 37 + fi 38 + fi 39 + else 40 + if [[ $locked == true ]]; then 41 + atfile.die "Unable to lock '$key'" "$error" 42 + else 43 + atfile.die "Unable to unlock '$key'" "$error" 44 + fi 45 + fi 46 + }
-571
src/commands/old_cmds.sh
··· 1 - #!/usr/bin/env bash 2 - 3 - function atfile.invoke.blob_list() { 4 - cursor="$1" 5 - unset error 6 - 7 - atfile.say.debug "Getting blobs...\nโ†ณ Repo: $_username" 8 - blobs="$(com.atproto.sync.listBlobs "$_username" "$cursor")" 9 - error="$(atfile.util.get_xrpc_error $? "$blobs")" 10 - 11 - if [[ -z "$error" ]]; then 12 - records="$(echo "$blobs" | jq -c '.cids[]')" 13 - if [[ -z "$records" ]]; then 14 - if [[ -n "$cursor" ]]; then 15 - atfile.die "No more blobs for '$_username'" 16 - else 17 - atfile.die "No blobs for '$_username'" 18 - fi 19 - fi 20 - 21 - unset first_cid 22 - unset last_cid 23 - unset browser_accessible 24 - unset record_count 25 - unset json_output 26 - 27 - # shellcheck disable=SC2154 28 - if [[ $_output_json == 0 ]]; then 29 - echo -e "Blob" 30 - echo -e "----" 31 - else 32 - json_output="{\"blobs\":[" 33 - fi 34 - 35 - while IFS=$'\n' read -r c; do 36 - cid="$(echo "$c" | jq -r ".")" 37 - blob_uri="$(atfile.util.build_blob_uri "$_username" "$cid")" 38 - last_cid="$cid" 39 - ((record_count++)) 40 - 41 - if [[ -z $first_cid ]]; then 42 - first_cid="$cid" 43 - browser_accessible=$(atfile.util.is_url_accessible_in_browser "$blob_uri") 44 - fi 45 - 46 - if [[ -n $cid ]]; then 47 - if [[ $_output_json == 1 ]]; then 48 - json_output+="{ \"cid\": \"$cid\", \"url\": \"$blob_uri\" }," 49 - else 50 - if [[ $browser_accessible == 1 ]]; then 51 - echo "$blob_uri" 52 - else 53 - echo "$cid" 54 - fi 55 - fi 56 - fi 57 - done <<< "$records" 58 - 59 - if [[ $_output_json == 0 ]]; then 60 - atfile.util.print_table_paginate_hint "$last_cid" $record_count 61 - else 62 - json_output="${json_output::-1}" 63 - json_output+="]," 64 - json_output+="\"browser_accessible\": $(atfile.util.get_yn "$browser_accessible")," 65 - json_output+="\"cursor\": \"$last_cid\"}" 66 - echo -e "$json_output" | jq 67 - fi 68 - else 69 - atfile.die "Unable to list blobs" 70 - fi 71 - } 72 - 73 - function atfile.invoke.blob_upload() { 74 - file="$1" 75 - 76 - if [[ ! -f "$file" ]]; then 77 - atfile.die "File '$file' does not exist" 78 - else 79 - file="$(atfile.util.get_realpath "$file")" 80 - fi 81 - 82 - atfile.say.debug "Uploading blob...\nโ†ณ File: $file" 83 - com.atproto.sync.uploadBlob "$file" | jq 84 - } 85 - 86 - function atfile.invoke.delete() { 87 - key="$1" 88 - success=1 89 - unset error 90 - 91 - lock_record="$(com.atproto.repo.getRecord "$_username" "blue.zio.atfile.lock" "$key")" 92 - 93 - if [[ $(echo "$lock_record" | jq -r ".value.lock") == true ]]; then 94 - # shellcheck disable=SC2154 95 - atfile.die "Unable to delete '$key' โ€” file is locked\n Run \`$_prog unlock $key\` to unlock file" 96 - fi 97 - 98 - # shellcheck disable=SC2154 99 - record="$(com.atproto.repo.deleteRecord "$_username" "$_nsid_upload" "$key")" 100 - error="$(atfile.util.get_xrpc_error $? "$record")" 101 - 102 - if [[ -z "$error" ]]; then 103 - if [[ $_output_json == 1 ]]; then 104 - echo "{ \"deleted\": true }" | jq 105 - else 106 - echo "Deleted: $key" 107 - fi 108 - else 109 - atfile.die.xrpc_error "Unable to delete '$key'" "$error" 110 - fi 111 - } 112 - 113 - function atfile.invoke.download() { 114 - key="$1" 115 - decrypt=$2 116 - success=1 117 - downloaded_file="" 118 - 119 - atfile.say.debug "Getting record...\nโ†ณ NSID: $_nsid_upload\nโ†ณ Repo: $_username\nโ†ณ Key: $key" 120 - record="$(com.atproto.repo.getRecord "$_username" "$_nsid_upload" "$key")" 121 - [[ $? != 0 || -z "$record" || "$record" == "{}" || "$record" == *"\"error\":"* ]] && success=0 122 - 123 - if [[ $success == 1 ]]; then 124 - blob_uri="$(atfile.util.build_blob_uri "$(echo "$record" | jq -r ".uri" | cut -d "/" -f 3)" "$(echo "$record" | jq -r ".value.blob.ref.\"\$link\"")")" 125 - file_name="$(echo "$record" | jq -r '.value.file.name')" 126 - key="$(atfile.util.get_rkey_from_at_uri "$(echo "$record" | jq -r ".uri")")" 127 - downloaded_file="$(atfile.util.build_out_filename "$key" "$file_name")" 128 - 129 - curl -H "User-Agent: $(atfile.util.get_uas)" --silent "$blob_uri" -o "$downloaded_file" 130 - # shellcheck disable=SC2181 131 - [[ $? != 0 ]] && success=0 132 - fi 133 - 134 - if [[ $decrypt == 1 && $success == 1 ]]; then 135 - new_downloaded_file="$(echo "$downloaded_file" | sed -s s/.gpg//)" 136 - 137 - gpg --quiet --output "$new_downloaded_file" --decrypt "$downloaded_file" 138 - 139 - # shellcheck disable=SC2181 140 - if [[ $? != 0 ]]; then 141 - success=0 142 - else 143 - rm -f "$downloaded_file" 144 - downloaded_file="$new_downloaded_file" 145 - fi 146 - fi 147 - 148 - if [[ $success == 1 ]]; then 149 - if [[ $_output_json == 1 ]]; then 150 - is_decrypted="false" 151 - [[ $decrypt == 1 ]] && is_decrypted="true" 152 - echo -e "{ \"decrypted\": $is_decrypted, \"name\": \"$(basename "${downloaded_file}")\", \"path\": \"$(atfile.util.get_realpath "${downloaded_file}")\" }" | jq 153 - else 154 - echo -e "Downloaded: $key" 155 - [[ $decrypt == 1 ]] && echo "Decrypted: $downloaded_file" 156 - echo -e "โ†ณ Path: $(atfile.util.get_realpath "$downloaded_file")" 157 - fi 158 - else 159 - [[ -f "$downloaded_file" ]] && rm -f "$downloaded_file" 160 - atfile.die "Unable to download '$key'" 161 - fi 162 - } 163 - 164 - function atfile.invoke.get() { 165 - key="$1" 166 - success=1 167 - 168 - atfile.say.debug "Getting record...\nโ†ณ NSID: $_nsid_upload\nโ†ณ Repo: $_username\nโ†ณ Key: $key" 169 - record="$(com.atproto.repo.getRecord "$_username" "$_nsid_upload" "$key")" 170 - [[ $? != 0 || -z "$record" || "$record" == "{}" || "$record" == *"\"error\":"* ]] && success=0 171 - 172 - if [[ $success == 1 ]]; then 173 - file_type="$(echo "$record" | jq -r '.value.file.mimeType')" 174 - did="$(echo "$record" | jq -r ".uri" | cut -d "/" -f 3)" 175 - key="$(atfile.util.get_rkey_from_at_uri "$(echo "$record" | jq -r ".uri")")" 176 - blob_uri="$(atfile.util.build_blob_uri "$did" "$(echo "$record" | jq -r ".value.blob.ref.\"\$link\"")")" 177 - cdn_uri="$(atfile.util.get_cdn_uri "$did" "$(echo "$record" | jq -r ".value.blob.ref.\"\$link\"")" "$file_type")" 178 - 179 - unset locked 180 - unset encrypted 181 - 182 - # shellcheck disable=SC2154 183 - atfile.say.debug "Getting record...\nโ†ณ NSID: $_nsid_lock\nโ†ณ Repo: $_username\nโ†ณ Key: $key" 184 - locked_record="$(com.atproto.repo.getRecord "$_username" "$_nsid_lock" "$key")" 185 - # shellcheck disable=SC2181 186 - if [[ $? == 0 ]] && [[ -n "$locked_record" ]]; then 187 - if [[ $(echo "$locked_record" | jq -r ".value.lock") == true ]]; then 188 - locked="$(atfile.util.get_yn 1)" 189 - else 190 - locked="$(atfile.util.get_yn 0)" 191 - fi 192 - fi 193 - 194 - if [[ "$file_type" == "application/prs.atfile.gpg-crypt" ]]; then 195 - encrypted="$(atfile.util.get_yn 1)" 196 - else 197 - encrypted="$(atfile.util.get_yn 0)" 198 - fi 199 - 200 - if [[ $_output_json == 1 ]]; then 201 - browser_accessible=$(atfile.util.get_yn "$(atfile.util.is_url_accessible_in_browser "$blob_uri")") 202 - 203 - echo "{ \"encrypted\": $encrypted, \"locked\": $locked, \"upload\": $(echo "$record" | jq -r ".value"), \"url\": { \"blob\": \"$blob_uri\", \"browser_accessible\": $browser_accessible, \"cdn\": { \"bsky\": \"$cdn_uri\" } } }" | jq 204 - else 205 - file_date="$(echo "$record" | jq -r '.value.file.modifiedAt')" 206 - file_hash="$(echo "$record" | jq -r '.value.checksum.hash')" 207 - file_hash_type="$(echo "$record" | jq -r '.value.checksum.algo')" 208 - [[ "$file_hash_type" == "null" ]] && file_hash_type="$(echo "$record" | jq -r '.value.checksum.type')" 209 - file_hash_pretty="$file_hash ($file_hash_type)" 210 - file_name="$(echo "$record" | jq -r '.value.file.name')" 211 - file_name_pretty="$(atfile.util.get_file_name_pretty "$(echo "$record" | jq -r '.value')")" 212 - file_size="$(echo "$record" | jq -r '.value.file.size')" 213 - file_size_pretty="$(atfile.util.get_file_size_pretty "$file_size")" 214 - 215 - unset finger_type 216 - header="$file_name_pretty" 217 - 218 - if [[ $(atfile.util.is_null_or_empty "$file_hash_type") == 1 ]] || [[ "$file_hash_type" == "md5" && ${#file_hash} != 32 ]] || [[ "$file_hash_type" == "none" ]]; then 219 - file_hash_pretty="(None)" 220 - fi 221 - 222 - if [[ "$(echo "$record" | jq -r ".value.finger")" != "null" ]]; then 223 - finger_type="$(echo "$record" | jq -r ".value.finger.\"\$type\"" | cut -d "#" -f 2)" 224 - fi 225 - 226 - echo "$header" 227 - atfile.util.print_blob_url_output "$blob_uri" 228 - [[ -n "$cdn_uri" ]] && echo -e " โ†ณ CDN: $cdn_uri" 229 - echo -e "โ†ณ URI: atfile://$_username/$key" 230 - echo -e "โ†ณ File: $key" 231 - echo -e " โ†ณ Name: $file_name" 232 - echo -e " โ†ณ Type: $file_type" 233 - echo -e " โ†ณ Size: $file_size_pretty" 234 - echo -e " โ†ณ Date: $(atfile.util.get_date "$file_date" "%Y-%m-%d %H:%M:%S %Z")" 235 - echo -e " โ†ณ Hash: $file_hash_pretty" 236 - echo -e "โ†ณ Locked: $locked" 237 - echo -e "โ†ณ Encrypted: $encrypted" 238 - if [[ -z "$finger_type" ]]; then 239 - echo -e "โ†ณ Source: (Unknown)" 240 - else 241 - case $finger_type in 242 - "browser") 243 - finger_browser_uas="$(echo "$record" | jq -r ".value.finger.userAgent")" 244 - 245 - [[ -z $finger_browser_uas || $finger_browser_uas == "null" ]] && finger_browser_uas="(Unknown)" 246 - 247 - echo -e "โ†ณ Source: $finger_browser_uas" 248 - ;; 249 - "machine") 250 - finger_machine_app="$(echo "$record" | jq -r ".value.finger.app")" 251 - finger_machine_host="$(echo "$record" | jq -r ".value.finger.host")" 252 - finger_machine_os="$(echo "$record" | jq -r ".value.finger.os")" 253 - 254 - [[ -z $finger_machine_app || $finger_machine_app == "null" ]] && finger_machine_app="(Unknown)" 255 - 256 - echo -e "โ†ณ Source: $finger_machine_app" 257 - [[ -n $finger_machine_host && $finger_machine_host != "null" ]] && echo -e " โ†ณ Host: $finger_machine_host" 258 - [[ -n $finger_machine_os && $finger_machine_os != "null" ]] && echo -e " โ†ณ OS: $finger_machine_os" 259 - ;; 260 - *) 261 - echo -e "โ†ณ Source: (Unknown)" 262 - ;; 263 - esac 264 - fi 265 - fi 266 - else 267 - atfile.die "Unable to get '$key'" 268 - fi 269 - } 270 - 271 - function atfile.invoke.get_url() { 272 - key="$1" 273 - unset error 274 - 275 - atfile.say.debug "Getting record...\nโ†ณ NSID: $_nsid_upload\nโ†ณ Repo: $_username\nโ†ณ Key: $key" 276 - record="$(com.atproto.repo.getRecord "$_username" "$_nsid_upload" "$key")" 277 - error="$(atfile.util.get_xrpc_error $? "$record")" 278 - 279 - if [[ -z "$error" ]]; then 280 - blob_url="$(atfile.util.build_blob_uri "$(echo "$record" | jq -r ".uri" | cut -d "/" -f 3)" "$(echo "$record" | jq -r ".value.blob.ref.\"\$link\"")")" 281 - 282 - if [[ $_output_json == 1 ]]; then 283 - echo -e "{\"url\": \"$blob_url\" }" | jq 284 - else 285 - echo "$blob_url" 286 - fi 287 - else 288 - atfile.die.xrpc_error "Unable to get '$key'" "$error" 289 - fi 290 - } 291 - 292 - function atfile.invoke.list() { 293 - cursor="$1" 294 - unset error 295 - 296 - atfile.say.debug "Getting records...\nโ†ณ NSID: $_nsid_upload\nโ†ณ Repo: $_username" 297 - records="$(com.atproto.repo.listRecords "$_username" "$_nsid_upload" "$cursor")" 298 - error="$(atfile.util.get_xrpc_error $? "$records")" 299 - 300 - if [[ -z "$error" ]]; then 301 - records="$(echo "$records" | jq -c '.records[]')" 302 - if [[ -z "$records" ]]; then 303 - if [[ -n "$cursor" ]]; then 304 - atfile.die "No more files for '$_username'" 305 - else 306 - atfile.die "No files for '$_username'" 307 - fi 308 - fi 309 - 310 - unset last_key 311 - unset record_count 312 - unset json_output 313 - 314 - if [[ $_output_json == 0 ]]; then 315 - echo -e "Key\t\tFile" 316 - echo -e "---\t\t----" 317 - else 318 - json_output="{\"uploads\":[" 319 - fi 320 - 321 - while IFS=$'\n' read -r c; do 322 - key=$(atfile.util.get_rkey_from_at_uri "$(echo "$c" | jq -r ".uri")") 323 - name="$(echo "$c" | jq -r '.value.file.name')" 324 - type_emoji="$(atfile.util.get_file_type_emoji "$(echo "$c" | jq -r '.value.file.mimeType')")" 325 - last_key="$key" 326 - ((record_count++)) 327 - 328 - if [[ -n $key ]]; then 329 - if [[ $_output_json == 1 ]]; then 330 - json_output+="$c," 331 - else 332 - if [[ $_os == "haiku" ]]; then 333 - # BUG: Haiku Terminal has issues with emojis 334 - echo -e "$key\t$name" 335 - else 336 - echo -e "$key\t$type_emoji $name" 337 - fi 338 - fi 339 - fi 340 - done <<< "$records" 341 - 342 - if [[ $_output_json == 0 ]]; then 343 - atfile.util.print_table_paginate_hint "$last_key" $record_count 344 - else 345 - json_output="${json_output::-1}" 346 - json_output+="]," 347 - json_output+="\"cursor\": \"$last_key\"}" 348 - echo -e "$json_output" | jq 349 - fi 350 - else 351 - atfile.die.xrpc_error "Unable to list files" "$error" 352 - fi 353 - } 354 - 355 - function atfile.invoke.lock() { 356 - key="$1" 357 - locked=$2 358 - unset error 359 - 360 - atfile.say.debug "Getting record...\nโ†ณ NSID: $_nsid_upload\nโ†ณ Repo: $_username\nโ†ณ Key: $key" 361 - upload_record="$(com.atproto.repo.getRecord "$_username" "$_nsid_upload" "$key")" 362 - error=$(atfile.util.get_xrpc_error $? "$upload_record") 363 - 364 - if [[ -z "$error" ]]; then 365 - if [[ $locked == 1 ]]; then 366 - locked=true 367 - else 368 - locked=false 369 - fi 370 - 371 - lock_record="$(blue.zio.atfile.lock $locked)" 372 - 373 - atfile.say.debug "Updating record...\nโ†ณ NSID: $_nsid_lock\nโ†ณ Repo: $_username\nโ†ณ Key: $key" 374 - record="$(com.atproto.repo.putRecord "$_username" "$_nsid_lock" "$key" "$lock_record")" 375 - error=$(atfile.util.get_xrpc_error $? "$record") 376 - fi 377 - 378 - if [[ -z "$error" ]]; then 379 - if [[ $_output_json == 1 ]]; then 380 - echo -e "{ \"locked\": $locked }" | jq 381 - else 382 - if [[ $locked == true ]]; then 383 - echo "Locked: $key" 384 - else 385 - echo "Unlocked: $key" 386 - fi 387 - fi 388 - else 389 - if [[ $locked == true ]]; then 390 - atfile.die "Unable to lock '$key'" "$error" 391 - else 392 - atfile.die "Unable to unlock '$key'" "$error" 393 - fi 394 - fi 395 - } 396 - 397 - function atfile.invoke.print() { 398 - key="$1" 399 - unset error 400 - 401 - atfile.say.debug "Getting record...\nโ†ณ NSID: $_nsid_upload\nโ†ณ Repo: $_username\nโ†ณ Key: $key" 402 - record="$(com.atproto.repo.getRecord "$_username" "$_nsid_upload" "$key")" 403 - error="$(atfile.util.get_xrpc_error $? "$record")" 404 - 405 - if [[ -z "$error" ]]; then 406 - blob_uri="$(atfile.util.build_blob_uri "$(echo "$record" | jq -r ".uri" | cut -d "/" -f 3)" "$(echo "$record" | jq -r ".value.blob.ref.\"\$link\"")")" 407 - file_type="$(echo "$record" | jq -r '.value.file.mimeType')" 408 - 409 - curl -H "$(atfile.util.get_uas)" -s -L "$blob_uri" --output - 410 - # shellcheck disable=SC2181 411 - [[ $? != 0 ]] && error="?" 412 - fi 413 - 414 - if [[ -n "$error" ]]; then 415 - atfile.die "Unable to cat '$key'" "$error" 416 - fi 417 - } 418 - 419 - function atfile.invoke.upload() { 420 - file="$1" 421 - recipient="$2" 422 - key="$3" 423 - unset error 424 - 425 - if [[ ! -f "$file" ]]; then 426 - atfile.die "File '$file' does not exist" 427 - else 428 - file="$(atfile.util.get_realpath "$file")" 429 - fi 430 - 431 - if [[ -n $recipient ]]; then 432 - file_crypt="$(dirname "$file")/$(basename "$file").gpg" 433 - 434 - [[ $_output_json == 0 ]] && echo -e "Encrypting '$file_crypt'..." 435 - gpg --yes --quiet --recipient "$recipient" --output "$file_crypt" --encrypt "$file" 436 - 437 - # shellcheck disable=SC2181 438 - if [[ $? == 0 ]]; then 439 - file="$file_crypt" 440 - else 441 - rm -f "$file_crypt" 442 - atfile.die "Unable to encrypt '$(basename "$file")'" 443 - fi 444 - fi 445 - 446 - if [[ -z "$error" ]]; then 447 - unset file_date 448 - unset file_size 449 - unset file_type 450 - 451 - case "$_os" in 452 - "bsd"|"macos") 453 - file_date="$(atfile.util.get_date "$(stat -f '%Sm' -t "%Y-%m-%dT%H:%M:%SZ" "$file")")" 454 - file_size="$(stat -f '%z' "$file")" 455 - file_type="$(file -b --mime-type "$file")" 456 - ;; 457 - "haiku") 458 - haiku_file_attr="$(catattr BEOS:TYPE "$file" 2> /dev/null)" 459 - # shellcheck disable=SC2181 460 - [[ $? == 0 ]] && file_type="$(echo "$haiku_file_attr" | cut -d ":" -f 3 | xargs)" 461 - 462 - file_date="$(atfile.util.get_date "$(stat -c '%y' "$file")")" 463 - file_size="$(stat -c %s "$file")" 464 - ;; 465 - *) 466 - file_date="$(atfile.util.get_date "$(stat -c '%y' "$file")")" 467 - file_size="$(stat -c %s "$file")" 468 - file_type="$(file -b --mime-type "$file")" 469 - ;; 470 - esac 471 - 472 - file_hash="$(atfile.util.get_md5 "$file")" 473 - file_hash_checksum="$(echo "$file_hash" | cut -d "|" -f 1)" 474 - file_hash_type="$(echo "$file_hash" | cut -d "|" -f 2)" 475 - file_name="$(basename "$file")" 476 - 477 - if [[ -n $recipient ]]; then 478 - file_type="application/prs.atfile.gpg-crypt" 479 - elif [[ "$file_type" == "application/"* ]]; then 480 - file_extension="${file_name##*.}" 481 - 482 - case "$file_extension" in 483 - "car") file_type="application/prs.atfile.car" ;; 484 - "dmg"|"smi") file_type="application/x-apple-diskimage" ;; 485 - esac 486 - fi 487 - 488 - file_type_emoji="$(atfile.util.get_file_type_emoji "$file_type")" 489 - 490 - atfile.say.debug "File: $file\nโ†ณ Date: $file_date\nโ†ณ Hash: $file_hash_checksum ($file_hash_type)\nโ†ณ Name: $file_name\nโ†ณ Size: $file_size\nโ†ณ Type: $file_type_emoji $file_type" 491 - 492 - unset file_finger_record 493 - unset file_meta_record 494 - 495 - file_finger_record="$(atfile.util.get_finger_record)" 496 - file_meta_record="$(atfile.util.get_meta_record "$file" "$file_type")" 497 - 498 - atfile.say.debug "Checking filesize..." 499 - file_size_surplus="$(atfile.util.get_file_size_surplus_for_pds "$file_size" "$_server")" 500 - 501 - if [[ $file_size_surplus != 0 ]]; then 502 - die_message="File '$file_name' is too large ($(atfile.util.get_file_size_pretty "$file_size_surplus") over)" 503 - atfile.die "$die_message" 504 - fi 505 - 506 - [[ $_output_json == 0 ]] && echo "Uploading '$file'..." 507 - 508 - blob="$(com.atproto.sync.uploadBlob "$file")" 509 - error="$(atfile.util.get_xrpc_error $? "$blob")" 510 - [[ $error == "?" ]] && error="Blob rejected by PDS (too large?)" 511 - 512 - atfile.say.debug "Uploading blob...\nโ†ณ Ref: $(echo "$blob" | jq -r ".ref.\"\$link\"")" 513 - 514 - if [[ -z "$error" ]]; then 515 - # shellcheck disable=SC2154 516 - file_record="$(blue.zio.atfile.upload "$blob" "$_now" "$file_hash_checksum" "$file_hash_type" "$file_date" "$file_name" "$file_size" "$file_type" "$file_meta_record" "$file_finger_record")" 517 - 518 - if [[ -n "$key" ]]; then 519 - atfile.say.debug "Updating record...\nโ†ณ NSID: $_nsid_upload\nโ†ณ Repo: $_username\nโ†ณ Key: $key" 520 - record="$(com.atproto.repo.putRecord "$_username" "$_nsid_upload" "$key" "$file_record")" 521 - error="$(atfile.util.get_xrpc_error $? "$record")" 522 - else 523 - atfile.say.debug "Creating record...\nโ†ณ NSID: $_nsid_upload\nโ†ณ Repo: $_username" 524 - record="$(com.atproto.repo.createRecord "$_username" "$_nsid_upload" "$file_record")" 525 - error="$(atfile.util.get_xrpc_error $? "$record")" 526 - fi 527 - fi 528 - fi 529 - 530 - if [[ -n $recipient ]]; then 531 - rm -f "$file" 532 - fi 533 - 534 - if [[ -z "$error" ]]; then 535 - unset recipient_key 536 - blob_uri="$(atfile.util.build_blob_uri "$(echo "$record" | jq -r ".uri" | cut -d "/" -f 3)" "$(echo "$blob" | jq -r ".ref.\"\$link\"")")" 537 - key="$(atfile.util.get_rkey_from_at_uri "$(echo "$record" | jq -r ".uri")")" 538 - 539 - if [[ -n "$recipient" ]]; then 540 - recipient_key="$(gpg --list-keys "$recipient" | sed -n 2p | xargs)" 541 - fi 542 - 543 - if [[ $_output_json == 1 ]]; then 544 - unset recipient_json 545 - 546 - if [[ -n "$recipient" ]]; then 547 - recipient_json="{ \"id\": \"$recipient\", \"key\": \"$recipient_key\" }" 548 - else 549 - recipient_json="null" 550 - fi 551 - 552 - echo -e "{ \"blob\": \"$blob_uri\", \"key\": \"$key\", \"upload\": $record, \"recipient\": $recipient_json }" | jq 553 - else 554 - echo "---" 555 - if [[ $_os == "haiku" ]]; then 556 - # BUG: Haiku Terminal has issues with emojis 557 - echo "Uploaded: $file_name" 558 - else 559 - echo "Uploaded: $file_type_emoji $file_name" 560 - fi 561 - atfile.util.print_blob_url_output "$blob_uri" 562 - echo -e "โ†ณ Key: $key" 563 - echo -e "โ†ณ URI: atfile://$_username/$key" 564 - if [[ -n "$recipient" ]]; then 565 - echo -e "โ†ณ Recipient: $recipient ($recipient_key)" 566 - fi 567 - fi 568 - else 569 - atfile.die.xrpc_error "Unable to upload '$file'" "$error" 570 - fi 571 - }
+23
src/commands/print.sh
··· 1 + #!/usr/bin/env bash 2 + 3 + function atfile.print() { 4 + key="$1" 5 + unset error 6 + 7 + # shellcheck disable=SC2154 8 + atfile.say.debug "Getting record...\nโ†ณ NSID: $_nsid_upload\nโ†ณ Repo: $_username\nโ†ณ Key: $key" 9 + record="$(com.atproto.repo.getRecord "$_username" "$_nsid_upload" "$key")" 10 + error="$(atfile.util.get_xrpc_error $? "$record")" 11 + 12 + if [[ -z "$error" ]]; then 13 + blob_uri="$(atfile.util.build_blob_uri "$(echo "$record" | jq -r ".uri" | cut -d "/" -f 3)" "$(echo "$record" | jq -r ".value.blob.ref.\"\$link\"")")" 14 + 15 + curl -H "$(atfile.util.get_uas)" -s -L "$blob_uri" --output - 16 + # shellcheck disable=SC2181 17 + [[ $? != 0 ]] && error="?" 18 + fi 19 + 20 + if [[ -n "$error" ]]; then 21 + atfile.die "Unable to cat '$key'" "$error" 22 + fi 23 + }
+1 -1
src/commands/update.sh
··· 97 97 [[ $? != 0 ]] && atfile.die "Unable to create temporary file (do you have permission?)" 98 98 99 99 atfile.say.debug "Getting blob URL for $latest_version ($latest_version_record_id)..." 100 - blob_url="$(atfile.invoke.get_url "$latest_version_record_id")" 100 + blob_url="$(atfile.get_url "$latest_version_record_id")" 101 101 # shellcheck disable=SC2181 102 102 [[ $? != 0 ]] && atfile.die "Unable to get blob URL" 103 103
+165
src/commands/upload.sh
··· 1 + #!/usr/bin/env bash 2 + 3 + function atfile.upload() { 4 + file="$1" 5 + recipient="$2" 6 + key="$3" 7 + unset error 8 + 9 + if [[ ! -f "$file" ]]; then 10 + atfile.die "File '$file' does not exist" 11 + else 12 + file="$(atfile.util.get_realpath "$file")" 13 + fi 14 + 15 + if [[ -n $recipient ]]; then 16 + file_crypt="$(dirname "$file")/$(basename "$file").gpg" 17 + 18 + # shellcheck disable=SC2154 19 + [[ $_output_json == 0 ]] && echo -e "Encrypting '$file_crypt'..." 20 + gpg --yes --quiet --recipient "$recipient" --output "$file_crypt" --encrypt "$file" 21 + 22 + # shellcheck disable=SC2181 23 + if [[ $? == 0 ]]; then 24 + file="$file_crypt" 25 + else 26 + rm -f "$file_crypt" 27 + atfile.die "Unable to encrypt '$(basename "$file")'" 28 + fi 29 + fi 30 + 31 + if [[ -z "$error" ]]; then 32 + unset file_date 33 + unset file_size 34 + unset file_type 35 + 36 + # shellcheck disable=SC2154 37 + case "$_os" in 38 + "bsd"|"macos") 39 + file_date="$(atfile.util.get_date "$(stat -f '%Sm' -t "%Y-%m-%dT%H:%M:%SZ" "$file")")" 40 + file_size="$(stat -f '%z' "$file")" 41 + file_type="$(file -b --mime-type "$file")" 42 + ;; 43 + "haiku") 44 + haiku_file_attr="$(catattr BEOS:TYPE "$file" 2> /dev/null)" 45 + # shellcheck disable=SC2181 46 + [[ $? == 0 ]] && file_type="$(echo "$haiku_file_attr" | cut -d ":" -f 3 | xargs)" 47 + 48 + file_date="$(atfile.util.get_date "$(stat -c '%y' "$file")")" 49 + file_size="$(stat -c %s "$file")" 50 + ;; 51 + *) 52 + file_date="$(atfile.util.get_date "$(stat -c '%y' "$file")")" 53 + file_size="$(stat -c %s "$file")" 54 + file_type="$(file -b --mime-type "$file")" 55 + ;; 56 + esac 57 + 58 + file_hash="$(atfile.util.get_md5 "$file")" 59 + file_hash_checksum="$(echo "$file_hash" | cut -d "|" -f 1)" 60 + file_hash_type="$(echo "$file_hash" | cut -d "|" -f 2)" 61 + file_name="$(basename "$file")" 62 + 63 + if [[ -n $recipient ]]; then 64 + file_type="application/prs.atfile.gpg-crypt" 65 + elif [[ "$file_type" == "application/"* ]]; then 66 + file_extension="${file_name##*.}" 67 + 68 + case "$file_extension" in 69 + "car") file_type="application/prs.atfile.car" ;; 70 + "dmg"|"smi") file_type="application/x-apple-diskimage" ;; 71 + esac 72 + fi 73 + 74 + file_type_emoji="$(atfile.util.get_file_type_emoji "$file_type")" 75 + 76 + # shellcheck disable=SC2154 77 + atfile.say.debug "File: $file\nโ†ณ Date: $file_date\nโ†ณ Hash: $file_hash_checksum ($file_hash_type)\nโ†ณ Name: $file_name\nโ†ณ Size: $file_size\nโ†ณ Type: $file_type_emoji $file_type" 78 + 79 + unset file_finger_record 80 + unset file_meta_record 81 + 82 + file_finger_record="$(atfile.util.get_finger_record)" 83 + file_meta_record="$(atfile.util.get_meta_record "$file" "$file_type")" 84 + 85 + atfile.say.debug "Checking filesize..." 86 + # shellcheck disable=SC2154 87 + file_size_surplus="$(atfile.util.get_file_size_surplus_for_pds "$file_size" "$_server")" 88 + 89 + if [[ $file_size_surplus != 0 ]]; then 90 + die_message="File '$file_name' is too large ($(atfile.util.get_file_size_pretty "$file_size_surplus") over)" 91 + atfile.die "$die_message" 92 + fi 93 + 94 + # shellcheck disable=SC2154 95 + [[ $_output_json == 0 ]] && echo "Uploading '$file'..." 96 + 97 + blob="$(com.atproto.sync.uploadBlob "$file")" 98 + error="$(atfile.util.get_xrpc_error $? "$blob")" 99 + [[ $error == "?" ]] && error="Blob rejected by PDS (too large?)" 100 + 101 + atfile.say.debug "Uploading blob...\nโ†ณ Ref: $(echo "$blob" | jq -r ".ref.\"\$link\"")" 102 + 103 + if [[ -z "$error" ]]; then 104 + # shellcheck disable=SC2154 105 + file_record="$(blue.zio.atfile.upload "$blob" "$_now" "$file_hash_checksum" "$file_hash_type" "$file_date" "$file_name" "$file_size" "$file_type" "$file_meta_record" "$file_finger_record")" 106 + 107 + if [[ -n "$key" ]]; then 108 + # shellcheck disable=SC2154 109 + atfile.say.debug "Updating record...\nโ†ณ NSID: $_nsid_upload\nโ†ณ Repo: $_username\nโ†ณ Key: $key" 110 + record="$(com.atproto.repo.putRecord "$_username" "$_nsid_upload" "$key" "$file_record")" 111 + error="$(atfile.util.get_xrpc_error $? "$record")" 112 + else 113 + # shellcheck disable=SC2154 114 + atfile.say.debug "Creating record...\nโ†ณ NSID: $_nsid_upload\nโ†ณ Repo: $_username" 115 + record="$(com.atproto.repo.createRecord "$_username" "$_nsid_upload" "$file_record")" 116 + error="$(atfile.util.get_xrpc_error $? "$record")" 117 + fi 118 + fi 119 + fi 120 + 121 + if [[ -n $recipient ]]; then 122 + rm -f "$file" 123 + fi 124 + 125 + if [[ -z "$error" ]]; then 126 + unset recipient_key 127 + blob_uri="$(atfile.util.build_blob_uri "$(echo "$record" | jq -r ".uri" | cut -d "/" -f 3)" "$(echo "$blob" | jq -r ".ref.\"\$link\"")")" 128 + key="$(atfile.util.get_rkey_from_at_uri "$(echo "$record" | jq -r ".uri")")" 129 + 130 + if [[ -n "$recipient" ]]; then 131 + recipient_key="$(gpg --list-keys "$recipient" | sed -n 2p | xargs)" 132 + fi 133 + 134 + # shellcheck disable=SC2154 135 + if [[ $_output_json == 1 ]]; then 136 + unset recipient_json 137 + 138 + if [[ -n "$recipient" ]]; then 139 + recipient_json="{ \"id\": \"$recipient\", \"key\": \"$recipient_key\" }" 140 + else 141 + recipient_json="null" 142 + fi 143 + 144 + echo -e "{ \"blob\": \"$blob_uri\", \"key\": \"$key\", \"upload\": $record, \"recipient\": $recipient_json }" | jq 145 + else 146 + echo "---" 147 + # shellcheck disable=SC2154 148 + if [[ $_os == "haiku" ]]; then 149 + # BUG: Haiku Terminal has issues with emojis 150 + echo "Uploaded: $file_name" 151 + else 152 + echo "Uploaded: $file_type_emoji $file_name" 153 + fi 154 + atfile.util.print_blob_url_output "$blob_uri" 155 + echo -e "โ†ณ Key: $key" 156 + # shellcheck disable=SC2154 157 + echo -e "โ†ณ URI: atfile://$_username/$key" 158 + if [[ -n "$recipient" ]]; then 159 + echo -e "โ†ณ Recipient: $recipient ($recipient_key)" 160 + fi 161 + fi 162 + else 163 + atfile.die.xrpc_error "Unable to upload '$file'" "$error" 164 + fi 165 + }
+15 -15
src/shared/invoke.sh
··· 15 15 ;; 16 16 "blob") 17 17 case "${args[0]}" in 18 - "list"|"ls"|"l") atfile.invoke.blob_list "${args[1]}" ;; 19 - "upload"|"u") atfile.invoke.blob_upload "${args[1]}" ;; 18 + "list"|"ls"|"l") atfile.blob_list "${args[1]}" ;; 19 + "upload"|"u") atfile.blob_upload "${args[1]}" ;; 20 20 *) atfile.die.unknown_command "$(echo "$command ${args[0]}" | xargs)" ;; 21 - esac 21 + esac 22 22 ;; 23 23 "bsky") 24 24 if [[ -z "${args[0]}" ]]; then ··· 41 41 atfile.util.override_actor "${args[1]}" 42 42 fi 43 43 44 - atfile.invoke.print "${args[0]}" 44 + atfile.print "${args[0]}" 45 45 ;; 46 46 "delete") 47 47 [[ -z "${args[0]}" ]] && atfile.die "<key> not set" 48 - atfile.invoke.delete "${args[0]}" 48 + atfile.delete "${args[0]}" 49 49 ;; 50 50 "fetch") 51 51 [[ -z "${args[0]}" ]] && atfile.die "<key> not set" ··· 53 53 atfile.util.override_actor "${args[1]}" 54 54 fi 55 55 56 - atfile.invoke.download "${args[0]}" 56 + atfile.download "${args[0]}" 57 57 ;; 58 58 "fetch-crypt") 59 59 atfile.util.check_prog_gpg ··· 62 62 atfile.util.override_actor "${args[1]}" 63 63 fi 64 64 65 - atfile.invoke.download "${args[0]}" 1 65 + atfile.download "${args[0]}" 1 66 66 ;; 67 67 "handle") 68 68 uri="${args[0]}" ··· 89 89 atfile.util.override_actor "${args[1]}" 90 90 fi 91 91 92 - atfile.invoke.get "${args[0]}" 92 + atfile.get "${args[0]}" 93 93 ;; 94 94 "install") 95 95 # TODO: Disable when installed (how?), similar to `release` ··· 103 103 104 104 atfile.util.override_actor "${args[0]}" 105 105 106 - atfile.invoke.list "${args[1]}" 106 + atfile.list "${args[1]}" 107 107 else 108 108 if [[ -n "${args[1]}" ]]; then 109 109 atfile.util.override_actor "${args[1]}" 110 110 fi 111 - atfile.invoke.list "${args[0]}" 111 + atfile.list "${args[0]}" 112 112 fi 113 113 ;; 114 114 "lock") 115 - atfile.invoke.lock "${args[0]}" 1 115 + atfile.lock "${args[0]}" 1 116 116 ;; 117 117 "now") 118 118 atfile.now "${args[0]}" ··· 147 147 "upload") 148 148 atfile.util.check_prog_optional_metadata 149 149 [[ -z "${args[0]}" ]] && atfile.die "<file> not set" 150 - atfile.invoke.upload "${args[0]}" "" "${args[1]}" 150 + atfile.upload "${args[0]}" "" "${args[1]}" 151 151 ;; 152 152 "upload-crypt") 153 153 atfile.util.check_prog_optional_metadata 154 154 atfile.util.check_prog_gpg 155 155 [[ -z "${args[0]}" ]] && atfile.die "<file> not set" 156 156 [[ -z "${args[1]}" ]] && atfile.die "<recipient> not set" 157 - atfile.invoke.upload "${args[0]}" "${args[1]}" "${args[2]}" 157 + atfile.upload "${args[0]}" "${args[1]}" "${args[2]}" 158 158 ;; 159 159 "unlock") 160 - atfile.invoke.lock "${args[0]}" 0 160 + atfile.lock "${args[0]}" 0 161 161 ;; 162 162 "update") 163 163 atfile.update install ··· 168 168 atfile.util.override_actor "${args[1]}" 169 169 fi 170 170 171 - atfile.invoke.get_url "${args[0]}" 171 + atfile.get_url "${args[0]}" 172 172 ;; 173 173 "version") 174 174 echo -e "$_version"