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
users, err := arn.FilterUsers(func(user *arn.User) bool {
return user.IsActive() && user.AvatarExtension != ""
return user.IsActive() && user.Avatar.Extension != ""
})
if err != nil {

View File

@ -52,7 +52,7 @@ func (output *AvatarOriginalFileOutput) SaveAvatar(avatar *Avatar) error {
}
// Set user avatar
avatar.User.AvatarExtension = extension
avatar.User.Avatar.Extension = extension
// Write to file
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.
func Work(user *arn.User) {
user.AvatarExtension = ""
user.Avatar.Extension = ""
for _, source := range avatarSources {
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)
if sourceType == "FileSystem" {
user.AvatarExtension = avatar.Extension()
user.Avatar.Extension = avatar.Extension()
break
}
@ -157,7 +157,7 @@ func Work(user *arn.User) {
}
// 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)
if err != nil {
@ -166,6 +166,6 @@ func Work(user *arn.User) {
}
// Save avatar data
user.AvatarExtension = avatarExt
user.Avatar.Extension = avatarExt
user.Save()
}

View File

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

View File

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