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

Configure Feed

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

record: refactor command

Ducky 5b2cc529 c1806024

+155 -102
+7 -8
src/commands/help.sh
··· 82 82 application <atfile-uri> opens with\n 83 83 now 84 84 Get date in ISO-8601 format\n 85 - record add <record-json> [<collection>] 86 - record get <key> [<collection>] [<actor>] 85 + record list <at-uri> 86 + record create <collection> <record-json> 87 + record create <at-uri> <record-json> 87 88 record get <at-uri> 88 - record put <key> <record-json> [<collection>] 89 - record put <at-uri> <record-json> 90 - record rm <key> [<collection>] 91 - record rm <at-uri> 89 + record update <at-uri> <record-json> 90 + record recreate <at-uri> <record-json> 91 + record delete <at-uri> 92 92 Manage records on a repository 93 - āš ļø No validation is performed. Here be dragons! 94 - ā„¹ļø <collection> defaults to '$_nsid_upload'\n 93 + āš ļø No validation is performed. Here be dragons!\n 95 94 resolve <actor> 96 95 Get details for <actor>\n 97 96 stream [<collection(s)>] [<did(s)>] [<cursor>] [<compress>]
-88
src/commands/old_cmds.sh
··· 518 518 fi 519 519 } 520 520 521 - function atfile.invoke.manage_record() { 522 - function atfile.invoke.manage_record.get_collection() { 523 - collection="$_nsid_upload" 524 - parameter_output="$1" 525 - 526 - [[ -n "$parameter_output" ]] && collection="$1" # fuck it, manage all the records from atfile! 527 - echo "$collection" 528 - } 529 - 530 - case "$1" in 531 - "create") 532 - collection="$(atfile.invoke.manage_record.get_collection "$3")" 533 - record="$2" 534 - [[ -z "$record" ]] && atfile.die "<record> not set" 535 - 536 - record_json="$(echo "$record" | jq)" 537 - # shellcheck disable=SC2181 538 - [[ $? != 0 ]] && atfile.die "Invalid JSON" 539 - 540 - com.atproto.repo.createRecord "$_username" "$collection" "$record_json" | jq 541 - ;; 542 - "delete") 543 - collection="$(atfile.invoke.manage_record.get_collection "$3")" 544 - key="$2" 545 - [[ -z "$key" ]] && atfile.die "<key/at-uri> not set" 546 - 547 - if [[ "$key" == at:* ]]; then 548 - at_uri="$key" 549 - collection="$(echo "$at_uri" | cut -d "/" -f 4)" 550 - key="$(echo "$at_uri" | cut -d "/" -f 5)" 551 - username="$(echo "$at_uri" | cut -d "/" -f 3)" 552 - 553 - [[ "$username" != "$_username" ]] && atfile.die "Unable to delete record — not owned by you ($_username)" 554 - fi 555 - 556 - com.atproto.repo.deleteRecord "$_username" "$collection" "$key" | jq 557 - ;; 558 - "get") 559 - collection="$(atfile.invoke.manage_record.get_collection "$3")" 560 - key="$2" 561 - username="$4" 562 - [[ -z "$key" ]] && atfile.die "<key/at-uri> not set" 563 - 564 - if [[ "$key" == at:* ]]; then 565 - at_uri="$key" 566 - collection="$(echo "$at_uri" | cut -d "/" -f 4)" 567 - key="$(echo "$at_uri" | cut -d "/" -f 5)" 568 - username="$(echo "$at_uri" | cut -d "/" -f 3)" 569 - fi 570 - 571 - if [[ -z "$username" ]]; then 572 - username="$_username" 573 - else 574 - # shellcheck disable=SC2053 575 - if [[ $username != $_username ]]; then 576 - atfile.util.override_actor "$username" 577 - fi 578 - fi 579 - 580 - com.atproto.repo.getRecord "$username" "$collection" "$key" | jq 581 - atfile.util.override_actor_reset 582 - ;; 583 - # BUG: Collection is always blue.zio.atfile.upload when not using at:// 584 - "put") 585 - collection="$(atfile.invoke.manage_record.get_collection "$4")" 586 - key="$2" 587 - record="$3" 588 - [[ -z "$key" ]] && atfile.die "<key/at-uri> not set" 589 - [[ -z "$record" ]] && atfile.die "<record> not set" 590 - 591 - record_json="$(echo "$record" | jq)" 592 - # shellcheck disable=SC2181 593 - [[ $? != 0 ]] && atfile.die "Invalid JSON" 594 - 595 - if [[ "$key" == at:* ]]; then 596 - at_uri="$key" 597 - collection="$(echo "$at_uri" | cut -d "/" -f 4)" 598 - key="$(echo "$at_uri" | cut -d "/" -f 5)" 599 - username="$(echo "$at_uri" | cut -d "/" -f 3)" 600 - 601 - [[ "$username" != "$_username" ]] && atfile.die "Unable to put record — not owned by you ($_username)" 602 - fi 603 - 604 - com.atproto.repo.putRecord "$_username" "$collection" "$key" "$record" | jq 605 - ;; 606 - esac 607 - } 608 - 609 521 function atfile.invoke.print() { 610 522 key="$1" 611 523 unset error
+126
src/commands/record.sh
··· 1 + #!/usr/bin/env bash 2 + 3 + # shellcheck disable=SC2120 4 + function atfile.record() { 5 + function atfile.record.output_record() { 6 + # shellcheck disable=SC2154 7 + if [[ "$_output_json" == 1 ]]; then 8 + echo "{ \"uri\": \"$1\", \"cid\": \"$2\", \"record\": $3 }" | jq 9 + else 10 + echo "⚔ $1" 11 + echo "šŸ“¦ $2" 12 + echo "---" 13 + echo "$3" | jq 14 + fi 15 + } 16 + 17 + sub_command="$1" 18 + at_uri="$2" 19 + record="$3" 20 + 21 + unset record_json 22 + unset output_json 23 + unset output_return 24 + unset at_actor 25 + unset at_collection 26 + unset at_rkey 27 + 28 + if [[ "$sub_command" == "create" && "$at_uri" != "at://"* ]]; then 29 + # shellcheck disable=SC2154 30 + at_uri="at://$_username/$at_uri" 31 + fi 32 + 33 + if [[ "$sub_command" != "delete" ]] &&\ 34 + [[ "$sub_command" != "get" ]]; then 35 + if [[ -z "$record" ]]; then 36 + atfile.die "<record> not set" 37 + else 38 + record_json="$(echo "$record" | jq)" 39 + # shellcheck disable=SC2181 40 + [[ $? != 0 ]] && atfile.die "Invalid JSON" 41 + fi 42 + fi 43 + 44 + [[ "$at_uri" != "at://"* ]] && atfile.die \ 45 + "Invalid AT URI\n↳ Must be 'at://<actor>[/<collection>[/<rkey>]]'" 46 + 47 + at_actor="$(atfile.util.parse_at_uri "$at_uri" "actor")" 48 + at_collection="$(atfile.util.parse_at_uri "$at_uri" "collection")" 49 + at_rkey="$(atfile.util.parse_at_uri "$at_uri" "rkey")" 50 + 51 + case "$sub_command" in 52 + "create") 53 + if [[ -z "$at_rkey" ]]; then 54 + output_json="$(com.atproto.repo.createRecord "$at_actor" "$at_collection" "$record_json")" 55 + output_return="$?" 56 + else 57 + output_json="$(com.atproto.repo.putRecord "$at_actor" "$at_collection" "$at_rkey" "$record_json")" 58 + output_return="$?" 59 + fi 60 + ;; 61 + "delete") 62 + output_json="$(com.atproto.repo.deleteRecord "$at_actor" "$at_collection" "$at_rkey")" 63 + output_return="$?" 64 + ;; 65 + "get") 66 + output_json="$(com.atproto.repo.getRecord "$at_actor" "$at_collection" "$at_rkey")" 67 + output_return="$?" 68 + ;; 69 + "recreate") 70 + output_json="$(com.atproto.repo.deleteRecord "$at_actor" "$at_collection" "$at_rkey")" 71 + output_return="$?" 72 + output_json="$(com.atproto.repo.putRecord "$at_actor" "$at_collection" "$at_rkey" "$record_json")" 73 + output_return="$?" 74 + ;; 75 + "update") 76 + output_json="$(com.atproto.repo.putRecord "$at_actor" "$at_collection" "$at_rkey" "$record_json")" 77 + output_return="$?" 78 + ;; 79 + esac 80 + 81 + error="$(atfile.util.get_xrpc_error "$output_return" "$output_json")" 82 + [[ -n "$error" ]] && atfile.die.xrpc_error "Unable to $sub_command '$at_uri'" "$output_json" 83 + 84 + case "$sub_command" in 85 + "create"|"recreate"|"update") 86 + atfile.record.output_record \ 87 + "$(echo "$output_json" | jq -r .uri)" \ 88 + "$(echo "$output_json" | jq -r .commit.cid)" \ 89 + "$record_json" 90 + ;; 91 + "delete") 92 + atfile.record.output_record \ 93 + "$at_uri" \ 94 + "$(echo "$output_json" | jq -r .commit.cid)" \ 95 + "null" 96 + ;; 97 + *) 98 + atfile.record.output_record \ 99 + "$(echo "$output_json" | jq -r .uri)" \ 100 + "$(echo "$output_json" | jq -r .cid)" \ 101 + "$(echo "$output_json" | jq -r .value)" 102 + ;; 103 + esac 104 + } 105 + 106 + function atfile.record_list() { 107 + at_uri="$1" 108 + 109 + unset at_actor 110 + unset at_collection 111 + unset at_rkey 112 + 113 + [[ "$at_uri" != "at://"* ]] && atfile.die \ 114 + "Invalid AT URI\n↳ Must be 'at://<actor>[/<collection>]'" 115 + 116 + at_actor="$(atfile.util.parse_at_uri "$at_uri" "actor")" 117 + at_collection="$(atfile.util.parse_at_uri "$at_uri" "collection")" 118 + at_rkey="$(atfile.util.parse_at_uri "$at_uri" "rkey")" 119 + 120 + if [[ -n "$at_rkey" ]]; then 121 + atfile.record get "$at_uri" 122 + return 123 + fi 124 + 125 + atfile.die "Not yet implemented!" 126 + }
+6 -5
src/entry.sh
··· 240 240 _prog_hint_jq="pkgman install jq" 241 241 fi 242 242 243 - atfile.say.debug "Checking required programs..." 244 243 atfile.util.check_prog "curl" "https://curl.se" 245 244 [[ $_os != "haiku" && $_os != "solaris" ]] && atfile.util.check_prog "file" "https://www.darwinsys.com/file" 246 245 atfile.util.check_prog "jq" "$_prog_hint_jq" ··· 414 413 "record") 415 414 # NOTE: Performs no validation (apart from JSON)! Here be dragons 416 415 case "$2" in 417 - "add"|"create"|"c") atfile.invoke.manage_record "create" "$3" "$4" ;; 418 - "get"|"g") atfile.invoke.manage_record "get" "$3" "$4" "$5" ;; 419 - "put"|"update"|"u") atfile.invoke.manage_record "put" "$3" "$4" ;; 420 - "rm"|"delete"|"d") atfile.invoke.manage_record "delete" "$3" "$4" ;; 416 + "add"|"create"|"c") atfile.record "create" "$3" "$4" ;; 417 + "get"|"g") atfile.record "get" "$3" ;; 418 + "ls"|"list"|"l") atfile.record_list "$3" ;; 419 + "put"|"update"|"u") atfile.record "update" "$3" "$4" ;; 420 + "rc"|"recreate"|"r") atfile.record "recreate" "$3" "$4" ;; 421 + "rm"|"delete"|"d") atfile.record "delete" "$3" ;; 421 422 *) atfile.die.unknown_command "$(echo "$_command $2" | xargs)" ;; 422 423 esac 423 424 ;;
+1 -1
src/shared/die.sh
··· 43 43 xrpc_error="$2" 44 44 45 45 [[ "$xrpc_error" == "?" ]] && unset xrpc_error 46 - [[ -n "$xrpc_error" ]] && message="$message\n↳ $xrpc_error" 46 + [[ -n "$xrpc_error" && "$xrpc_error" != "{}" ]] && message="$message\n↳ $xrpc_error" 47 47 48 48 atfile.die "$message" 49 49 }
+15
src/shared/util.sh
··· 36 36 command="$1" 37 37 download_hint="$2" 38 38 skip_hint="$3" 39 + 40 + atfile.say.debug "Checking program '$1' exists..." 39 41 40 42 if ! [ -x "$(command -v "$command")" ]; then 41 43 message="'$command' not installed" ··· 895 897 *) echo "$uri" 896 898 esac 897 899 fi 900 + } 901 + 902 + function atfile.util.parse_at_uri() { 903 + at_uri="$1" 904 + segment="$2" 905 + unset parsed_at_uri 906 + 907 + case $segment in 908 + "actor"|"did"|"handle") echo "$at_uri" | cut -d "/" -f 3 ;; 909 + "collection") echo "$at_uri" | cut -d "/" -f 4 ;; 910 + "key"|"rkey") echo "$at_uri" | cut -d "/" -f 5 ;; 911 + *) echo "$at_uri" | cut -d "/" -f "$segment" ;; 912 + esac 898 913 } 899 914 900 915 function atfile.util.get_uri_segment() {