# General repo configuration
repo:
  bindAddress: '${node.metadata['matrix-media-repo'].get('listen-addr', '127.0.0.1')}'
  port: ${node.metadata['matrix-media-repo'].get('port', 20090)}
  logDirectory: '-'
  trustAnyForwardedAddress: false
  useForwardedHost: true

federation:
  backoffAt: 20

database:
  postgres: "postgres://${node.metadata['matrix-media-repo']['database']['user']}:${node.metadata['matrix-media-repo']['database']['password']}@${node.metadata['matrix-media-repo']['database'].get('host', 'localhost')}/${node.metadata['matrix-media-repo']['database']['database']}?sslmode=disable"

  pool:
    maxConnections: 25
    maxIdleConnections: 5

homeservers:
% for homeserver, config in node.metadata['matrix-media-repo'].get('homeservers', {}).items():
  - name: ${homeserver}
    csApi: "${config['domain']}"
    backoffAt: ${config.get('backoff_at', 10)}
    adminApiKind: "${config.get('api', 'matrix')}"
% endfor

accessTokens:
  maxCacheTimeSeconds: 0
  useLocalAppserviceConfig: false

admins:
% for user in sorted(node.metadata['matrix-media-repo']['admins']):
  - "${user}"
% endfor

sharedSecretAuth:
  enabled: false
  token: "${node.metadata['matrix-media-repo']['shared-secret-token']}"

datastores:
  - type: file
    enabled: true
    forKinds:
      - 'thumbnails'
      - 'remote_media'
      - 'local_media'
      - 'archives'
    opts:
      path: /var/matrix/media

archiving:
  enabled: true
  selfService: ${str(node.metadata['matrix-media-repo']['archive']['self-service']).lower()}
  targetBytesPerPart: ${node.metadata['matrix-media-repo']['archive'].get('mb_per_part', node.metadata['matrix-media-repo']['upload_max_mb']*2)*1024*1024}

uploads:
  maxBytes: ${node.metadata['matrix-media-repo']['upload_max_mb']*1024*1024}
  minBytes: 100
  reportedMaxBytes: 0
  quotas:
    enabled: false

downloads:
  maxBytes: ${node.metadata['matrix-media-repo']['download_max_mb']*1024*1024}
  numWorkers: ${node.metadata['matrix-media-repo']['workers']}
  failureCacheMinutes: 5
  cache:
    enabled: true
    maxSizeBytes: ${node.metadata['matrix-media-repo']['download_max_mb']*10*1024*1024}
    maxFileSizeBytes: ${node.metadata['matrix-media-repo']['upload_max_mb']*1024*1024}
    trackedMinutes: 30
    minDownloads: 5
    minCacheTimeSeconds: 300
    minEvictedTimeSeconds: 60
  expireAfterDays: 0

urlPreviews:
  enabled: true
  maxPageSizeBytes: ${node.metadata['matrix-media-repo']['preview_max_mb']*1024*1024}
  previewUnsafeCertificates: false
  numWords: 50
  maxLength: 200
  numTitleWords: 30
  maxTitleLength: 150
  filePreviewTypes:
    - "image/*"
  numWorkers: ${node.metadata['matrix-media-repo']['workers']}
  disallowedNetworks:
    - "127.0.0.1/8"
    - "10.0.0.0/8"
    - "172.16.0.0/12"
    - "192.168.0.0/16"
    - "100.64.0.0/10"
    - "169.254.0.0/16"
    - '::1/128'
    - 'fe80::/64'
    - 'fc00::/7'
  allowedNetworks:
    - "0.0.0.0/0"
    - "::/0"
  expireAfterDays: 0
  defaultLanguage: "en-US,en"
  oEmbed: false

thumbnails:
  maxSourceBytes: ${node.metadata['matrix-media-repo']['preview_max_mb']*1024*1024}
  numWorkers: ${node.metadata['matrix-media-repo']['workers']}
  sizes:
    - width: 32
      height: 32
    - width: 96
      height: 96
    - width: 320
      height: 240
    - width: 640
      height: 480
    - width: 768
      height: 240
    - width: 800
      height: 600
  dynamicSizing: false
  types:
    - "image/jpeg"
    - "image/jpg"
    - "image/png"
    - "image/gif"
    - "image/heif"
    - "image/webp"
    - "image/svg+xml"
    - "audio/mpeg"
    - "audio/ogg"
    - "audio/wav"
    - "audio/flac"
    - "video/mp4"
  allowAnimated: true
  defaultAnimated: false
  maxAnimateSizeBytes: ${node.metadata['matrix-media-repo']['preview_max_mb']*1024*1024}
  stillFrame: 0.5
  expireAfterDays: 0

rateLimit:
  enabled: true
  requestsPerSecond: 10
  burst: 50

identicons:
  enabled: true

quarantine:
  replaceThumbnails: true
  replaceDownloads: false
  allowLocalAdmins: true

timeouts:
  urlPreviewTimeoutSeconds: 10
  federationTimeoutSeconds: 120
  clientServerTimeoutSeconds: 30

metrics:
  enabled: true
  bindAddress: "127.0.0.1"
  port: 20091

featureSupport:
  MSC2448:
    enabled: false
  IPFS:
    enabled: false
  redis:
    enabled: false