Compare commits

..

No commits in common. "349e78e4339cf25547383a47c6e41e25e7d5c78b" and "9cca79ec4cdb6e30f04743f6bc48c3c959689bf3" have entirely different histories.

32 changed files with 228 additions and 794 deletions

32
main.go
View file

@ -10,15 +10,11 @@ import (
"github.com/go-webauthn/webauthn/webauthn" "github.com/go-webauthn/webauthn/webauthn"
"github.com/mstarongithub/passkey" "github.com/mstarongithub/passkey"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"git.mstar.dev/mstar/linstrom/config" "git.mstar.dev/mstar/linstrom/config"
"git.mstar.dev/mstar/linstrom/server" "git.mstar.dev/mstar/linstrom/server"
"git.mstar.dev/mstar/linstrom/shared" "git.mstar.dev/mstar/linstrom/shared"
"git.mstar.dev/mstar/linstrom/storage" "git.mstar.dev/mstar/linstrom/storage"
storagenew "git.mstar.dev/mstar/linstrom/storage-new"
"git.mstar.dev/mstar/linstrom/storage-new/dbgen"
"git.mstar.dev/mstar/linstrom/storage/cache" "git.mstar.dev/mstar/linstrom/storage/cache"
) )
@ -49,16 +45,7 @@ func main() {
if *shared.FlagConfigOnly { if *shared.FlagConfigOnly {
return return
} }
if *shared.FlagStartNew {
log.Info().Msg("Starting new system")
newServer()
} else {
log.Info().Msg("Starting old system")
oldServer()
}
}
func oldServer() {
storageCache, err := cache.NewCache( storageCache, err := cache.NewCache(
config.GlobalConfig.Storage.MaxInMemoryCacheSize, config.GlobalConfig.Storage.MaxInMemoryCacheSize,
config.GlobalConfig.Storage.RedisUrl, config.GlobalConfig.Storage.RedisUrl,
@ -106,22 +93,3 @@ func oldServer() {
// TODO: Set up queues // TODO: Set up queues
// TODO: Set up plugins // TODO: Set up plugins
} }
func newServer() {
db, err := gorm.Open(
postgres.Open(config.GlobalConfig.Storage.BuildPostgresDSN()),
&gorm.Config{
Logger: shared.NewGormLogger(log.Logger),
},
)
if err != nil {
log.Fatal().Err(err).Msg("Failed to start db")
}
dbgen.SetDefault(db)
if err = storagenew.Migrate(db); err != nil {
log.Fatal().Err(err).Msg("Failed to automigrate structure")
}
if err = storagenew.InsertSelf(); err != nil {
log.Fatal().Err(err).Msg("Failed to insert self properly")
}
}

View file

@ -19,7 +19,6 @@ var (
false, false,
"If set, the server will only validate the config (or write the default one) and then quit", "If set, the server will only validate the config (or write the default one) and then quit",
) )
FlagStartNew *bool = flag.Bool("new", false, "Start the new system")
) )
func flagUsage() { func flagUsage() {

View file

@ -35,19 +35,6 @@ func newAccessToken(db *gorm.DB, opts ...gen.DOOption) accessToken {
db: db.Session(&gorm.Session{}), db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("User", "models.User"), RelationField: field.NewRelation("User", "models.User"),
Server: struct {
field.RelationField
Icon struct {
field.RelationField
}
}{
RelationField: field.NewRelation("User.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("User.Server.Icon", "models.MediaMetadata"),
},
},
Icon: struct { Icon: struct {
field.RelationField field.RelationField
}{ }{
@ -258,12 +245,6 @@ type accessTokenBelongsToUser struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }
@ -459,15 +440,15 @@ type IAccessTokenDo interface {
GetTokenIfValid(token string) (result *models.AccessToken, err error) GetTokenIfValid(token string) (result *models.AccessToken, err error)
} }
// Get the data for a token // Get the data for a token if it hasn't expired yet
// //
// SELECT * FROM @@table WHERE token = @token // SELECT * FROM @@table WHERE token = @token AND expires_at < NOW() LIMIT 1
func (a accessTokenDo) GetTokenIfValid(token string) (result *models.AccessToken, err error) { func (a accessTokenDo) GetTokenIfValid(token string) (result *models.AccessToken, err error) {
var params []interface{} var params []interface{}
var generateSQL strings.Builder var generateSQL strings.Builder
params = append(params, token) params = append(params, token)
generateSQL.WriteString("SELECT * FROM access_tokens WHERE token = ? ") generateSQL.WriteString("SELECT * FROM access_tokens WHERE token = ? AND expires_at < NOW() LIMIT 1 ")
var executeSQL *gorm.DB var executeSQL *gorm.DB
executeSQL = a.UnderlyingDB().Raw(generateSQL.String(), params...).Take(&result) // ignore_security_alert executeSQL = a.UnderlyingDB().Raw(generateSQL.String(), params...).Take(&result) // ignore_security_alert

View file

@ -38,19 +38,6 @@ func newFeed(db *gorm.DB, opts ...gen.DOOption) feed {
db: db.Session(&gorm.Session{}), db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("Owner", "models.User"), RelationField: field.NewRelation("Owner", "models.User"),
Server: struct {
field.RelationField
Icon struct {
field.RelationField
}
}{
RelationField: field.NewRelation("Owner.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("Owner.Server.Icon", "models.MediaMetadata"),
},
},
Icon: struct { Icon: struct {
field.RelationField field.RelationField
}{ }{
@ -273,12 +260,6 @@ type feedBelongsToOwner struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }

View file

@ -35,19 +35,6 @@ func newLoginProcessToken(db *gorm.DB, opts ...gen.DOOption) loginProcessToken {
db: db.Session(&gorm.Session{}), db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("User", "models.User"), RelationField: field.NewRelation("User", "models.User"),
Server: struct {
field.RelationField
Icon struct {
field.RelationField
}
}{
RelationField: field.NewRelation("User.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("User.Server.Icon", "models.MediaMetadata"),
},
},
Icon: struct { Icon: struct {
field.RelationField field.RelationField
}{ }{
@ -261,12 +248,6 @@ type loginProcessTokenBelongsToUser struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }

View file

@ -30,7 +30,7 @@ func newMediaMetadata(db *gorm.DB, opts ...gen.DOOption) mediaMetadata {
_mediaMetadata.CreatedAt = field.NewTime(tableName, "created_at") _mediaMetadata.CreatedAt = field.NewTime(tableName, "created_at")
_mediaMetadata.UpdatedAt = field.NewTime(tableName, "updated_at") _mediaMetadata.UpdatedAt = field.NewTime(tableName, "updated_at")
_mediaMetadata.DeletedAt = field.NewField(tableName, "deleted_at") _mediaMetadata.DeletedAt = field.NewField(tableName, "deleted_at")
_mediaMetadata.OwnedById = field.NewField(tableName, "owned_by_id") _mediaMetadata.OwnedById = field.NewString(tableName, "owned_by_id")
_mediaMetadata.Remote = field.NewBool(tableName, "remote") _mediaMetadata.Remote = field.NewBool(tableName, "remote")
_mediaMetadata.Location = field.NewString(tableName, "location") _mediaMetadata.Location = field.NewString(tableName, "location")
_mediaMetadata.Type = field.NewString(tableName, "type") _mediaMetadata.Type = field.NewString(tableName, "type")
@ -51,7 +51,7 @@ type mediaMetadata struct {
CreatedAt field.Time CreatedAt field.Time
UpdatedAt field.Time UpdatedAt field.Time
DeletedAt field.Field DeletedAt field.Field
OwnedById field.Field OwnedById field.String
Remote field.Bool Remote field.Bool
Location field.String Location field.String
Type field.String Type field.String
@ -78,7 +78,7 @@ func (m *mediaMetadata) updateTableName(table string) *mediaMetadata {
m.CreatedAt = field.NewTime(table, "created_at") m.CreatedAt = field.NewTime(table, "created_at")
m.UpdatedAt = field.NewTime(table, "updated_at") m.UpdatedAt = field.NewTime(table, "updated_at")
m.DeletedAt = field.NewField(table, "deleted_at") m.DeletedAt = field.NewField(table, "deleted_at")
m.OwnedById = field.NewField(table, "owned_by_id") m.OwnedById = field.NewString(table, "owned_by_id")
m.Remote = field.NewBool(table, "remote") m.Remote = field.NewBool(table, "remote")
m.Location = field.NewString(table, "location") m.Location = field.NewString(table, "location")
m.Type = field.NewString(table, "type") m.Type = field.NewString(table, "type")

View file

@ -35,12 +35,6 @@ func newNoteTag(db *gorm.DB, opts ...gen.DOOption) noteTag {
RelationField: field.NewRelation("Note", "models.Note"), RelationField: field.NewRelation("Note", "models.Note"),
Creator: struct { Creator: struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }
@ -106,19 +100,6 @@ func newNoteTag(db *gorm.DB, opts ...gen.DOOption) noteTag {
} }
}{ }{
RelationField: field.NewRelation("Note.Creator", "models.User"), RelationField: field.NewRelation("Note.Creator", "models.User"),
Server: struct {
field.RelationField
Icon struct {
field.RelationField
}
}{
RelationField: field.NewRelation("Note.Creator.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("Note.Creator.Server.Icon", "models.MediaMetadata"),
},
},
Icon: struct { Icon: struct {
field.RelationField field.RelationField
}{ }{
@ -288,6 +269,9 @@ func newNoteTag(db *gorm.DB, opts ...gen.DOOption) noteTag {
} }
Server struct { Server struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
} }
} }
}{ }{
@ -304,6 +288,9 @@ func newNoteTag(db *gorm.DB, opts ...gen.DOOption) noteTag {
} }
Server struct { Server struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
} }
}{ }{
RelationField: field.NewRelation("Note.EmoteRelations.Emote", "models.Emote"), RelationField: field.NewRelation("Note.EmoteRelations.Emote", "models.Emote"),
@ -314,8 +301,16 @@ func newNoteTag(db *gorm.DB, opts ...gen.DOOption) noteTag {
}, },
Server: struct { Server: struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
}{ }{
RelationField: field.NewRelation("Note.EmoteRelations.Emote.Server", "models.RemoteServer"), RelationField: field.NewRelation("Note.EmoteRelations.Emote.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("Note.EmoteRelations.Emote.Server.Icon", "models.MediaMetadata"),
},
}, },
}, },
}, },
@ -427,12 +422,6 @@ type noteTagBelongsToNote struct {
Creator struct { Creator struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }
@ -518,6 +507,9 @@ type noteTagBelongsToNote struct {
} }
Server struct { Server struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
} }
} }
} }

