chore(go): migrate more models to codegen versions. For #3778
This commit is contained in:
@@ -162,9 +162,9 @@ func loadEmoji() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
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)
|
emojiArr = append(emojiArr, emoji)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,16 +10,16 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/owncast/owncast/config"
|
"github.com/owncast/owncast/config"
|
||||||
"github.com/owncast/owncast/models"
|
|
||||||
"github.com/owncast/owncast/static"
|
"github.com/owncast/owncast/static"
|
||||||
"github.com/owncast/owncast/utils"
|
"github.com/owncast/owncast/utils"
|
||||||
|
"github.com/owncast/owncast/webserver/handlers/generated"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
emojiCacheMu sync.Mutex
|
emojiCacheMu sync.Mutex
|
||||||
emojiCacheData = make([]models.CustomEmoji, 0)
|
emojiCacheData = make([]generated.Emoji, 0)
|
||||||
emojiCacheModTime time.Time
|
emojiCacheModTime time.Time
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ func UpdateEmojiList(force bool) (time.Time, error) {
|
|||||||
return modTime, fmt.Errorf("unable to open custom emoji directory")
|
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 {
|
walkFunction := func(path string, d os.DirEntry, err error) error {
|
||||||
if d == nil || d.IsDir() {
|
if d == nil || d.IsDir() {
|
||||||
@@ -61,7 +61,7 @@ func UpdateEmojiList(force bool) (time.Time, error) {
|
|||||||
emojiPath := filepath.Join(config.EmojiDir, path)
|
emojiPath := filepath.Join(config.EmojiDir, path)
|
||||||
fileName := d.Name()
|
fileName := d.Name()
|
||||||
fileBase := fileName[:len(fileName)-len(filepath.Ext(fileName))]
|
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)
|
emojiCacheData = append(emojiCacheData, singleEmoji)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -76,7 +76,7 @@ func UpdateEmojiList(force bool) (time.Time, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetEmojiList returns a list of custom emoji from the emoji directory.
|
// GetEmojiList returns a list of custom emoji from the emoji directory.
|
||||||
func GetEmojiList() []models.CustomEmoji {
|
func GetEmojiList() []generated.Emoji {
|
||||||
_, err := UpdateEmojiList(false)
|
_, err := UpdateEmojiList(false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
@@ -88,7 +88,7 @@ func GetEmojiList() []models.CustomEmoji {
|
|||||||
|
|
||||||
// return a copy of cache data, ensures underlying slice isn't affected
|
// return a copy of cache data, ensures underlying slice isn't affected
|
||||||
// by future update
|
// by future update
|
||||||
emojiData := make([]models.CustomEmoji, len(emojiCacheData))
|
emojiData := make([]generated.Emoji, len(emojiCacheData))
|
||||||
copy(emojiData, emojiCacheData)
|
copy(emojiData, emojiCacheData)
|
||||||
|
|
||||||
return emojiData
|
return emojiData
|
||||||
|
|||||||
@@ -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"`
|
|
||||||
}
|
|
||||||
@@ -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"`
|
|
||||||
}
|
|
||||||
@@ -3,13 +3,13 @@ package authrepository
|
|||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
|
||||||
"github.com/owncast/owncast/models"
|
"github.com/owncast/owncast/webserver/handlers/generated"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AuthRepository interface {
|
type AuthRepository interface {
|
||||||
CreateBanIPTable(db *sql.DB)
|
CreateBanIPTable(db *sql.DB)
|
||||||
BanIPAddress(address, note string) error
|
BanIPAddress(address, note string) error
|
||||||
IsIPAddressBanned(address string) (bool, error)
|
IsIPAddressBanned(address string) (bool, error)
|
||||||
GetIPAddressBans() ([]models.IPAddress, error)
|
GetIPAddressBans() ([]generated.IPAddress, error)
|
||||||
RemoveIPAddressBan(address string) error
|
RemoveIPAddressBan(address string) error
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/owncast/owncast/db"
|
"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.
|
// 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.
|
// 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())
|
result, err := r.datastore.GetQueries().GetIPAddressBans(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
response := []models.IPAddress{}
|
response := []generated.IPAddress{}
|
||||||
for _, ip := range result {
|
for _, ip := range result {
|
||||||
response = append(response, models.IPAddress{
|
response = append(response, generated.IPAddress{
|
||||||
IPAddress: ip.IpAddress,
|
IpAddress: &ip.IpAddress,
|
||||||
Notes: ip.Notes.String,
|
Notes: &ip.Notes.String,
|
||||||
CreatedAt: ip.CreatedAt.Time,
|
CreatedAt: &ip.CreatedAt.Time,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return response, err
|
return response, err
|
||||||
|
|||||||
Reference in New Issue
Block a user