From 910717cf018a1253fc1f489fc3e190e889697a62 Mon Sep 17 00:00:00 2001 From: mStar Date: Sat, 5 Apr 2025 12:22:00 +0200 Subject: [PATCH] Add attempts for default data --- storage-new/models/MediaMetadata.go | 17 +++++++++++++++++ storage-new/models/RemoteServer.go | 15 +++++++++++++++ storage-new/models/RolesDefaults.go | 2 +- storage-new/models/User.go | 25 +++++++++++++++++++++++-- 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/storage-new/models/MediaMetadata.go b/storage-new/models/MediaMetadata.go index a090bb4..777364a 100644 --- a/storage-new/models/MediaMetadata.go +++ b/storage-new/models/MediaMetadata.go @@ -31,3 +31,20 @@ type MediaMetadata struct { // Whether the media is to be blurred by default Blurred bool } + +// TODO: Implement special handling for the linstrom URI type +// Linstrom URIs indicate resource either generated on the fly, like identicons, +// or embedded data, such as the default duck +// For external users, transform them into normal http URIs with a "special" path +const DefaultDuckLocationName = "linstrom://default-media" + +var DefaultDuckMedia = MediaMetadata{ + ID: "3b562a45-36b7-4c42-a944-3672f319ff7b", + OwnedById: "", // FIXME: Add default user ID here + Remote: false, + Location: DefaultDuckLocationName, + Type: "image/webp", + Name: "default-duck.webp", + AltText: "a greyscale image of a pidgeon on some smooth surface, likely a liquid. It is captioned with the text \"Duck\"", + Blurred: false, +} diff --git a/storage-new/models/RemoteServer.go b/storage-new/models/RemoteServer.go index 457d2c7..9f5d8e6 100644 --- a/storage-new/models/RemoteServer.go +++ b/storage-new/models/RemoteServer.go @@ -3,6 +3,7 @@ package models import ( "database/sql" + "git.mstar.dev/mstar/linstrom/config" "gorm.io/gorm" ) @@ -17,3 +18,17 @@ type RemoteServer struct { IconId sql.NullString // ID of a media file IsSelf bool // Whether this server is yours truly } + +func BuildDefaultServer() *RemoteServer { + return &RemoteServer{ + Model: gorm.Model{ + ID: 1, + }, + ServerType: ServerSoftwareLinstrom, + Domain: config.GlobalConfig.General.GetFullDomain(), + Name: config.GlobalConfig.Self.ServerDisplayName, + Icon: &DefaultDuckMedia, + IconId: sql.NullString{String: DefaultDuckMedia.ID, Valid: true}, + IsSelf: true, + } +} diff --git a/storage-new/models/RolesDefaults.go b/storage-new/models/RolesDefaults.go index fc1b746..3d6274e 100644 --- a/storage-new/models/RolesDefaults.go +++ b/storage-new/models/RolesDefaults.go @@ -232,7 +232,7 @@ var ServerActorRole = Role{ CanSendAnnouncements: other.IntoPointer(true), } -var allDefaultRoles = []*Role{ +var AllDefaultRoles = []*Role{ &DefaultUserRole, &FullAdminRole, &AccountFreezeRole, diff --git a/storage-new/models/User.go b/storage-new/models/User.go index 9e8bf70..d68b14c 100644 --- a/storage-new/models/User.go +++ b/storage-new/models/User.go @@ -5,6 +5,8 @@ import ( "time" "gorm.io/gorm" + + "git.mstar.dev/mstar/linstrom/config" ) // A user describes an account for creating content and events. @@ -35,8 +37,8 @@ type User struct { // When this entry was deleted (for soft deletions) // Soft delete means that this entry still exists in the db, but gorm won't include it anymore unless specifically told to // If not null, this entry is marked as deleted - DeletedAt gorm.DeletedAt `gorm:"index"` - // Server RemoteServer // `gorm:"foreignKey:ServerId;references:ID"` // The server this user is from + DeletedAt gorm.DeletedAt `gorm:"index"` + Server RemoteServer ServerId uint // Id of the server this user is from, needed for including RemoteServer DisplayName string // The display name of the user. Can be different from the handle Description string // The description of a user account @@ -76,3 +78,22 @@ type User struct { RemoteInfo *UserRemoteLinks AuthMethods []UserAuthMethod } + +func BuildLinstromUser() *User { + server := BuildDefaultServer() + return &User{ + ID: "e3f4bb33-6d39-4349-b13e-f5c6fde56141", + Username: "linstrom", + Server: *server, + ServerId: server.ID, + DisplayName: config.GlobalConfig.Self.ServerActorDisplayName, + Description: "The default linstrom server user", + IsBot: true, + Icon: DefaultDuckMedia, + IconId: DefaultDuckMedia.ID, + Background: nil, + BackgroundId: sql.NullString{Valid: false}, + Banner: nil, + BannerId: sql.NullString{Valid: false}, + } +}