akkoma/docs/docs/configuration/howto_set_richmedia_cache_t...

1010 B

How to set rich media cache TTL based on image TTL

Explanation

Richmedia are cached without the TTL, but the rich media may have image which can expire, like AWS-signed URL. In such cases, the old image URL (expired) is returned from the media cache.

So, to avoid such situation, we can define a module that will set TTL based on image. The module must adopt behaviour Pleroma.Web.RichMedia.Parser.TTL

Example

defmodule MyModule do
  @behaviour Pleroma.Web.RichMedia.Parser.TTL

  @impl Pleroma.Web.RichMedia.Parser.TTL
  def ttl(data, url) do
    image_url = Map.get(data, :image)
    # do some parsing in the url and get the TTL of the image
    # return TTL is unix time
    parse_ttl_from_url(image_url)
  end
end

And update the config

config :pleroma, :rich_media,
  ttl_setters: [Pleroma.Web.RichMedia.Parser.TTL.AwsSignedUrl, MyModule]

For reference there is a parser for AWS signed URL Pleroma.Web.RichMedia.Parser.TTL.AwsSignedUrl, it's enabled by default.