diff --git a/storage/mediaFile.go b/storage/mediaFile.go index c3a55c3..a37e1e2 100644 --- a/storage/mediaFile.go +++ b/storage/mediaFile.go @@ -6,11 +6,10 @@ import ( "gorm.io/gorm" ) -// MediaFile represents a file containing some media -// This media may be stored locally via a file system or S3 bucket -// or remote on a different server -// Additionally, it contains some useful data for more easily working with it -type MediaFile struct { +// MediaMetadata contains metadata about some media +// Metadata includes whether it's a remote file or not, what the name is, +// the MIME type, and an identifier pointing to its location +type MediaMetadata struct { ID string `gorm:"primarykey"` // The unique ID of this media file CreatedAt time.Time // When this entry was created UpdatedAt time.Time // When this entry was last updated @@ -19,18 +18,22 @@ type MediaFile struct { // If not null, this entry is marked as deleted DeletedAt gorm.DeletedAt `gorm:"index"` Remote bool // whether the attachment is a remote one - // Always an url, either an absolute path to a local file or an url to a remote file - Link string - Type string // What media type this is following mime types, eg image/png - // Whether this media has been cached locally - // Used for user and server icons as well as emotes, not attachments - // If true, Link will be read as file path. url otherwise - // Reason: Attachments would take way to much space considering that they are often only loaded a few times at most - // And caching a file for those few times would be a waste of storage - // Caching user and server icons locally however should reduce burden on remote servers by quite a bit though - // TODO: Decide later during usage if attachment caching would be a good idea - LocallyCached bool + // Where the media is stored. Url if remote file, + Location string + Type string // What media type this is following mime types, eg image/png // Descriptive name for a media file // Emote name for example or servername.filetype for a server's icon Name string } + +// TODO: Figure out how to actually manage media. Because this current idea sucks +// One idea would be to make another storage provider, but purely focused on handling the files +// and then using this section to store metadata about the files it knows +func (s *Storage) NewMediaMetadata(url, mediaType, name string) (*MediaMetadata, error) { + newMedia := MediaMetadata{ + Location: url, + Name: name, + } + s.db.Create(&newMedia) + return nil, nil +} diff --git a/storage/storage.go b/storage/storage.go index 3696a24..92ce234 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -39,7 +39,7 @@ func storageFromEmptyDb(db *gorm.DB, cache *cache.Cache) (*Storage, error) { // AutoMigrate ensures the db is in a state where all the structs given here // have their own tables and relations setup. It also updates tables if necessary err := db.AutoMigrate( - MediaFile{}, + MediaMetadata{}, Account{}, RemoteServer{}, Note{},