~sumner/nixos-configuration

adb1c85e626fd2407a9b5e952ed2755fb2722014 — Sumner Evans a month ago b508762
cleanup-synapse: add purge remote media script

https://matrix-org.github.io/synapse/v1.44/admin_api/media_admin_api.html#purge-remote-media-api
1 files changed, 16 insertions(+), 0 deletions(-)

M modules/services/matrix/synapse/cleanup-synapse.nix
M modules/services/matrix/synapse/cleanup-synapse.nix => modules/services/matrix/synapse/cleanup-synapse.nix +16 -0
@@ 10,8 10,23 @@ let
  synapseCfg = config.services.matrix-synapse-custom;

  adminUrl = "http://localhost:8008/_synapse/admin/v1";
  adminMediaRepoUrl = "http://localhost:8011/_synapse/admin/v1";
  adminCurl = ''${curl}/bin/curl --header "Authorization: Bearer $CLEANUP_ACCESS_TOKEN" '';

  # Delete old cached remote media
  purgeRemoteMedia = writeShellScriptBin "purge-remote-media" ''
    set -xe

    now=$(${coreutils}/bin/date +%s%N | ${coreutils}/bin/cut -b1-13)
    nintey_days_ago=$(( now - 7776000000 ))

    ${adminCurl} \
      -X POST \
      -H "Content-Type: application/json" \
      -d "{}" \
      "${adminMediaRepoUrl}/purge_media_cache?before_ts=$nintey_days_ago"
  '';

  # Get rid of any rooms that aren't joined by anyone from the homeserver.
  cleanupForgottenRooms = writeShellScriptBin "cleanup-forgotten" ''
    set -xe


@@ 113,6 128,7 @@ let

  cleanupSynapseScript = writeShellScriptBin "cleanup-synapse" ''
    set -xe
    ${purgeRemoteMedia}/bin/purge-remote-media
    ${cleanupForgottenRooms}/bin/cleanup-forgotten
    ${compressState}/bin/compress-state
    ${reindexAndVaccum}/bin/reindex-and-vaccum