📦➔🦋 Store and retrieve files on the Atmosphere
1#!/usr/bin/env bash
2
3function atfile.resolve() {
4 actor="$1"
5
6 [[ -z $actor && -n $_username ]] && actor="$_username"
7
8 atfile.say.debug "Resolving actor '$actor'..."
9
10 resolved_did="$(atfile.util.resolve_identity "$actor")"
11 error="$(atfile.util.get_xrpc_error $? "$resolved_did")"
12 [[ -n "$error" ]] && atfile.die.xrpc_error "Unable to resolve '$actor'" "$resolved_did"
13
14 aliases="$(echo "$resolved_did" | cut -d "|" -f 5)"
15 did="$(echo "$resolved_did" | cut -d "|" -f 1)"
16 did_doc="$(echo "$resolved_did" | cut -d "|" -f 4)/$did"
17 did_type="did:$(echo "$did" | cut -d ":" -f 2)"
18 handle="$(echo "$resolved_did" | cut -d "|" -f 3 | cut -d "/" -f 3)"
19 pds="$(echo "$resolved_did" | cut -d "|" -f 2)"
20 pds_name="$(atfile.util.get_pds_pretty "$pds")"
21 pds_software="Bluesky PDS"
22 atfile.say.debug "Getting PDS version for '$pds'..."
23 pds_version="$(curl -H "User-Agent: $(atfile.util.get_uas)" -s -l -X GET "$pds/xrpc/_health" | jq -r '.version')"
24
25 if [[ "$pds_version" == *" v"* ]]; then
26 pds_software="🐌 $(echo "$pds_version" | sed -s 's/ v/\n/g' | sed -n 1p)"
27 pds_version="$(echo "$pds_version" | sed -s 's/ v/\n/g' | sed -n 2p)"
28
29 if [[ "$pds_name" == "$(atfile.util.get_uri_segment "$pds" host)" ]]; then
30 pds_name="$pds_software"
31 fi
32 fi
33
34 case "$did_type" in
35 "did:web")
36 did_doc="$(atfile.util.get_didweb_doc_url "$did")"
37 ;;
38 esac
39
40 # shellcheck disable=SC2154
41 if [[ $_output_json == 1 ]]; then
42 did_doc_data="$(curl -H "User-Agent: $(atfile.util.get_uas)" -s -l -X GET "$did_doc")"
43 aliases_json="$(echo "$did_doc_data" | jq -r ".alsoKnownAs")"
44
45 echo -e "{
46 \"aka\": $aliases_json,
47 \"did\": \"$did\",
48 \"doc\": {
49 \"data\": $did_doc_data,
50 \"url\": \"$did_doc\"
51 },
52 \"handle\": \"$handle\",
53 \"pds\": {
54 \"endpoint\": \"$pds\",
55 \"name\": \"$pds_name\",
56 \"software\": {
57 \"name\": \"$pds_software\",
58 \"version\": \"$pds_version\"
59 }
60 },
61 \"type\": \"$did_type\"
62}" | jq
63 else
64 atfile.say "$did"
65 atfile.say "↳ Type: $did_type"
66 atfile.say " ↳ Doc: $did_doc"
67 atfile.say "↳ Handle: @$handle"
68
69 while IFS=$";" read -ra a; do
70 unset first_alias
71
72 for i in "${a[@]}"; do
73 if [[ -z "$first_alias" ]]; then
74 atfile.say " ↳ $i"
75 else
76 atfile.say " $i"
77 fi
78
79 first_alias="${a[0]}"
80 done
81 done <<< "$aliases"
82
83 atfile.say "↳ PDS: $pds_name"
84 atfile.say " ↳ Endpoint: $pds"
85 [[ $(atfile.util.is_null_or_empty "$pds_version") == 0 ]] && atfile.say " ↳ Version: $pds_version"
86 fi
87}