Class: Async::Matrix::Bridge::Discord::DB::CachedFile

Inherits:
Sequel::Model
  • Object
show all
Defined in:
lib/async/matrix/bridge/discord/db/file.rb

Overview

Caches uploaded media to avoid re-uploading the same Discord attachment to the Matrix homeserver.

Uses a composite primary key of (url, encrypted) because the same source URL may be uploaded both encrypted and unencrypted to different portal rooms.

cached = CachedFile.create(
  url: "https://cdn.discordapp.com/...",
  encrypted: false,
  mxc: "mxc://example.com/abc"
)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.by_url(url, encrypted: false) ⇒ Object

Look up a cached file by source URL and encryption status.



37
38
39
# File 'lib/async/matrix/bridge/discord/db/file.rb', line 37

def self.by_url(url, encrypted: false)
  first(url: url, encrypted: encrypted)
end

Instance Method Details

#validateObject



30
31
32
33
34
# File 'lib/async/matrix/bridge/discord/db/file.rb', line 30

def validate
  super
  errors.add(:url, "cannot be empty") if url.nil? || url.empty?
  errors.add(:mxc, "cannot be empty") if mxc.nil? || mxc.empty?
end