📦➔🦋 Store and retrieve files on the Atmosphere
1#!/usr/bin/env bash
2
3function 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.xrpc_error "Unable to lock '$key'" "$error"
42 else
43 atfile.die.xrpc_error "Unable to unlock '$key'" "$error"
44 fi
45 fi
46}