View file

@ -35,12 +35,6 @@ func newNoteToAttachment(db *gorm.DB, opts ...gen.DOOption) noteToAttachment {
RelationField: field.NewRelation("Note", "models.Note"), RelationField: field.NewRelation("Note", "models.Note"),
Creator: struct { Creator: struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }
@ -106,19 +100,6 @@ func newNoteToAttachment(db *gorm.DB, opts ...gen.DOOption) noteToAttachment {
} }
}{ }{
RelationField: field.NewRelation("Note.Creator", "models.User"), RelationField: field.NewRelation("Note.Creator", "models.User"),
Server: struct {
field.RelationField
Icon struct {
field.RelationField
}
}{
RelationField: field.NewRelation("Note.Creator.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("Note.Creator.Server.Icon", "models.MediaMetadata"),
},
},
Icon: struct { Icon: struct {
field.RelationField field.RelationField
}{ }{
@ -288,6 +269,9 @@ func newNoteToAttachment(db *gorm.DB, opts ...gen.DOOption) noteToAttachment {
} }
Server struct { Server struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
} }
} }
}{ }{
@ -304,6 +288,9 @@ func newNoteToAttachment(db *gorm.DB, opts ...gen.DOOption) noteToAttachment {
} }
Server struct { Server struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
} }
}{ }{
RelationField: field.NewRelation("Note.EmoteRelations.Emote", "models.Emote"), RelationField: field.NewRelation("Note.EmoteRelations.Emote", "models.Emote"),
@ -314,8 +301,16 @@ func newNoteToAttachment(db *gorm.DB, opts ...gen.DOOption) noteToAttachment {
}, },
Server: struct { Server: struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
}{ }{
RelationField: field.NewRelation("Note.EmoteRelations.Emote.Server", "models.RemoteServer"), RelationField: field.NewRelation("Note.EmoteRelations.Emote.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("Note.EmoteRelations.Emote.Server.Icon", "models.MediaMetadata"),
},
}, },
}, },
}, },
@ -435,12 +430,6 @@ type noteToAttachmentBelongsToNote struct {
Creator struct { Creator struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }
@ -526,6 +515,9 @@ type noteToAttachmentBelongsToNote struct {
} }
Server struct { Server struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
} }
} }
} }

View file

