repo: actpub action: blob revision: path_from: ap-getactor revision_from: refs/heads/master: path_to: revision_to:
blob of:
/ ap-getactor
refs/heads/master:/ap-getactor
#!/bin/bash no_cache=0 if [ "$1" == "--no-cache" ];then no_cache=1 shift fi if [ ! "$1" ];then printf "usage: ap-getactor\n" >&2 exit 1 fi user="$(printf "%s\n" "$1" | sed 's/^@//' | cut -d@ -f1)" domain="$(printf "%s\n" "$1" | sed 's/^@//' | cut -d@ -f2)" target="${user}@${domain}" mkdir -p ~/.cache/ap/actor cache_file=~/.cache/ap/actor/${target} if [ ! -s ${cache_file} -o "${no_cache}" = 1 ];then printf "ap-getactor: downloading actor file for %s@%s\n" "${user}" "${domain}" >&2 #find ~/.cache/ap/actor -mtime 30 -rm # clear cache after 30 minutes. ### I want to get the Cache-Control: max-age=180, derp header, ### then get the max-age's value, ### then set the mtime of the file that far into the future. ### so I can find -mtime 0 . -rm on all of the object files. anything in the past gets deleted. ### NOTICE: some servers require you to use signed GETs to get an actor file. actor_uri="$(ap-getactoruri "$target")" ap-signed-get "${actor_uri}" > "${cache_file}" cache_file2=~/.cache/ap/actor/"$(sha256sum <<< "${actor_uri}" | cut '-d ' -f1)" ln -s ${cache_file} ${cache_file2} #id="$(date +%s)" #touch -mt "/tmp/${id}" #mv "/tmp/${id}" "${cache_file}" else printf "ap-getactor: using cached actor file for %s@%s\n" "${user}" "${domain}" >&2 fi cat "${cache_file}"