chore(go): migrate more models to codegen versions. For #3778

This commit is contained in:
Gabe Kangas
2025-02-12 21:18:13 -08:00
parent 8bdb52fd37
commit 4b627f0693
6 changed files with 17 additions and 34 deletions

View File

@@ -162,9 +162,9 @@ func loadEmoji() {
if err != nil {
return
}
emojiHTML[strings.ToLower(emojiList[i].Name)] = buf.String()
emojiHTML[strings.ToLower(*emojiList[i].Name)] = buf.String()
emoji := emojiDef.NewEmoji(emojiList[i].Name, nil, strings.ToLower(emojiList[i].Name))
emoji := emojiDef.NewEmoji(*emojiList[i].Name, nil, strings.ToLower(*emojiList[i].Name))
emojiArr = append(emojiArr, emoji)
}

View File

@@ -10,16 +10,16 @@ import (
"time"
"github.com/owncast/owncast/config"
"github.com/owncast/owncast/models"
"github.com/owncast/owncast/static"
"github.com/owncast/owncast/utils"
"github.com/owncast/owncast/webserver/handlers/generated"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)
var (
emojiCacheMu sync.Mutex
emojiCacheData = make([]models.CustomEmoji, 0)
emojiCacheData = make([]generated.Emoji, 0)
emojiCacheModTime time.Time
)
@@ -51,7 +51,7 @@ func UpdateEmojiList(force bool) (time.Time, error) {
return modTime, fmt.Errorf("unable to open custom emoji directory")
}
emojiCacheData = make([]models.CustomEmoji, 0)
emojiCacheData = make([]generated.Emoji, 0)
walkFunction := func(path string, d os.DirEntry, err error) error {
if d == nil || d.IsDir() {
@@ -61,7 +61,7 @@ func UpdateEmojiList(force bool) (time.Time, error) {
emojiPath := filepath.Join(config.EmojiDir, path)
fileName := d.Name()
fileBase := fileName[:len(fileName)-len(filepath.Ext(fileName))]
singleEmoji := models.CustomEmoji{Name: fileBase, URL: emojiPath}
singleEmoji := generated.Emoji{Name: &fileBase, Url: &emojiPath}
emojiCacheData = append(emojiCacheData, singleEmoji)
return nil
}
@@ -76,7 +76,7 @@ func UpdateEmojiList(force bool) (time.Time, error) {
}
// GetEmojiList returns a list of custom emoji from the emoji directory.
func GetEmojiList() []models.CustomEmoji {
func GetEmojiList() []generated.Emoji {
_, err := UpdateEmojiList(false)
if err != nil {
return nil
@@ -88,7 +88,7 @@ func GetEmojiList() []models.CustomEmoji {
// return a copy of cache data, ensures underlying slice isn't affected
// by future update
emojiData := make([]models.CustomEmoji, len(emojiCacheData))
emojiData := make([]generated.Emoji, len(emojiCacheData))
copy(emojiData, emojiCacheData)
return emojiData

View File

@@ -1,7 +0,0 @@
package models
// CustomEmoji represents an image that can be used in chat as a custom emoji.
type CustomEmoji struct {
Name string `json:"name"`
URL string `json:"url"`
}

View File

@@ -1,10 +0,0 @@
package models
import "time"
// IPAddress is a simple representation of an IP address.
type IPAddress struct {
CreatedAt time.Time `json:"createdAt"`
IPAddress string `json:"ipAddress"`
Notes string `json:"notes"`
}

View File

@@ -3,13 +3,13 @@ package authrepository
import (
"database/sql"
"github.com/owncast/owncast/models"
"github.com/owncast/owncast/webserver/handlers/generated"
)
type AuthRepository interface {
CreateBanIPTable(db *sql.DB)
BanIPAddress(address, note string) error
IsIPAddressBanned(address string) (bool, error)
GetIPAddressBans() ([]models.IPAddress, error)
GetIPAddressBans() ([]generated.IPAddress, error)
RemoveIPAddressBan(address string) error
}

View File

@@ -6,7 +6,7 @@ import (
"log"
"github.com/owncast/owncast/db"
"github.com/owncast/owncast/models"
"github.com/owncast/owncast/webserver/handlers/generated"
)
// CreateBanIPTable will create the IP ban table if needed.
@@ -42,18 +42,18 @@ func (r *SqlAuthRepository) IsIPAddressBanned(address string) (bool, error) {
}
// GetIPAddressBans will return all the banned IP addresses.
func (r *SqlAuthRepository) GetIPAddressBans() ([]models.IPAddress, error) {
func (r *SqlAuthRepository) GetIPAddressBans() ([]generated.IPAddress, error) {
result, err := r.datastore.GetQueries().GetIPAddressBans(context.Background())
if err != nil {
return nil, err
}
response := []models.IPAddress{}
response := []generated.IPAddress{}
for _, ip := range result {
response = append(response, models.IPAddress{
IPAddress: ip.IpAddress,
Notes: ip.Notes.String,
CreatedAt: ip.CreatedAt.Time,
response = append(response, generated.IPAddress{
IpAddress: &ip.IpAddress,
Notes: &ip.Notes.String,
CreatedAt: &ip.CreatedAt.Time,
})
}
return response, err