2025-02-24 22:04:48 +05:00

184 lines
4.8 KiB
Go

package model
import (
"strconv"
"strings"
"time"
)
type Widget struct {
ID WidgetID `db:"id"`
StreamerID StreamerID `db:"streamer_id"`
TemplateID TemplateID `db:"template_id"`
BackgroundUrl MediaUrl `db:"background_url"`
ImageUrl MediaUrl `db:"image_url"`
AudioUrl MediaUrl `db:"audio_url"`
MinAmount DonatAmount `db:"min_amount"`
Duration Duration `db:"duration"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
}
type Donat struct {
ID DonatID `db:"id"`
StreamerID StreamerID `db:"streamer_id"`
WidgetID WidgetID `db:"widget_id"`
OrderID OrderID `db:"order_id"`
TargetID TargetID `db:"target_id"`
Text string `db:"text"`
DonatUser string `db:"donat_user"`
Amount DonatAmount `db:"amount"`
Paid bool `db:"paid"`
View bool `db:"view"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
}
type Target struct {
ID TargetID `db:"id"`
StreamerID StreamerID `db:"streamer_id"`
Text string `db:"text"`
Collected DonatAmount `db:"collected"`
Amount DonatAmount `db:"amount"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
}
type DonatePage struct {
id int `db:"id"`
streamerID int `db:"streamer_id"`
description string `db:"description"`
textAfterDonat string `db:"text_after_donat"`
pageBackground string `db:"page_background"`
avatar string `db:"avatar"`
backgroundImg string `db:"background_img"`
}
type Moderation struct {
id int `db:"id"`
streamerID int `db:"streamer_id"`
enable bool `db:"enable"`
duration int `db:"duration"`
}
type Filter struct {
id int `db:"id"`
streamerID int `db:"streamer_id"`
enableLinks bool `db:"enable_links"`
}
type FilterWord struct {
id int `db:"id"`
donatFilterID int `db:"donat_filter_id"`
word string `db:"word"`
}
type VoiceSettings struct {
id int `db:"id"`
streamerID int `db:"streamer_id"`
voiceSpeed int `db:"voice_speed"`
scenery string `db:"scenery"`
voiceSoundPercent int `db:"voice_sound_percent"`
minPrice int `db:"min_price"`
}
type Language struct {
id int `db:"id"`
isoCode string `db:"iso_code"`
ruName string `db:"ru_name"`
enName string `db:"en_name"`
}
type VoiceLanguage struct {
id int `db:"id"`
voiceSettingID int `db:"voice_setting_id"`
languageID int `db:"language_id"`
}
type UpdateDonatPage struct {
ProfileAvatar bool `json:"profileAvatar"`
Description string `json:"description"`
TextAfterDonat string `json:"textAfterDonat"`
PageBackground string `json:"pageBackground"`
}
type VoiceSettingsResponse struct {
Id int `json:"id"`
StreamerID int `json:"streamerID"`
VoiceSpeed int `json:"voiceSpeed"`
Scenery string `json:"scenery"`
VoiceSoundPercent int `json:"voiceSoundPercent"`
MinPrice int `json:"minPrice"`
}
type UpdateVoiceSettings struct {
Enable bool `json:"enable"`
VoiceSpeed int `json:"voiceSpeed"`
Scenery string `json:"scenery"`
VoiceSoundPercent int `json:"voiceSoundPercent"`
MinPrice int `json:"minPrice"`
}
type FilterSettingResponse struct {
EnableLinks bool `json:"enableLinks"`
FilteredWords []string `json:"filteredWords"`
}
type UpdateFilterSettings struct {
EnableLinks bool `json:"enableLinks"`
AddWords []string `json:"addWords"`
RemoveWords []string `json:"removeWords"`
}
type ModerationResponse struct {
Enable bool `json:"enable"`
Duration int `json:"duration"`
}
type UpdateModeration struct {
Enable bool `json:"enable"`
Duration int `json:"duration"`
}
type DonatAndWidget struct {
Widget *Widget
Donat *Donat
Display Display
}
func (widget *Widget) GetMediaUrl(mediaType MediaType) MediaUrl {
var mediaUrl MediaUrl
if mediaType == "background_url" {
mediaUrl = widget.BackgroundUrl
} else if mediaType == "image_url" {
mediaUrl = widget.ImageUrl
} else if mediaType == "audio_url" {
mediaUrl = widget.AudioUrl
}
return mediaUrl
}
func (widget *Widget) NormalizeUrl() {
selfDomain := "http://localhost:8002/api/widget/media"
strWidgetID := strconv.Itoa(int(widget.ID))
if !strings.Contains(string(widget.ImageUrl), "http") && widget.ImageUrl != "" {
widget.ImageUrl = MediaUrl(selfDomain + "/image/get/" + strWidgetID)
}
if !strings.Contains(string(widget.BackgroundUrl), "http") && widget.BackgroundUrl != "" {
widget.BackgroundUrl = MediaUrl(selfDomain + "/background/get/" + strWidgetID)
}
if !strings.Contains(string(widget.AudioUrl), "http") && widget.AudioUrl != "" {
widget.AudioUrl = MediaUrl(selfDomain + "/audio/get/" + strWidgetID)
}
}