Updated struct

This commit is contained in:
Eduard Urbach 2017-07-17 19:56:26 +02:00
parent 98c4b90e9f
commit e014a5f628
5 changed files with 16 additions and 18 deletions

View File

@ -15,7 +15,7 @@ func main() {
// Filter out active users with an avatar // Filter out active users with an avatar
users, err := arn.FilterUsers(func(user *arn.User) bool { users, err := arn.FilterUsers(func(user *arn.User) bool {
return user.IsActive() && user.AvatarExtension != "" return user.IsActive() && user.Avatar.Extension != ""
}) })
if err != nil { if err != nil {

View File

@ -52,7 +52,7 @@ func (output *AvatarOriginalFileOutput) SaveAvatar(avatar *Avatar) error {
} }
// Set user avatar // Set user avatar
avatar.User.AvatarExtension = extension avatar.User.Avatar.Extension = extension
// Write to file // Write to file
fileName := output.Directory + avatar.User.ID + extension fileName := output.Directory + avatar.User.ID + extension

View File

@ -123,7 +123,7 @@ func StartWorkers(queue chan *arn.User, work func(*arn.User)) {
// Work handles a single user. // Work handles a single user.
func Work(user *arn.User) { func Work(user *arn.User) {
user.AvatarExtension = "" user.Avatar.Extension = ""
for _, source := range avatarSources { for _, source := range avatarSources {
avatar := source.GetAvatar(user) avatar := source.GetAvatar(user)
@ -141,7 +141,7 @@ func Work(user *arn.User) {
// Avoid quality loss (if it's on the file system, we don't need to write it again) // Avoid quality loss (if it's on the file system, we don't need to write it again)
if sourceType == "FileSystem" { if sourceType == "FileSystem" {
user.AvatarExtension = avatar.Extension() user.Avatar.Extension = avatar.Extension()
break break
} }
@ -157,7 +157,7 @@ func Work(user *arn.User) {
} }
// Since this a very long running job, refresh user data before saving it. // Since this a very long running job, refresh user data before saving it.
avatarExt := user.AvatarExtension avatarExt := user.Avatar.Extension
user, err := arn.GetUser(user.ID) user, err := arn.GetUser(user.ID)
if err != nil { if err != nil {
@ -166,6 +166,6 @@ func Work(user *arn.User) {
} }
// Save avatar data // Save avatar data
user.AvatarExtension = avatarExt user.Avatar.Extension = avatarExt
user.Save() user.Save()
} }

View File

@ -8,8 +8,8 @@ import (
func main() { func main() {
for user := range arn.MustStreamUsers() { for user := range arn.MustStreamUsers() {
if !strings.HasPrefix(user.AvatarExtension, ".") { if !strings.HasPrefix(user.Avatar.Extension, ".") {
user.AvatarExtension = "" user.Avatar.Extension = ""
} }
user.Save() user.Save()

View File

@ -1,24 +1,22 @@
package main package main
import ( import (
"github.com/animenotifier/arn"
"github.com/fatih/color" "github.com/fatih/color"
"github.com/jinzhu/copier"
) )
func main() { func main() {
color.Yellow("Updating user struct") color.Yellow("Updating user struct")
// Iterate over the stream // // Iterate over the stream
for user := range arn.MustStreamUsers() { // for user := range arn.MustStreamUsers() {
newUser := &arn.UserNew{} // newUser := &arn.UserNew{}
copier.Copy(newUser, user) // copier.Copy(newUser, user)
newUser.Avatar.Extension = user.Avatar // newUser.Avatar.Extension = user.Avatar
// Save in DB // // Save in DB
arn.PanicOnError(arn.DB.Set("User", user.ID, newUser)) // arn.PanicOnError(arn.DB.Set("User", user.ID, newUser))
} // }
color.Green("Finished.") color.Green("Finished.")
} }