@ -34,19 +34,6 @@ func newNoteToBoost(db *gorm.DB, opts ...gen.DOOption) noteToBoost {
db: db.Session(&gorm.Session{}), db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("User", "models.User"), RelationField: field.NewRelation("User", "models.User"),
Server: struct {
field.RelationField
Icon struct {
field.RelationField
}
}{
RelationField: field.NewRelation("User.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("User.Server.Icon", "models.MediaMetadata"),
},
},
Icon: struct { Icon: struct {
field.RelationField field.RelationField
}{ }{
@ -226,6 +213,9 @@ func newNoteToBoost(db *gorm.DB, opts ...gen.DOOption) noteToBoost {
} }
Server struct { Server struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
} }
} }
}{ }{
@ -242,6 +232,9 @@ func newNoteToBoost(db *gorm.DB, opts ...gen.DOOption) noteToBoost {
} }
Server struct { Server struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
} }
}{ }{
RelationField: field.NewRelation("Note.EmoteRelations.Emote", "models.Emote"), RelationField: field.NewRelation("Note.EmoteRelations.Emote", "models.Emote"),
@ -252,8 +245,16 @@ func newNoteToBoost(db *gorm.DB, opts ...gen.DOOption) noteToBoost {
}, },
Server: struct { Server: struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
}{ }{
RelationField: field.NewRelation("Note.EmoteRelations.Emote.Server", "models.RemoteServer"), RelationField: field.NewRelation("Note.EmoteRelations.Emote.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("Note.EmoteRelations.Emote.Server.Icon", "models.MediaMetadata"),
},
}, },
}, },
}, },
@ -368,12 +369,6 @@ type noteToBoostBelongsToUser struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }
@ -533,6 +528,9 @@ type noteToBoostBelongsToNote struct {
} }
Server struct { Server struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
} }
} }
} }

View file

@ -35,12 +35,6 @@ func newNoteToEmote(db *gorm.DB, opts ...gen.DOOption) noteToEmote {
RelationField: field.NewRelation("Note", "models.Note"), RelationField: field.NewRelation("Note", "models.Note"),
Creator: struct { Creator: struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }
@ -106,19 +100,6 @@ func newNoteToEmote(db *gorm.DB, opts ...gen.DOOption) noteToEmote {
} }
}{ }{
RelationField: field.NewRelation("Note.Creator", "models.User"), RelationField: field.NewRelation("Note.Creator", "models.User"),
Server: struct {
field.RelationField
Icon struct {
field.RelationField
}
}{
RelationField: field.NewRelation("Note.Creator.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("Note.Creator.Server.Icon", "models.MediaMetadata"),
},
},
Icon: struct { Icon: struct {
field.RelationField field.RelationField
}{ }{
@ -288,6 +269,9 @@ func newNoteToEmote(db *gorm.DB, opts ...gen.DOOption) noteToEmote {
} }
Server struct { Server struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
} }
} }
}{ }{
@ -304,6 +288,9 @@ func newNoteToEmote(db *gorm.DB, opts ...gen.DOOption) noteToEmote {
} }
Server struct { Server struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
} }
}{ }{
RelationField: field.NewRelation("Note.EmoteRelations.Emote", "models.Emote"), RelationField: field.NewRelation("Note.EmoteRelations.Emote", "models.Emote"),
@ -314,8 +301,16 @@ func newNoteToEmote(db *gorm.DB, opts ...gen.DOOption) noteToEmote {
}, },
Server: struct { Server: struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
}{ }{
RelationField: field.NewRelation("Note.EmoteRelations.Emote.Server", "models.RemoteServer"), RelationField: field.NewRelation("Note.EmoteRelations.Emote.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("Note.EmoteRelations.Emote.Server.Icon", "models.MediaMetadata"),
},
}, },
}, },
}, },
@ -435,12 +430,6 @@ type noteToEmoteBelongsToNote struct {
Creator struct { Creator struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }
@ -526,6 +515,9 @@ type noteToEmoteBelongsToNote struct {
} }
Server struct { Server struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
} }
} }
} }

View file

@ -35,12 +35,6 @@ func newNoteToFeed(db *gorm.DB, opts ...gen.DOOption) noteToFeed {
RelationField: field.NewRelation("Note", "models.Note"), RelationField: field.NewRelation("Note", "models.Note"),
Creator: struct { Creator: struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }
@ -106,19 +100,6 @@ func newNoteToFeed(db *gorm.DB, opts ...gen.DOOption) noteToFeed {
} }
}{ }{
RelationField: field.NewRelation("Note.Creator", "models.User"), RelationField: field.NewRelation("Note.Creator", "models.User"),
Server: struct {
field.RelationField
Icon struct {
field.RelationField
}
}{
RelationField: field.NewRelation("Note.Creator.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("Note.Creator.Server.Icon", "models.MediaMetadata"),
},
},
Icon: struct { Icon: struct {
field.RelationField field.RelationField
}{ }{
@ -288,6 +269,9 @@ func newNoteToFeed(db *gorm.DB, opts ...gen.DOOption) noteToFeed {
} }
Server struct { Server struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
} }
} }
}{ }{
@ -304,6 +288,9 @@ func newNoteToFeed(db *gorm.DB, opts ...gen.DOOption) noteToFeed {
} }
Server struct { Server struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
} }
}{ }{
RelationField: field.NewRelation("Note.EmoteRelations.Emote", "models.Emote"), RelationField: field.NewRelation("Note.EmoteRelations.Emote", "models.Emote"),
@ -314,8 +301,16 @@ func newNoteToFeed(db *gorm.DB, opts ...gen.DOOption) noteToFeed {
}, },
Server: struct { Server: struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
}{ }{
RelationField: field.NewRelation("Note.EmoteRelations.Emote.Server", "models.RemoteServer"), RelationField: field.NewRelation("Note.EmoteRelations.Emote.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("Note.EmoteRelations.Emote.Server.Icon", "models.MediaMetadata"),
},
}, },
}, },
}, },
@ -427,12 +422,6 @@ type noteToFeedBelongsToNote struct {
Creator struct { Creator struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }
@ -518,6 +507,9 @@ type noteToFeedBelongsToNote struct {
} }
Server struct { Server struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
} }
} }
} }

View file

@ -35,12 +35,6 @@ func newNoteToPing(db *gorm.DB, opts ...gen.DOOption) noteToPing {
RelationField: field.NewRelation("Note", "models.Note"), RelationField: field.NewRelation("Note", "models.Note"),
Creator: struct { Creator: struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }
@ -106,19 +100,6 @@ func newNoteToPing(db *gorm.DB, opts ...gen.DOOption) noteToPing {
} }
}{ }{
RelationField: field.NewRelation("Note.Creator", "models.User"), RelationField: field.NewRelation("Note.Creator", "models.User"),
Server: struct {
field.RelationField
Icon struct {
field.RelationField
}
}{
RelationField: field.NewRelation("Note.Creator.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("Note.Creator.Server.Icon", "models.MediaMetadata"),
},
},
Icon: struct { Icon: struct {
field.RelationField field.RelationField
}{ }{
@ -288,6 +269,9 @@ func newNoteToPing(db *gorm.DB, opts ...gen.DOOption) noteToPing {
} }
Server struct { Server struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
} }
} }
}{ }{
@ -304,6 +288,9 @@ func newNoteToPing(db *gorm.DB, opts ...gen.DOOption) noteToPing {
} }
Server struct { Server struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
} }
}{ }{
RelationField: field.NewRelation("Note.EmoteRelations.Emote", "models.Emote"), RelationField: field.NewRelation("Note.EmoteRelations.Emote", "models.Emote"),
@ -314,8 +301,16 @@ func newNoteToPing(db *gorm.DB, opts ...gen.DOOption) noteToPing {
}, },
Server: struct { Server: struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
}{ }{
RelationField: field.NewRelation("Note.EmoteRelations.Emote.Server", "models.RemoteServer"), RelationField: field.NewRelation("Note.EmoteRelations.Emote.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("Note.EmoteRelations.Emote.Server.Icon", "models.MediaMetadata"),
},
}, },
}, },
}, },
@ -435,12 +430,6 @@ type noteToPingBelongsToNote struct {
Creator struct { Creator struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }
@ -526,6 +515,9 @@ type noteToPingBelongsToNote struct {
} }
Server struct { Server struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
} }
} }
} }

