2017-06-12 18:06:31 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"runtime"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/animenotifier/arn"
|
2017-06-12 22:06:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
avatarsDirectoryOriginal = "images/avatars/original/"
|
|
|
|
avatarsDirectoryWebP = "images/avatars/webp/"
|
2017-06-12 18:06:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2017-06-12 22:06:35 +00:00
|
|
|
os.Chdir("../../")
|
|
|
|
|
2017-06-12 18:06:31 +00:00
|
|
|
users, _ := arn.AllUsers()
|
|
|
|
|
|
|
|
usersQueue := make(chan *arn.User)
|
|
|
|
rateLimiter := time.NewTicker(100 * time.Millisecond)
|
|
|
|
defer rateLimiter.Stop()
|
|
|
|
|
|
|
|
for w := 0; w < runtime.NumCPU(); w++ {
|
|
|
|
go func(workerID int) {
|
|
|
|
for user := range usersQueue {
|
|
|
|
<-rateLimiter.C
|
2017-06-12 22:06:35 +00:00
|
|
|
|
2017-06-12 19:11:20 +00:00
|
|
|
if downloadAvatar(user) {
|
|
|
|
makeWebPAvatar(user)
|
|
|
|
user.Avatar = "/+" + user.Nick + "/avatar"
|
|
|
|
} else {
|
|
|
|
user.Avatar = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
user.Save()
|
2017-06-12 18:06:31 +00:00
|
|
|
}
|
|
|
|
}(w)
|
|
|
|
}
|
|
|
|
|
|
|
|
for user := range users {
|
|
|
|
usersQueue <- user
|
|
|
|
}
|
|
|
|
}
|