📦➔🦋 Store and retrieve files on the Atmosphere
1#!/usr/bin/env bash
2
3# PDS
4
5function atfile.xrpc.pds.blob() {
6 file="$1"
7 type="$2"
8 lexi="$3"
9
10 [[ -z $lexi ]] && lexi="com.atproto.repo.uploadBlob"
11 [[ -z $type ]] && type="*/*"
12
13 atfile.http.upload \
14 "$_server/xrpc/$lexi" \
15 "$file" \
16 "Bearer $(atfile.xrpc.pds.jwt)" \
17 "$type" | jq
18}
19
20function atfile.xrpc.pds.get() {
21 lexi="$1"
22 query="$2"
23 type="$3"
24 endpoint="$4"
25
26 [[ -z $endpoint ]] && endpoint="$_server"
27
28 atfile.http.get \
29 "$endpoint/xrpc/$lexi?$query" \
30 "Bearer $(atfile.xrpc.pds.jwt)" \
31 "$type" | jq
32}
33
34function atfile.xrpc.pds.jwt() {
35 atfile.http.post \
36 "$_server/xrpc/com.atproto.server.createSession" \
37 '{"identifier": "'"$_username"'", "password": "'"$_password"'"}' | jq -r ".accessJwt"
38}
39
40function atfile.xrpc.pds.post() {
41 lexi="$1"
42 data="$2"
43 type="$3"
44
45 [[ -z $type ]] && type="application/json"
46
47 curl -s -X POST "$_server/xrpc/$lexi" \
48 -H "Authorization: Bearer $(atfile.xrpc.pds.jwt)" \
49 -H "Content-Type: $type" \
50 -H "User-Agent: $(atfile.util.get_uas)" \
51 -d "$data" | jq
52}
53
54# AppView
55
56## Bluesky
57
58function atfile.xrpc.bsky.get() {
59 lexi="$1"
60 query="$2"
61 type="$3"
62 appview="$4"
63
64 # shellcheck disable=SC2154
65 [[ -z "$appview" ]] && appview="$_endpoint_appview"
66
67 atfile.http.get \
68 "$appview/xrpc/$lexi?$query" \
69 "" \
70 "$type" | jq
71}