View file

@ -46,12 +46,6 @@ func newNote(db *gorm.DB, opts ...gen.DOOption) note {
field.RelationField field.RelationField
Creator struct { Creator struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }
@ -131,6 +125,9 @@ func newNote(db *gorm.DB, opts ...gen.DOOption) note {
} }
Server struct { Server struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
} }
} }
} }
@ -153,12 +150,6 @@ func newNote(db *gorm.DB, opts ...gen.DOOption) note {
RelationField: field.NewRelation("AttachmentRelations.Note", "models.Note"), RelationField: field.NewRelation("AttachmentRelations.Note", "models.Note"),
Creator: struct { Creator: struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }
@ -224,19 +215,6 @@ func newNote(db *gorm.DB, opts ...gen.DOOption) note {
} }
}{ }{
RelationField: field.NewRelation("AttachmentRelations.Note.Creator", "models.User"), RelationField: field.NewRelation("AttachmentRelations.Note.Creator", "models.User"),
Server: struct {
field.RelationField
Icon struct {
field.RelationField
}
}{
RelationField: field.NewRelation("AttachmentRelations.Note.Creator.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("AttachmentRelations.Note.Creator.Server.Icon", "models.MediaMetadata"),
},
},
Icon: struct { Icon: struct {
field.RelationField field.RelationField
}{ }{
@ -390,6 +368,9 @@ func newNote(db *gorm.DB, opts ...gen.DOOption) note {
} }
Server struct { Server struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
} }
} }
}{ }{
@ -406,6 +387,9 @@ func newNote(db *gorm.DB, opts ...gen.DOOption) note {
} }
Server struct { Server struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
} }
}{ }{
RelationField: field.NewRelation("AttachmentRelations.Note.EmoteRelations.Emote", "models.Emote"), RelationField: field.NewRelation("AttachmentRelations.Note.EmoteRelations.Emote", "models.Emote"),
@ -416,8 +400,16 @@ func newNote(db *gorm.DB, opts ...gen.DOOption) note {
}, },
Server: struct { Server: struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
}{ }{
RelationField: field.NewRelation("AttachmentRelations.Note.EmoteRelations.Emote.Server", "models.RemoteServer"), RelationField: field.NewRelation("AttachmentRelations.Note.EmoteRelations.Emote.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("AttachmentRelations.Note.EmoteRelations.Emote.Server.Icon", "models.MediaMetadata"),
},
}, },
}, },
}, },
@ -596,12 +588,6 @@ type noteHasManyAttachmentRelations struct {
field.RelationField field.RelationField
Creator struct { Creator struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }
@ -681,6 +667,9 @@ type noteHasManyAttachmentRelations struct {
} }
Server struct { Server struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
} }
} }
} }

View file

@ -40,19 +40,6 @@ func newNotification(db *gorm.DB, opts ...gen.DOOption) notification {
db: db.Session(&gorm.Session{}), db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("ForUser", "models.User"), RelationField: field.NewRelation("ForUser", "models.User"),
Server: struct {
field.RelationField
Icon struct {
field.RelationField
}
}{
RelationField: field.NewRelation("ForUser.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("ForUser.Server.Icon", "models.MediaMetadata"),
},
},
Icon: struct { Icon: struct {
field.RelationField field.RelationField
}{ }{
@ -232,6 +219,9 @@ func newNotification(db *gorm.DB, opts ...gen.DOOption) notification {
} }
Server struct { Server struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
} }
} }
}{ }{
@ -248,6 +238,9 @@ func newNotification(db *gorm.DB, opts ...gen.DOOption) notification {
} }
Server struct { Server struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
} }
}{ }{
RelationField: field.NewRelation("SourceNote.EmoteRelations.Emote", "models.Emote"), RelationField: field.NewRelation("SourceNote.EmoteRelations.Emote", "models.Emote"),
@ -258,8 +251,16 @@ func newNotification(db *gorm.DB, opts ...gen.DOOption) notification {
}, },
Server: struct { Server: struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
}{ }{
RelationField: field.NewRelation("SourceNote.EmoteRelations.Emote.Server", "models.RemoteServer"), RelationField: field.NewRelation("SourceNote.EmoteRelations.Emote.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("SourceNote.EmoteRelations.Emote.Server.Icon", "models.MediaMetadata"),
},
}, },
}, },
}, },
@ -397,12 +398,6 @@ type notificationBelongsToForUser struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }
@ -562,6 +557,9 @@ type notificationBelongsToSourceNote struct {
} }
Server struct { Server struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
} }
} }
} }

View file

@ -39,12 +39,6 @@ func newReaction(db *gorm.DB, opts ...gen.DOOption) reaction {
RelationField: field.NewRelation("Note", "models.Note"), RelationField: field.NewRelation("Note", "models.Note"),
Creator: struct { Creator: struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }
@ -110,19 +104,6 @@ func newReaction(db *gorm.DB, opts ...gen.DOOption) reaction {
} }
}{ }{
RelationField: field.NewRelation("Note.Creator", "models.User"), RelationField: field.NewRelation("Note.Creator", "models.User"),
Server: struct {
field.RelationField
Icon struct {
field.RelationField
}
}{
RelationField: field.NewRelation("Note.Creator.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("Note.Creator.Server.Icon", "models.MediaMetadata"),
},
},
Icon: struct { Icon: struct {
field.RelationField field.RelationField
}{ }{
@ -292,6 +273,9 @@ func newReaction(db *gorm.DB, opts ...gen.DOOption) reaction {
} }
Server struct { Server struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
} }
} }
}{ }{
@ -308,6 +292,9 @@ func newReaction(db *gorm.DB, opts ...gen.DOOption) reaction {
} }
Server struct { Server struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
} }
}{ }{
RelationField: field.NewRelation("Note.EmoteRelations.Emote", "models.Emote"), RelationField: field.NewRelation("Note.EmoteRelations.Emote", "models.Emote"),
@ -318,8 +305,16 @@ func newReaction(db *gorm.DB, opts ...gen.DOOption) reaction {
}, },
Server: struct { Server: struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
}{ }{
RelationField: field.NewRelation("Note.EmoteRelations.Emote.Server", "models.RemoteServer"), RelationField: field.NewRelation("Note.EmoteRelations.Emote.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("Note.EmoteRelations.Emote.Server.Icon", "models.MediaMetadata"),
},
}, },
}, },
}, },
@ -459,12 +454,6 @@ type reactionBelongsToNote struct {
Creator struct { Creator struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }
@ -550,6 +539,9 @@ type reactionBelongsToNote struct {
} }
Server struct { Server struct {
field.RelationField field.RelationField
Icon struct {
field.RelationField
}
} }
} }
} }

