diff options
author | June McEnroe <june@causal.agency> | 2025-06-01 22:34:07 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2025-06-01 22:34:07 -0400 |
commit | 849b32bf42eb8a3f600fed555c48c29dd7b9c694 (patch) | |
tree | c4defa058e7d0ae9866e388a64b55e89a1516af2 | |
parent | Remove something (diff) | |
download | src-master.tar.gz src-master.zip |
-rw-r--r-- | www/photo.causal.agency/.gitignore | 5 | ||||
-rw-r--r-- | www/photo.causal.agency/mastodon.sh | 54 |
2 files changed, 58 insertions, 1 deletions
diff --git a/www/photo.causal.agency/.gitignore b/www/photo.causal.agency/.gitignore index 4e55d718..e6e1a830 100644 --- a/www/photo.causal.agency/.gitignore +++ b/www/photo.causal.agency/.gitignore @@ -1,3 +1,6 @@ -*.JPG *.jpg +*.JPG +app.json +posted.txt static/ +token.json diff --git a/www/photo.causal.agency/mastodon.sh b/www/photo.causal.agency/mastodon.sh new file mode 100644 index 00000000..1eaa1114 --- /dev/null +++ b/www/photo.causal.agency/mastodon.sh @@ -0,0 +1,54 @@ +#!/bin/sh +set -eu + +Instance=https://tilde.zone +Root=${1:-static} + +if ! test -f app.json; then + echo 'No app.json!' >&2 + exit 1 +fi +chmod 600 app.json + +if ! test -f token.json; then + client_id=$(jq -r .client_id app.json) + client_secret=$(jq -r .client_secret app.json) + echo "Please open ${Instance}/oauth/authorize?client_id=${client_id}&scope=write&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code" + printf 'Enter code: ' + read -r code + curl -Ss -X POST \ + -F 'grant_type=authorization_code' \ + -F "client_id=${client_id}" \ + -F "client_secret=${client_secret}" \ + -F 'redirect_uri=urn:ietf:wg:oauth:2.0:oob' \ + -F "code=${code}" \ + ${Instance}/oauth/token >token.json +fi +chmod 600 token.json + +access_token=$(jq -r .access_token token.json) + +if ! test -f posted.txt; then + touch posted.txt +fi + +photo=$( + find ${Root} -type f -path '*/0*/*.jpg' | + sort | comm -13 posted.txt - | head -n 1 +) +preview=${Root}/preview/${photo##*/} + +media_id=$( + curl -Ss -X POST \ + -H "Authorization: Bearer ${access_token}" \ + -F "file=@${preview}" \ + ${Instance}/api/v2/media | + jq -r .id +) + +curl -Ss -X POST \ + -H "Authorization: Bearer ${access_token}" \ + -F "media_ids[]=${media_id}" \ + ${Instance}/api/v1/statuses >/dev/null + +echo ${photo} >>posted.txt |