-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
313 additions
and
302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/command/with-contenv bash | ||
#shellcheck shell=bash disable=SC1091,SC2174 | ||
# ----------------------------------------------------------------------------------- | ||
# Copyright 2024 Ramon F. Kolb - licensed under the terms and conditions | ||
# of GPLv3. The terms and conditions of this license are included with the Github | ||
# distribution of this package, and are also available here: | ||
# https://github.com/kx1t/docker-planefence/ | ||
# | ||
# This package may incorporate other software and license terms. | ||
# ----------------------------------------------------------------------------------- | ||
|
||
if [[ -f /usr/share/planefence/persist/planefence.config ]]; then source /usr/share/planefence/persist/planefence.config; fi | ||
|
||
ACCESS_TOKEN=$MASTODON_ACCESS_TOKEN | ||
INSTANCE_URL="https://$MASTODON_SERVER" | ||
|
||
RETENTION_DAYS="${MASTODON_RETENTION_TIME}" | ||
|
||
delete_toot() { | ||
local toot_id="$1" | ||
local result | ||
if result="$(curl -s --fail -X DELETE -H "Authorization: Bearer $ACCESS_TOKEN" "$INSTANCE_URL/api/v1/statuses/$toot_id" 2>&1)"; then | ||
echo "successfully deleted" | ||
else | ||
echo "error: $result" | ||
fi | ||
} | ||
|
||
if [[ -z "$RETENTION_DAYS" ]]; then | ||
echo "RETENTION_DAYS not set. Exiting." | ||
exit 1 | ||
fi | ||
|
||
unset toot_dates counter last_id | ||
declare -A toot_dates | ||
|
||
now="$(date +%s)" | ||
|
||
masto_id="$(curl -s -H "Authorization: Bearer $ACCESS_TOKEN" "$INSTANCE_URL/api/v1/accounts/verify_credentials" | jq -r '.id')" | ||
|
||
while : ; do | ||
echo -n "Indexing Media IDs round $((++counter))" | ||
toots="$(curl -s -H "Authorization: Bearer $ACCESS_TOKEN" "$INSTANCE_URL/api/v1/accounts/$masto_id/statuses?limit=40${last_id:+&max_id=}${last_id}")" | ||
# shellcheck disable=SC2207 | ||
toot_ids=($(jq -r '.[] | .id' <<< "$toots" 2>/dev/null)) | ||
if (( ${#toot_ids[@]} == 0)); then | ||
echo "No more toots, we are done!" | ||
exit | ||
fi | ||
last_id="${toot_ids[-1]}" | ||
echo " ${#toot_ids[@]} toots" | ||
for t in "${toot_ids[@]}"; do | ||
if [[ -z "${toot_dates[$t]}" ]]; then | ||
toot_dates[$t]="$(date -d "$(jq -r 'map(select(.id == "'"$t"'"))[].created_at' <<< "$toots")" +%s)" | ||
echo -n "$t --> $(date -d @"${toot_dates[$t]}") " | ||
if (( (now - toot_dates[$t])/(60*60*24) > RETENTION_DAYS )); then | ||
echo -n " expired (age: $(( (now - toot_dates[$t])/(60*60*24) )) days): " | ||
if [[ "$1" == "delete" ]]; then | ||
echo -n "deleting... " | ||
delete_toot "$t"; | ||
else | ||
echo "(not deleted)" | ||
fi | ||
else | ||
echo " not expired (age: $(( (now | ||
- toot_dates[$t])/(60*60*24) )) days)" | ||
fi | ||
else | ||
echo "$t --> duplicate, we're done!" | ||
exit | ||
fi | ||
done | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.