View file

@ -38,19 +38,6 @@ func newUserAuthMethod(db *gorm.DB, opts ...gen.DOOption) userAuthMethod {
db: db.Session(&gorm.Session{}), db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("User", "models.User"), RelationField: field.NewRelation("User", "models.User"),
Server: struct {
field.RelationField
Icon struct {
field.RelationField
}
}{
RelationField: field.NewRelation("User.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("User.Server.Icon", "models.MediaMetadata"),
},
},
Icon: struct { Icon: struct {
field.RelationField field.RelationField
}{ }{
@ -273,12 +260,6 @@ type userAuthMethodBelongsToUser struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }

View file

@ -39,19 +39,6 @@ func newUserInfoField(db *gorm.DB, opts ...gen.DOOption) userInfoField {
db: db.Session(&gorm.Session{}), db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("User", "models.User"), RelationField: field.NewRelation("User", "models.User"),
Server: struct {
field.RelationField
Icon struct {
field.RelationField
}
}{
RelationField: field.NewRelation("User.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("User.Server.Icon", "models.MediaMetadata"),
},
},
Icon: struct { Icon: struct {
field.RelationField field.RelationField
}{ }{
@ -277,12 +264,6 @@ type userInfoFieldBelongsToUser struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }

View file

@ -43,19 +43,6 @@ func newUserRemoteLinks(db *gorm.DB, opts ...gen.DOOption) userRemoteLinks {
db: db.Session(&gorm.Session{}), db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("User", "models.User"), RelationField: field.NewRelation("User", "models.User"),
Server: struct {
field.RelationField
Icon struct {
field.RelationField
}
}{
RelationField: field.NewRelation("User.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("User.Server.Icon", "models.MediaMetadata"),
},
},
Icon: struct { Icon: struct {
field.RelationField field.RelationField
}{ }{
@ -293,12 +280,6 @@ type userRemoteLinksBelongsToUser struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }

View file

@ -33,19 +33,6 @@ func newUserToBeing(db *gorm.DB, opts ...gen.DOOption) userToBeing {
db: db.Session(&gorm.Session{}), db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("User", "models.User"), RelationField: field.NewRelation("User", "models.User"),
Server: struct {
field.RelationField
Icon struct {
field.RelationField
}
}{
RelationField: field.NewRelation("User.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("User.Server.Icon", "models.MediaMetadata"),
},
},
Icon: struct { Icon: struct {
field.RelationField field.RelationField
}{ }{
@ -253,12 +240,6 @@ type userToBeingBelongsToUser struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }

View file

@ -28,24 +28,11 @@ func newUserToPronoun(db *gorm.DB, opts ...gen.DOOption) userToPronoun {
_userToPronoun.ALL = field.NewAsterisk(tableName) _userToPronoun.ALL = field.NewAsterisk(tableName)
_userToPronoun.ID = field.NewUint64(tableName, "id") _userToPronoun.ID = field.NewUint64(tableName, "id")
_userToPronoun.UserId = field.NewString(tableName, "user_id") _userToPronoun.UserId = field.NewString(tableName, "user_id")
_userToPronoun.Pronoun = field.NewString(tableName, "pronoun") _userToPronoun.Pronoung = field.NewString(tableName, "pronoung")
_userToPronoun.User = userToPronounBelongsToUser{ _userToPronoun.User = userToPronounBelongsToUser{
db: db.Session(&gorm.Session{}), db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("User", "models.User"), RelationField: field.NewRelation("User", "models.User"),
Server: struct {
field.RelationField
Icon struct {
field.RelationField
}
}{
RelationField: field.NewRelation("User.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("User.Server.Icon", "models.MediaMetadata"),
},
},
Icon: struct { Icon: struct {
field.RelationField field.RelationField
}{ }{
@ -191,11 +178,11 @@ func newUserToPronoun(db *gorm.DB, opts ...gen.DOOption) userToPronoun {
type userToPronoun struct { type userToPronoun struct {
userToPronounDo userToPronounDo
ALL field.Asterisk ALL field.Asterisk
ID field.Uint64 ID field.Uint64
UserId field.String UserId field.String
Pronoun field.String Pronoung field.String
User userToPronounBelongsToUser User userToPronounBelongsToUser
fieldMap map[string]field.Expr fieldMap map[string]field.Expr
} }
@ -214,7 +201,7 @@ func (u *userToPronoun) updateTableName(table string) *userToPronoun {
u.ALL = field.NewAsterisk(table) u.ALL = field.NewAsterisk(table)
u.ID = field.NewUint64(table, "id") u.ID = field.NewUint64(table, "id")
u.UserId = field.NewString(table, "user_id") u.UserId = field.NewString(table, "user_id")
u.Pronoun = field.NewString(table, "pronoun") u.Pronoung = field.NewString(table, "pronoung")
u.fillFieldMap() u.fillFieldMap()
@ -234,7 +221,7 @@ func (u *userToPronoun) fillFieldMap() {
u.fieldMap = make(map[string]field.Expr, 4) u.fieldMap = make(map[string]field.Expr, 4)
u.fieldMap["id"] = u.ID u.fieldMap["id"] = u.ID
u.fieldMap["user_id"] = u.UserId u.fieldMap["user_id"] = u.UserId
u.fieldMap["pronoun"] = u.Pronoun u.fieldMap["pronoung"] = u.Pronoung
} }
@ -253,12 +240,6 @@ type userToPronounBelongsToUser struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }

View file

@ -33,19 +33,6 @@ func newUserToRole(db *gorm.DB, opts ...gen.DOOption) userToRole {
db: db.Session(&gorm.Session{}), db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("User", "models.User"), RelationField: field.NewRelation("User", "models.User"),
Server: struct {
field.RelationField
Icon struct {
field.RelationField
}
}{
RelationField: field.NewRelation("User.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("User.Server.Icon", "models.MediaMetadata"),
},
},
Icon: struct { Icon: struct {
field.RelationField field.RelationField
}{ }{
@ -261,12 +248,6 @@ type userToRoleBelongsToUser struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }

View file

@ -33,19 +33,6 @@ func newUserToTag(db *gorm.DB, opts ...gen.DOOption) userToTag {
db: db.Session(&gorm.Session{}), db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("User", "models.User"), RelationField: field.NewRelation("User", "models.User"),
Server: struct {
field.RelationField
Icon struct {
field.RelationField
}
}{
RelationField: field.NewRelation("User.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("User.Server.Icon", "models.MediaMetadata"),
},
},
Icon: struct { Icon: struct {
field.RelationField field.RelationField
}{ }{
@ -253,12 +240,6 @@ type userToTagBelongsToUser struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }

View file

@ -34,19 +34,6 @@ func newUserToUserRelation(db *gorm.DB, opts ...gen.DOOption) userToUserRelation
db: db.Session(&gorm.Session{}), db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("User", "models.User"), RelationField: field.NewRelation("User", "models.User"),
Server: struct {
field.RelationField
Icon struct {
field.RelationField
}
}{
RelationField: field.NewRelation("User.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("User.Server.Icon", "models.MediaMetadata"),
},
},
Icon: struct { Icon: struct {
field.RelationField field.RelationField
}{ }{
@ -265,12 +252,6 @@ type userToUserRelationBelongsToUser struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }

View file

@ -36,7 +36,7 @@ func newUser(db *gorm.DB, opts ...gen.DOOption) user {
_user.DisplayName = field.NewString(tableName, "display_name") _user.DisplayName = field.NewString(tableName, "display_name")
_user.Description = field.NewString(tableName, "description") _user.Description = field.NewString(tableName, "description")
_user.IsBot = field.NewBool(tableName, "is_bot") _user.IsBot = field.NewBool(tableName, "is_bot")
_user.IconId = field.NewField(tableName, "icon_id") _user.IconId = field.NewString(tableName, "icon_id")
_user.BackgroundId = field.NewField(tableName, "background_id") _user.BackgroundId = field.NewField(tableName, "background_id")
_user.BannerId = field.NewField(tableName, "banner_id") _user.BannerId = field.NewField(tableName, "banner_id")
_user.Indexable = field.NewBool(tableName, "indexable") _user.Indexable = field.NewBool(tableName, "indexable")
@ -47,19 +47,12 @@ func newUser(db *gorm.DB, opts ...gen.DOOption) user {
_user.Verified = field.NewBool(tableName, "verified") _user.Verified = field.NewBool(tableName, "verified")
_user.PasskeyId = field.NewBytes(tableName, "passkey_id") _user.PasskeyId = field.NewBytes(tableName, "passkey_id")
_user.FinishedRegistration = field.NewBool(tableName, "finished_registration") _user.FinishedRegistration = field.NewBool(tableName, "finished_registration")
_user.PrivateKey = field.NewBytes(tableName, "private_key")
_user.RemoteInfo = userHasOneRemoteInfo{ _user.RemoteInfo = userHasOneRemoteInfo{
db: db.Session(&gorm.Session{}), db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("RemoteInfo", "models.UserRemoteLinks"), RelationField: field.NewRelation("RemoteInfo", "models.UserRemoteLinks"),
User: struct { User: struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }
@ -122,19 +115,6 @@ func newUser(db *gorm.DB, opts ...gen.DOOption) user {
} }
}{ }{
RelationField: field.NewRelation("RemoteInfo.User", "models.User"), RelationField: field.NewRelation("RemoteInfo.User", "models.User"),
Server: struct {
field.RelationField
Icon struct {
field.RelationField
}
}{
RelationField: field.NewRelation("RemoteInfo.User.Server", "models.RemoteServer"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("RemoteInfo.User.Server.Icon", "models.MediaMetadata"),
},
},
Icon: struct { Icon: struct {
field.RelationField field.RelationField
}{ }{
@ -307,12 +287,6 @@ func newUser(db *gorm.DB, opts ...gen.DOOption) user {
RelationField: field.NewRelation("AuthMethods", "models.UserAuthMethod"), RelationField: field.NewRelation("AuthMethods", "models.UserAuthMethod"),
} }
_user.Server = userBelongsToServer{
db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("Server", "models.RemoteServer"),
}
_user.Icon = userBelongsToIcon{ _user.Icon = userBelongsToIcon{
db: db.Session(&gorm.Session{}), db: db.Session(&gorm.Session{}),
@ -349,7 +323,7 @@ type user struct {
DisplayName field.String DisplayName field.String
Description field.String Description field.String
IsBot field.Bool IsBot field.Bool
IconId field.Field IconId field.String
BackgroundId field.Field BackgroundId field.Field
BannerId field.Field BannerId field.Field
Indexable field.Bool Indexable field.Bool
@ -360,7 +334,6 @@ type user struct {
Verified field.Bool Verified field.Bool
PasskeyId field.Bytes PasskeyId field.Bytes
FinishedRegistration field.Bool FinishedRegistration field.Bool
PrivateKey field.Bytes
RemoteInfo userHasOneRemoteInfo RemoteInfo userHasOneRemoteInfo
InfoFields userHasManyInfoFields InfoFields userHasManyInfoFields
@ -377,8 +350,6 @@ type user struct {
AuthMethods userHasManyAuthMethods AuthMethods userHasManyAuthMethods
Server userBelongsToServer
Icon userBelongsToIcon Icon userBelongsToIcon
Background userBelongsToBackground Background userBelongsToBackground
@ -409,7 +380,7 @@ func (u *user) updateTableName(table string) *user {
u.DisplayName = field.NewString(table, "display_name") u.DisplayName = field.NewString(table, "display_name")
u.Description = field.NewString(table, "description") u.Description = field.NewString(table, "description")
u.IsBot = field.NewBool(table, "is_bot") u.IsBot = field.NewBool(table, "is_bot")
u.IconId = field.NewField(table, "icon_id") u.IconId = field.NewString(table, "icon_id")
u.BackgroundId = field.NewField(table, "background_id") u.BackgroundId = field.NewField(table, "background_id")
u.BannerId = field.NewField(table, "banner_id") u.BannerId = field.NewField(table, "banner_id")
u.Indexable = field.NewBool(table, "indexable") u.Indexable = field.NewBool(table, "indexable")
@ -420,7 +391,6 @@ func (u *user) updateTableName(table string) *user {
u.Verified = field.NewBool(table, "verified") u.Verified = field.NewBool(table, "verified")
u.PasskeyId = field.NewBytes(table, "passkey_id") u.PasskeyId = field.NewBytes(table, "passkey_id")
u.FinishedRegistration = field.NewBool(table, "finished_registration") u.FinishedRegistration = field.NewBool(table, "finished_registration")
u.PrivateKey = field.NewBytes(table, "private_key")
u.fillFieldMap() u.fillFieldMap()
@ -437,7 +407,7 @@ func (u *user) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
} }
func (u *user) fillFieldMap() { func (u *user) fillFieldMap() {
u.fieldMap = make(map[string]field.Expr, 33) u.fieldMap = make(map[string]field.Expr, 31)
u.fieldMap["id"] = u.ID u.fieldMap["id"] = u.ID
u.fieldMap["username"] = u.Username u.fieldMap["username"] = u.Username
u.fieldMap["created_at"] = u.CreatedAt u.fieldMap["created_at"] = u.CreatedAt
@ -458,7 +428,6 @@ func (u *user) fillFieldMap() {
u.fieldMap["verified"] = u.Verified u.fieldMap["verified"] = u.Verified
u.fieldMap["passkey_id"] = u.PasskeyId u.fieldMap["passkey_id"] = u.PasskeyId
u.fieldMap["finished_registration"] = u.FinishedRegistration u.fieldMap["finished_registration"] = u.FinishedRegistration
u.fieldMap["private_key"] = u.PrivateKey
} }
@ -479,12 +448,6 @@ type userHasOneRemoteInfo struct {
User struct { User struct {
field.RelationField field.RelationField
Server struct {
field.RelationField
Icon struct {
field.RelationField
}
}
Icon struct { Icon struct {
field.RelationField field.RelationField
} }
@ -1110,77 +1073,6 @@ func (a userHasManyAuthMethodsTx) Count() int64 {
return a.tx.Count() return a.tx.Count()
} }
type userBelongsToServer struct {
db *gorm.DB
field.RelationField
}
func (a userBelongsToServer) Where(conds ...field.Expr) *userBelongsToServer {
if len(conds) == 0 {
return &a
}
exprs := make([]clause.Expression, 0, len(conds))
for _, cond := range conds {
exprs = append(exprs, cond.BeCond().(clause.Expression))
}
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
return &a
}
func (a userBelongsToServer) WithContext(ctx context.Context) *userBelongsToServer {
a.db = a.db.WithContext(ctx)
return &a
}
func (a userBelongsToServer) Session(session *gorm.Session) *userBelongsToServer {
a.db = a.db.Session(session)
return &a
}
func (a userBelongsToServer) Model(m *models.User) *userBelongsToServerTx {
return &userBelongsToServerTx{a.db.Model(m).Association(a.Name())}
}
type userBelongsToServerTx struct{ tx *gorm.Association }
func (a userBelongsToServerTx) Find() (result *models.RemoteServer, err error) {
return result, a.tx.Find(&result)
}
func (a userBelongsToServerTx) Append(values ...*models.RemoteServer) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Append(targetValues...)
}
func (a userBelongsToServerTx) Replace(values ...*models.RemoteServer) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Replace(targetValues...)
}
func (a userBelongsToServerTx) Delete(values ...*models.RemoteServer) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Delete(targetValues...)
}
func (a userBelongsToServerTx) Clear() error {
return a.tx.Clear()
}
func (a userBelongsToServerTx) Count() int64 {
return a.tx.Count()
}
type userBelongsToIcon struct { type userBelongsToIcon struct {
db *gorm.DB db *gorm.DB

View file

@ -1,7 +1,6 @@
package models package models
import ( import (
"database/sql"
"time" "time"
"gorm.io/gorm" "gorm.io/gorm"
@ -19,8 +18,7 @@ type MediaMetadata struct {
// Soft delete means that this entry still exists in the db, but gorm won't include it anymore unless specifically told to // 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 // If not null, this entry is marked as deleted
DeletedAt gorm.DeletedAt `gorm:"index"` DeletedAt gorm.DeletedAt `gorm:"index"`
// OwnedBy User OwnedById string // Account id this media belongs to
OwnedById sql.NullString // Account id this media belongs to
Remote bool // whether the attachment is a remote one Remote bool // whether the attachment is a remote one
// Where the media is stored. Url // Where the media is stored. Url
Location string Location string
@ -39,3 +37,14 @@ type MediaMetadata struct {
// or embedded data, such as the default duck // or embedded data, such as the default duck
// For external users, transform them into normal http URIs with a "special" path // For external users, transform them into normal http URIs with a "special" path
const DefaultDuckLocationName = "linstrom://default-media" 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 ( import (
"database/sql" "database/sql"
"git.mstar.dev/mstar/linstrom/config"
"gorm.io/gorm" "gorm.io/gorm"
) )
@ -17,3 +18,17 @@ type RemoteServer struct {
IconId sql.NullString // ID of a media file IconId sql.NullString // ID of a media file
IsSelf bool // Whether this server is yours truly 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

@ -4,13 +4,11 @@ import (
"math" "math"
"git.mstar.dev/mstar/goutils/other" "git.mstar.dev/mstar/goutils/other"
"gorm.io/gorm"
) )
// Default role every user has. Defines sane defaults for a normal user // Default role every user has. Defines sane defaults for a normal user
// Will get overwritten by just about every other role due to every other role having higher priority // Will get overwritten by just about every other role due to every other role having higher priority
var DefaultUserRole = Role{ var DefaultUserRole = Role{
Model: gorm.Model{ID: 1},
Name: "Default", Name: "Default",
Priority: 0, Priority: 0,
IsUserRole: false, IsUserRole: false,
@ -69,7 +67,6 @@ var DefaultUserRole = Role{
// Role providing maximum permissions // Role providing maximum permissions
var FullAdminRole = Role{ var FullAdminRole = Role{
Model: gorm.Model{ID: 2},
Name: "fullAdmin", Name: "fullAdmin",
Priority: math.MaxUint32, Priority: math.MaxUint32,
IsUserRole: false, IsUserRole: false,
@ -125,7 +122,6 @@ var FullAdminRole = Role{
// Role for totally freezing an account, blocking all activity from it // Role for totally freezing an account, blocking all activity from it
var AccountFreezeRole = Role{ var AccountFreezeRole = Role{
Model: gorm.Model{ID: 3},
Name: "accountFreeze", Name: "accountFreeze",
Priority: math.MaxUint32 - 1, Priority: math.MaxUint32 - 1,
IsUserRole: false, IsUserRole: false,
@ -183,7 +179,6 @@ var AccountFreezeRole = Role{
} }
var ServerActorRole = Role{ var ServerActorRole = Role{
Model: gorm.Model{ID: 4},
Name: "ServerActor", Name: "ServerActor",
Priority: math.MaxUint32, Priority: math.MaxUint32,
IsUserRole: true, IsUserRole: true,

View file

@ -6,6 +6,8 @@ import (
"gorm.io/gen" "gorm.io/gen"
"gorm.io/gorm" "gorm.io/gorm"
"git.mstar.dev/mstar/linstrom/config"
) )
// A user describes an account for creating content and events. // A user describes an account for creating content and events.
@ -42,8 +44,8 @@ type User struct {
DisplayName string // The display name of the user. Can be different from the handle DisplayName string // The display name of the user. Can be different from the handle
Description string // The description of a user account Description string // The description of a user account
IsBot bool // Whether to mark this account as a script controlled one IsBot bool // Whether to mark this account as a script controlled one
Icon *MediaMetadata Icon MediaMetadata
IconId sql.NullString // ID of a media file used as icon IconId string // ID of a media file used as icon
Background *MediaMetadata Background *MediaMetadata
BackgroundId sql.NullString // ID of a media file used as background image BackgroundId sql.NullString // ID of a media file used as background image
Banner *MediaMetadata Banner *MediaMetadata
@ -66,7 +68,6 @@ type User struct {
// saved space is worth // saved space is worth
PasskeyId []byte PasskeyId []byte
FinishedRegistration bool // Whether this account has completed registration yet FinishedRegistration bool // Whether this account has completed registration yet
PrivateKey []byte
// ---- "Remote" linked values // ---- "Remote" linked values
InfoFields []UserInfoField InfoFields []UserInfoField
@ -79,6 +80,25 @@ type User struct {
AuthMethods []UserAuthMethod 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},
}
}
type IUser interface { type IUser interface {
// Get a user by a username // Get a user by a username
// //

View file

@ -4,8 +4,8 @@ package models
// Each user may have zero, one or more pronouns // Each user may have zero, one or more pronouns
// but each user to pronoun relation may appear at most once // but each user to pronoun relation may appear at most once
type UserToPronoun struct { type UserToPronoun struct {
ID uint64 `gorm:"primarykey"` ID uint64 `gorm:"primarykey"`
User User User User
UserId string UserId string
Pronoun string Pronoung string
} }

View file

@ -1,154 +0,0 @@
package storage
import (
"crypto/ed25519"
"crypto/rand"
"database/sql"
"git.mstar.dev/mstar/goutils/other"
"github.com/google/uuid"
"github.com/rs/zerolog/log"
"gorm.io/gorm"
"git.mstar.dev/mstar/linstrom/config"
"git.mstar.dev/mstar/linstrom/storage-new/dbgen"
"git.mstar.dev/mstar/linstrom/storage-new/models"
)
func InsertSelf() error {
if err := insertRoles(); err != nil {
return other.Error("storage", "failed to save/update default roles", err)
}
duck, err := insertDefaultDuck()
if err != nil {
return other.Error("storage", "failed to save/update default duck", err)
}
server, err := insertServer(duck)
if err != nil {
return other.Error("storage", "failed to save/update self server", err)
}
log.Debug().Any("server", server).Send()
user, err := insertUser(server)
if err != nil {
return other.Error("storage", "failed to save/update self user", err)
}
if err = insertUserPronoun(user); err != nil {
return other.Error("storage", "failed to save/update self user pronoun", err)
}
return nil
}
func insertRoles() error {
return dbgen.Role.Save(models.AllDefaultRoles...)
}
func insertDefaultDuck() (*models.MediaMetadata, error) {
dbDuck, err := dbgen.MediaMetadata.Where(dbgen.MediaMetadata.Location.Eq(models.DefaultDuckLocationName)).
First()
if err == nil {
return dbDuck, nil
} else if err != gorm.ErrRecordNotFound {
return nil, err
}
duck := models.MediaMetadata{
ID: uuid.NewString(),
// NOTE: Default duck technically belongs to the server
// but to avoid cyclic dependency, declare it as unowned
OwnedById: sql.NullString{Valid: false},
Remote: false,
Location: models.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,
}
if err := dbgen.MediaMetadata.Create(&duck); err != nil {
return nil, err
}
return &duck, nil
}
func insertServer(duck *models.MediaMetadata) (*models.RemoteServer, error) {
dbServer, err := dbgen.RemoteServer.Where(dbgen.RemoteServer.ID.Eq(1)).First()
if err == nil {
return dbServer, nil
} else if err != gorm.ErrRecordNotFound {
return nil, err
}
server := models.RemoteServer{
Model: gorm.Model{
ID: 1,
},
ServerType: models.ServerSoftwareLinstrom,
Domain: config.GlobalConfig.General.GetFullDomain(),
Name: config.GlobalConfig.Self.ServerDisplayName,
Icon: duck,
IconId: sql.NullString{String: duck.ID, Valid: true},
IsSelf: true,
}
err = dbgen.RemoteServer.Save(&server)
if err != nil {
return nil, err
}
return &server, nil
}
func insertUser(server *models.RemoteServer) (*models.User, error) {
dbUser, err := dbgen.User.GetByUsername("linstrom")
if err == nil {
return dbUser, nil
}
if err != gorm.ErrRecordNotFound {
return nil, err
}
publicKey, privateKey, err := ed25519.GenerateKey(nil)
pkeyId := make([]byte, 64)
_, err = rand.Read(pkeyId)
if err != nil {
return nil, other.Error(
"storage",
"failed to generate passkey ID for linstrom account",
err,
)
}
user := models.User{
Username: "linstrom",
Server: *server,
ServerId: server.ID,
DisplayName: config.GlobalConfig.Self.ServerActorDisplayName,
Description: "The default linstrom server user",
IsBot: true,
Icon: nil,
IconId: sql.NullString{Valid: false},
Background: nil,
BackgroundId: sql.NullString{Valid: false},
Banner: nil,
BannerId: sql.NullString{Valid: false},
Indexable: false,
PublicKey: publicKey,
PrivateKey: privateKey,
Verified: true,
FinishedRegistration: true,
PasskeyId: pkeyId,
}
err = dbgen.User.Save(&user)
if err != nil {
return nil, err
}
return &user, err
}
func insertUserPronoun(user *models.User) error {
_, err := dbgen.UserToPronoun.Where(dbgen.UserToPronoun.UserId.Eq(user.ID)).
Where(dbgen.UserToPronoun.Pronoun.Eq("Yes")).First()
switch err {
case nil:
return nil
case gorm.ErrRecordNotFound:
return dbgen.UserToPronoun.Create(
&models.UserToPronoun{UserId: user.ID, User: *user, Pronoun: "Yes"},
)
default:
return err
}
}

View file

@ -1,7 +0,0 @@
package web
import "net/http"
type Server struct {
server http.Server
}

View file

@ -1,31 +0,0 @@
package webdebug
import (
"context"
"net/http"
)
const DebugAddr = "127.0.0.1:3305"
type Server struct {
server *http.Server
}
func New() *Server {
handler := http.NewServeMux()
web := http.Server{
Addr: DebugAddr,
Handler: handler,
}
return &Server{&web}
}
func (s *Server) Start() error {
if err := s.server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
return err
}
return nil
}
func (s *Server) Stop() error {
return s.server.Shutdown(context.Background())
}