package service import ( accountproto "service/api/proto/account/proto" streamerproto "service/api/proto/streamer/proto" "service/app/mix/dao" "service/bizcommon/util" "service/dbstruct" "github.com/gin-gonic/gin" goproto "google.golang.org/protobuf/proto" ) func (s *Service) CreateUpdateAccountImageAudit(ctx *gin.Context, oldAccount *dbstruct.Account, newAccount *dbstruct.Account) (tasks []*dbstruct.ImageAuditTask) { if newAccount.Avatar == nil { return nil } tasks = make([]*dbstruct.ImageAuditTask, 0) tasks = append(tasks, &dbstruct.ImageAuditTask{ RouteUrl: goproto.String(ctx.Request.URL.Path), AssociativeDatabase: goproto.String("account"), AssociativeTableName: goproto.String("account"), AssociativeTableId: newAccount.Mid, AssociativeTableColumn: goproto.String("avatar"), AuditedMedia: newAccount.Avatar, OldMedia: oldAccount.Avatar, }) return } func (s *Service) CreateUpdateStreamerImageAudit(ctx *gin.Context, oldStreamer *dbstruct.Streamer, newStreamer *dbstruct.Streamer) (tasks []*dbstruct.ImageAuditTask) { tasks = make([]*dbstruct.ImageAuditTask, 0) if newStreamer.Cover != nil { tasks = append(tasks, &dbstruct.ImageAuditTask{ RouteUrl: goproto.String(ctx.Request.URL.Path), AssociativeDatabase: goproto.String("streamer"), AssociativeTableName: goproto.String("streamer"), AssociativeTableId: oldStreamer.Mid, AssociativeTableColumn: goproto.String("cover"), AuditedMedia: newStreamer.Cover, OldMedia: oldStreamer.Cover, }) } if newStreamer.Album != nil { tasks = append(tasks, &dbstruct.ImageAuditTask{ RouteUrl: goproto.String(ctx.Request.URL.Path), AssociativeDatabase: goproto.String("streamer"), AssociativeTableName: goproto.String("streamer"), AssociativeTableId: oldStreamer.Mid, AssociativeTableColumn: goproto.String("album"), AuditedMedia: newStreamer.Album, OldMedia: oldStreamer.Album, }) } return } func (s *Service) GetUpdateImageFunc(ctx *gin.Context, task *dbstruct.ImageAuditTask) func() error { db := util.DerefString(task.AssociativeDatabase) table := util.DerefString(task.AssociativeTableName) column := util.DerefString(task.AssociativeTableColumn) if db == dao.DBAccount && table == dao.DBAccount { return s.GetAccountUpdateImageFunc(ctx, column, task.AuditedMedia, task.AssociativeTableId) } if db == dao.DBStreamer && table == dao.DBStreamer { return s.GetStreamerUpdateImageFunc(ctx, column, task.AuditedMedia, task.AssociativeTableId) } return func() error { return nil } } func (s *Service) GetAccountUpdateImageFunc(ctx *gin.Context, column string, media *dbstruct.MediaComponent, id *int64) func() error { if column == "avatar" { return func() error { return _DefaultAccount.OpUpdate(ctx, &accountproto.OpUpdateReq{ Account: &dbstruct.Account{ Mid: id, Avatar: media, }, }) } } return func() error { return nil } } func (s *Service) GetStreamerUpdateImageFunc(ctx *gin.Context, column string, media *dbstruct.MediaComponent, id *int64) func() error { switch column { case "cover": return func() error { return _DefaultStreamer.OpUpdate(ctx, &streamerproto.OpUpdateReq{ Streamer: &dbstruct.Streamer{ Mid: id, Cover: media, }, }) } case "album": return func() error { return _DefaultStreamer.OpUpdate(ctx, &streamerproto.OpUpdateReq{ Streamer: &dbstruct.Streamer{ Mid: id, Album: media, }, }) } } return func() error { return nil } }