repo: actpub
action: blob
revision: 
path_from: ap-cacheobject
revision_from: refs/heads/master:
path_to: 
revision_to: 
git.thebackupbox.net
actpub
git clone git://git.thebackupbox.net/actpub

blob of:

actpub

/ ap-cacheobject

blob_plain of this file

refs/heads/master:/ap-cacheobject

 #!/usr/bin/env bash

 if [ ! "$1" ];then
   printf 'Usage: ap-cacheobject \n' >&2
   exit 1
 fi

 uri="$1"

 mkdir -p ~/.cache/ap/object

 cache_file=~/.cache/ap/object/"$(sha256sum <<< "$uri" | cut '-d ' -f1)"

 if [ ! -s "$cache_file" ];then
   RESPONSE="$(ap-signed-get "$uri")"
   OBJECT_DATA="$(printf "%s" "$RESPONSE" | jq -r '. | to_entries | .[].value | select(if type == "object" then . else null end) | select(if .id == "'"$uri"'" then . else null end)')"
   if [ "$OBJECT_DATA" ];then #we didn't find it... guess just output the original response.
     printf '%s' "$OBJECT_DATA" #should be all good.
   else
     printf '%s' "$RESPONSE" # so we can see errors.
   fi > "${cache_file}"
 fi

 printf "%s\n" "${cache_file}"