repo: actpub
action: blob
revision:
path_from: ap-object2html
revision_from: refs/heads/master:
path_to:
revision_to:
blob of:
/ ap-object2html
refs/heads/master:/ap-object2html
#!/usr/bin/env bash
object_file="$1"
base="$(basename "${object_file}")"
if [ "$TILDE" ];then
cache_uri="/~${TILDE}/ap-cache/object/${base}"
else
cache_uri="/ap-cache/object/${base}"
fi
if [ ! -s "${object_file}" ];then
printf '\n'
printf 'error
\n'
printf 'the cached object file is empty somehow.
\n'
printf 'Cache File: %s
\n' "${object_file}"
printf 'Cached
\n' "${cache_uri}"
printf ' \n'
exit 1
fi
entitied_error="$(jq -r '.error//""' < "${object_file}" | html_entities_encode)"
if [ "$entitied_error" ];then
printf '\n'
printf 'error
\n'
printf "the json object is valid, but contains an 'error' key.
\n"
printf "value: %s
\n" "${entitied_error}"
printf 'Cache File: %s
\n' "${object_file}"
printf 'Cached
\n' "${cache_uri}"
printf ' \n'
exit 1
fi
type="$(jq -r '.type' < "${object_file}")"
printf 'Object Type: %s
' "${type}"
recursion_count="${2:-0}"
if [ "$recursion_count" -gt 10 ];then
printf "WHOOOOOOA THERE BUDDY. WE'RE RECURSING TOO DEEP.\n"
exit 1
fi
if [ ! "$object_file" ];then
printf "usage: ap-object2html