95 lines
2.4 KiB
Go
95 lines
2.4 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 UpdateDonatPage struct {
|
|
ProfileAvatar bool `json:"profileAvatar"`
|
|
Description string `json:"description"`
|
|
TextAfterDonat string `json:"textAfterDonat"`
|
|
PageBackground string `json:"pageBackground"`
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|