HEAVY: migrate accounts and logs to service/repo architecture

This commit is contained in:
ari melody 2026-07-31 02:43:45 +01:00
parent 5c255fb34b
commit 49e14b5bc5
Signed by: ari
GPG key ID: CF99829C92678188
37 changed files with 1019 additions and 687 deletions

View file

@ -1,11 +1,13 @@
package model
package app
import (
"embed"
"github.com/jmoiron/sqlx"
"arimelody-web/log"
"arimelody-web/model/twitch"
accountService "arimelody-web/service/account"
"arimelody-web/service/log"
)
type (
@ -43,8 +45,10 @@ type (
AppState struct {
DB *sqlx.DB
Config Config
Log log.Logger
Twitch *TwitchState
Log *log.LogService
Twitch *twitch.State
PublicFS embed.FS
AccountService *accountService.AccountService
}
)

31
model/log.go Normal file
View file

@ -0,0 +1,31 @@
package model
import "time"
type (
LogLevel int
Log struct {
ID string `json:"id" db:"id"`
Level LogLevel `json:"level" db:"level"`
Type string `json:"type" db:"type"`
Content string `json:"content" db:"content"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
)
const (
LOG_ACCOUNT string = "account"
LOG_MUSIC string = "music"
LOG_ARTIST string = "artist"
LOG_BLOG string = "blog"
LOG_ARTWORK string = "artwork"
LOG_FILES string = "files"
LOG_MISC string = "misc"
LOG_CURSOR string = "cursor"
)
const (
LEVEL_INFO LogLevel = 0
LEVEL_WARN LogLevel = 1
)

View file

@ -1,4 +1,4 @@
package model
package twitch
import (
"fmt"
@ -7,17 +7,17 @@ import (
)
type (
TwitchOAuthToken struct {
OAuthToken struct {
AccessToken string
ExpiresAt time.Time
TokenType string
}
TwitchState struct {
Token *TwitchOAuthToken
State struct {
Token *OAuthToken
}
TwitchStreamInfo struct {
StreamInfo struct {
ID string `json:"id"`
UserID string `json:"user_id"`
UserLogin string `json:"user_login"`
@ -36,7 +36,7 @@ type (
}
)
func (info *TwitchStreamInfo) Thumbnail(width int, height int) string {
func (info *StreamInfo) Thumbnail(width int, height int) string {
res := strings.Replace(info.ThumbnailURL, "{width}", fmt.Sprintf("%d", width), 1)
res = strings.Replace(res, "{height}", fmt.Sprintf("%d", height), 1)
return res