More reliable filtering of duplicate posts

Tweaks to filter_posts(), and now we use the
“Indempotency-Key” header, which should disallow
reposts for a short span of time (even if we lose
our history file).
This commit is contained in:
Jaidyn Ann 2024-04-10 21:56:08 -05:00
parent 4b306d34cb
commit 3048c4ad68

View File

@ -51,7 +51,7 @@ fetch_hashtag_posts() {
local hashtag="$2"
local minimum_id="$3"
if test -n "$most_recent_post_id"; then
if test -n "$minimum_id"; then
curl --fail "$server/api/v1/timelines/tag/$hashtag?min_id=$minimum_id"
else
curl --fail "$server/api/v1/timelines/tag/$hashtag"
@ -67,6 +67,7 @@ quote_post() {
--request POST \
--header "Authorization: Bearer $FEDI_AUTH" \
--header 'Content-Type: application/json' \
--header "Idempotency-Key: $(echo "$tagged_post_json" | jq -r .id)" \
--data "$(post_json "$tagged_post_json")" "$FEDI_SERVER/api/v1/statuses"
}
@ -120,8 +121,7 @@ post_body() {
filter_posts() {
local ids_to_filter="$1"
# If the list has more than give characters, use it to filter… (sanity check)
if test -n "$ids_to_filter" \
-a "$(echo "$ids_to_filter" | wc --bytes | awk '{print $1}')" -gt 5; then
if test -n "$ids_to_filter"; then
jq -cr .[] \
| grep --invert-match $(echo "$ids_to_filter" | sed 's%^%-e %')
else
@ -133,8 +133,8 @@ filter_posts() {
history_post_ids() {
local history_file="$1"
if test -f "$history_file"; then
grep -v '^[[:space:]]*$' "$history_file" \
| awk '{ print $2 }'
awk -F '\t' '{print $2}' "$history_file" \
| grep -v '^[[:space:]]*$'
fi
}