mirror of
https://git.sr.ht/~seirdy/seirdy.one
synced 2024-12-25 02:02:11 +00:00
46 lines
1.3 KiB
Bash
46 lines
1.3 KiB
Bash
#!/bin/sh
|
|
#
|
|
# Script to fetch all approved webmentions from webmentiond as a big json response.
|
|
# Uses POSIX and cURL in CI, also uses any pass/pash-compatible pwmngr otherwise
|
|
# The response is cached for 90 minutes.
|
|
|
|
set -e -u
|
|
|
|
auth_url='https://seirdy.one/webmentions/authenticate/access-key'
|
|
webmentions_url='https://seirdy.one/webmentions/manage/mentions?limit=9999&status=approved'
|
|
webmentions_file="$(realpath data/webmentions.json)"
|
|
|
|
# just a little curl wrapper I use on seirdy.one
|
|
alias ccurl='curl --proto "=https" --proto-default https --tlsv1.3 --cert-status'
|
|
|
|
# use a long-lived key (password) to fetch a short-lived bearer token.
|
|
key() {
|
|
set +u
|
|
if [ -n "$BUILD_SUBMITTER" ]; then
|
|
cat ~/.webmentiond-key
|
|
else
|
|
pash show webmentiond-ci-key
|
|
fi
|
|
set -u
|
|
}
|
|
|
|
token() {
|
|
key_response="$(key)"
|
|
ccurl -sX POST "$auth_url" -d "key=$key_response"
|
|
}
|
|
|
|
# use that token to fetch all webmentions
|
|
fetch_webmentions() {
|
|
token_response="$(token)"
|
|
ccurl --compressed -H "Authorization: Bearer $token_response" "$webmentions_url" -o "$webmentions_file"
|
|
}
|
|
|
|
# fetch webmentions if we don't have a fresh copy already.
|
|
|
|
if [ -f "$webmentions_file" ] \
|
|
&& [ "$(find "$webmentions_file" -mmin +90)" = "" ]; then
|
|
echo 'Using cached webmentions'
|
|
else
|
|
echo 'Fetching webmentions'
|
|
fetch_webmentions
|
|
fi
|