Horhik / Instagram2Fedi

Python script for crossposting from Instagram to Mastodon or Pixelfed
GNU General Public License v3.0
91 stars 7 forks source link

Run stateless? #9

Open ctr49 opened 1 year ago

ctr49 commented 1 year ago

I like the script but would like to run it stateless (i.e. not as daemon and without a local file to store already posted IDs). The target is to run it as FaaS with Heroku, Scaleway or any other FaaS provider trigger via cron (i.e. hourly).

Running one-shot instead of deamonized would be straight forward, but how could we avoid double-posting over and over? 1) only look at post in past (timeframe) and make sure script only runs once per timeframe (with the obvious disadvantage that we'd miss posts if there was an unsuccessful invocation). 2) Embed Insta post.mediaid in Toot to detect duplicates. Also introduce a timeframe to reduce the number of posts that need to be compared (with the advantage over option 1 that the script can and should run multiple times in the defined timeframe)

Any other ideas how to achieve the said objective?

ctr49 commented 1 year ago

Option 2 doesn't really work as arbitrary metadata cannot be injected into a status/toot. A media object supports this, but not the toot. To use the metadata in the media it would have to be fetched on every post, this would be an overkill from runtime perspective and would also make it run for an extended time which would make it expensive in a FaaS context.

Instead I came up with option 3: Use "Idempotency-Key" to have the Mastodon/Pixelfed server fail on duplicates. This would combine options 1 and 2 in a way that: The script would only look at posts made in the past hour. But it would inject a unique id (possibly Instagram shortcode) as "Idempotency-Key" when re-posting the toot/status. If it was already posted the Mastodon/Pixelfed server would figure it out and suppress the duplicate. The script should then be run multiple times an hour (to avoid missing a post if something went wrong).

For Mastodon this works out of the box with a few tiny modifications to the script (passing the post.shortcode to the toot call as Idempotency-Key), but unfortunately Pixelfed has not implemented Idempotency-Key yet, altough it claims to be Mastodon api-compatible, see https://github.com/pixelfed/pixelfed/issues/3581