Add attempts for default data

This commit is contained in:
Melody Becker 2025-04-05 12:22:00 +02:00
parent c25f27e82e
commit 910717cf01
No known key found for this signature in database
4 changed files with 56 additions and 3 deletions

View file

@ -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,
}

View file

@ -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,
}
}

View file

@ -232,7 +232,7 @@ var ServerActorRole = Role{
CanSendAnnouncements: other.IntoPointer(true),
}
var allDefaultRoles = []*Role{
var AllDefaultRoles = []*Role{
&DefaultUserRole,
&FullAdminRole,
&AccountFreezeRole,

View file

@ -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},
}
}