diff --git a/auth/facebook.go b/auth/facebook.go index fe80d2f9..75fa4b5a 100644 --- a/auth/facebook.go +++ b/auth/facebook.go @@ -92,11 +92,7 @@ func InstallFacebookAuth(app *aero.Application) { if user != nil { // Add FacebookToUser reference - err = user.ConnectFacebook(fbUser.ID) - - if err != nil { - ctx.Error(http.StatusInternalServerError, "Could not connect account to Facebook account", err) - } + user.ConnectFacebook(fbUser.ID) // Save in DB user.Save() @@ -110,7 +106,7 @@ func InstallFacebookAuth(app *aero.Application) { var getErr error // Try to find an existing user via the Facebook user ID - user, getErr = arn.GetUserFromTable("FacebookToUser", fbUser.ID) + user, getErr = arn.GetUserByFacebookID(fbUser.ID) if getErr == nil && user != nil { authLog.Info("User logged in via Facebook ID", user.ID, user.Nick, ctx.RealIP(), user.Email, user.RealName()) @@ -148,18 +144,10 @@ func InstallFacebookAuth(app *aero.Application) { user.Save() // Register user - err = arn.RegisterUser(user) - - if err != nil { - ctx.Error(http.StatusInternalServerError, "Could not register a new user", err) - } + arn.RegisterUser(user) // Connect account to a Facebook account - err = user.ConnectFacebook(fbUser.ID) - - if err != nil { - ctx.Error(http.StatusInternalServerError, "Could not connect account to Facebook account", err) - } + user.ConnectFacebook(fbUser.ID) // Save user object again with updated data user.Save() diff --git a/auth/google.go b/auth/google.go index ff49d05e..77321831 100644 --- a/auth/google.go +++ b/auth/google.go @@ -102,11 +102,7 @@ func InstallGoogleAuth(app *aero.Application) { if user != nil { // Add GoogleToUser reference - err = user.ConnectGoogle(googleUser.Sub) - - if err != nil { - ctx.Error(http.StatusInternalServerError, "Could not connect account to Google account", err) - } + user.ConnectGoogle(googleUser.Sub) // Save in DB user.Save() @@ -120,7 +116,7 @@ func InstallGoogleAuth(app *aero.Application) { var getErr error // Try to find an existing user via the Google user ID - user, getErr = arn.GetUserFromTable("GoogleToUser", googleUser.Sub) + user, getErr = arn.GetUserByGoogleID(googleUser.Sub) if getErr == nil && user != nil { authLog.Info("User logged in via Google ID", user.ID, user.Nick, ctx.RealIP(), user.Email, user.RealName()) @@ -158,18 +154,10 @@ func InstallGoogleAuth(app *aero.Application) { user.Save() // Register user - err = arn.RegisterUser(user) - - if err != nil { - ctx.Error(http.StatusInternalServerError, "Could not register a new user", err) - } + arn.RegisterUser(user) // Connect account to a Google account - err = user.ConnectGoogle(googleUser.Sub) - - if err != nil { - ctx.Error(http.StatusInternalServerError, "Could not connect account to Google account", err) - } + user.ConnectGoogle(googleUser.Sub) // Save user object again with updated data user.Save() diff --git a/main.go b/main.go index 0e62f80d..4c7277e2 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,6 @@ package main import ( "github.com/aerogo/aero" - "github.com/aerogo/session-store-aerospike" "github.com/animenotifier/arn" "github.com/animenotifier/notify.moe/auth" "github.com/animenotifier/notify.moe/components/css" @@ -69,7 +68,10 @@ func configure(app *aero.Application) *aero.Application { // Sessions app.Sessions.Duration = 3600 * 24 * 30 * 6 - app.Sessions.Store = aerospikestore.New(arn.DB, "Session", app.Sessions.Duration) + + // TODO: ... + println("Using memory session store") + // app.Sessions.Store = aerospikestore.New(arn.DB, "Session", app.Sessions.Duration) // Layout app.Layout = layout.Render @@ -210,8 +212,6 @@ func configure(app *aero.Application) *aero.Application { // Domain if arn.IsDevelopment() { app.Config.Domain = "beta.notify.moe" - } else { - arn.DB.SetScanPriority("high") } // Authentication diff --git a/pages/database/select.go b/pages/database/select.go index 5b1aa8f2..a9666d1c 100644 --- a/pages/database/select.go +++ b/pages/database/select.go @@ -48,11 +48,7 @@ func Select(ctx *aero.Context) string { Results: []interface{}{}, } - stream, err := arn.DB.All(dataTypeName) - - if err != nil { - return ctx.Error(http.StatusInternalServerError, "Error fetching data from the database", err) - } + stream := arn.DB.All(dataTypeName) process := func(obj interface{}) { _, _, value, _ := mirror.GetField(obj, field) @@ -62,47 +58,8 @@ func Select(ctx *aero.Context) string { } } - switch dataTypeName { - case "Analytics": - for obj := range stream.(chan *arn.Analytics) { - process(obj) - } - case "Anime": - for obj := range stream.(chan *arn.Anime) { - process(obj) - } - case "AnimeList": - for obj := range stream.(chan *arn.AnimeList) { - process(obj) - } - case "Character": - for obj := range stream.(chan *arn.Character) { - process(obj) - } - case "Group": - for obj := range stream.(chan *arn.Group) { - process(obj) - } - case "Post": - for obj := range stream.(chan *arn.Post) { - process(obj) - } - case "Settings": - for obj := range stream.(chan *arn.Settings) { - process(obj) - } - case "SoundTrack": - for obj := range stream.(chan *arn.SoundTrack) { - process(obj) - } - case "Thread": - for obj := range stream.(chan *arn.Thread) { - process(obj) - } - case "User": - for obj := range stream.(chan *arn.User) { - process(obj) - } + for obj := range stream { + process(obj) } for _, obj := range response.Results { diff --git a/pages/editor/anilist.go b/pages/editor/anilist.go index ffb8678b..f3c1415f 100644 --- a/pages/editor/anilist.go +++ b/pages/editor/anilist.go @@ -1,7 +1,6 @@ package editor import ( - "net/http" "sort" "github.com/aerogo/aero" @@ -13,14 +12,10 @@ const maxAniListEntries = 70 // AniList ... func AniList(ctx *aero.Context) string { - missing, err := arn.FilterAnime(func(anime *arn.Anime) bool { + missing := arn.FilterAnime(func(anime *arn.Anime) bool { return anime.GetMapping("anilist/anime") == "" }) - if err != nil { - ctx.Error(http.StatusInternalServerError, "Couldn't filter anime", err) - } - sort.Slice(missing, func(i, j int) bool { a := missing[i] b := missing[j] diff --git a/pages/editor/shoboi.go b/pages/editor/shoboi.go index dd33e329..96a1df94 100644 --- a/pages/editor/shoboi.go +++ b/pages/editor/shoboi.go @@ -1,7 +1,6 @@ package editor import ( - "net/http" "sort" "github.com/aerogo/aero" @@ -13,14 +12,10 @@ const maxShoboiEntries = 70 // Shoboi ... func Shoboi(ctx *aero.Context) string { - missing, err := arn.FilterAnime(func(anime *arn.Anime) bool { + missing := arn.FilterAnime(func(anime *arn.Anime) bool { return anime.GetMapping("shoboi/anime") == "" }) - if err != nil { - ctx.Error(http.StatusInternalServerError, "Couldn't filter anime", err) - } - sort.Slice(missing, func(i, j int) bool { a := missing[i] b := missing[j] diff --git a/pages/explore/explore.go b/pages/explore/explore.go index 529bbb15..fe1225f5 100644 --- a/pages/explore/explore.go +++ b/pages/explore/explore.go @@ -2,20 +2,19 @@ package explore import ( "github.com/aerogo/aero" - "github.com/animenotifier/arn" - "github.com/animenotifier/notify.moe/components" ) // Get ... func Get(ctx *aero.Context) string { - var cache arn.ListOfIDs - err := arn.DB.GetObject("Cache", "airing anime", &cache) + // var cache arn.ListOfIDs + // err := arn.DB.GetObject("Cache", "airing anime", &cache) - airing, err := arn.GetAiringAnimeCached() + // airing, err := arn.GetAiringAnimeCached() - if err != nil { - return ctx.Error(500, "Couldn't fetch airing anime", err) - } + // if err != nil { + // return ctx.Error(500, "Couldn't fetch airing anime", err) + // } - return ctx.HTML(components.Airing(airing)) + // return ctx.HTML(components.Airing(airing)) + return ctx.HTML("Not implemented") } diff --git a/pages/forum/forum.go b/pages/forum/forum.go index 1d648a98..49eaf27b 100644 --- a/pages/forum/forum.go +++ b/pages/forum/forum.go @@ -12,7 +12,7 @@ const ThreadsPerPage = 20 // Get forum category. func Get(ctx *aero.Context) string { tag := ctx.Get("tag") - threads, _ := arn.GetThreadsByTag(tag) + threads := arn.GetThreadsByTag(tag) arn.SortThreads(threads) if len(threads) > ThreadsPerPage { diff --git a/pages/listimport/listimportanilist/anilist.go b/pages/listimport/listimportanilist/anilist.go index 6f1b3c95..c3e6e0f0 100644 --- a/pages/listimport/listimportanilist/anilist.go +++ b/pages/listimport/listimportanilist/anilist.go @@ -64,11 +64,7 @@ func Finish(ctx *aero.Context) string { animeList.Import(item) } - err := animeList.Save() - - if err != nil { - return ctx.Error(http.StatusInternalServerError, "Error saving your anime list", err) - } + animeList.Save() return ctx.Redirect("/+" + user.Nick + "/animelist") } diff --git a/pages/listimport/listimportkitsu/kitsu.go b/pages/listimport/listimportkitsu/kitsu.go index ebdcd7a3..52254045 100644 --- a/pages/listimport/listimportkitsu/kitsu.go +++ b/pages/listimport/listimportkitsu/kitsu.go @@ -77,11 +77,7 @@ func Finish(ctx *aero.Context) string { animeList.Import(item) } - err := animeList.Save() - - if err != nil { - return ctx.Error(http.StatusInternalServerError, "Error saving your anime list", err) - } + animeList.Save() return ctx.Redirect("/+" + user.Nick + "/animelist") } diff --git a/pages/listimport/listimportmyanimelist/myanimelist.go b/pages/listimport/listimportmyanimelist/myanimelist.go index 7b816e37..455a9f8b 100644 --- a/pages/listimport/listimportmyanimelist/myanimelist.go +++ b/pages/listimport/listimportmyanimelist/myanimelist.go @@ -73,11 +73,7 @@ func Finish(ctx *aero.Context) string { animeList.Import(item) } - err := animeList.Save() - - if err != nil { - return ctx.Error(http.StatusInternalServerError, "Error saving your anime list", err) - } + animeList.Save() return ctx.Redirect("/+" + user.Nick + "/animelist") } diff --git a/pages/paypal/success.go b/pages/paypal/success.go index ee7f609f..6bd509e3 100644 --- a/pages/paypal/success.go +++ b/pages/paypal/success.go @@ -66,21 +66,13 @@ func Success(ctx *aero.Context) string { Created: arn.DateTimeUTC(), } - err = payment.Save() - - if err != nil { - return ctx.Error(http.StatusInternalServerError, "Could not save payment in the database", err) - } + payment.Save() // Increase user's balance user.Balance += payment.Gems() // Save in DB - err = user.Save() - - if err != nil { - return ctx.Error(http.StatusInternalServerError, "Could not save new balance", err) - } + user.Save() // Notify admin go func() { diff --git a/pages/shop/buyitem.go b/pages/shop/buyitem.go index 669c4ebf..df2b1d78 100644 --- a/pages/shop/buyitem.go +++ b/pages/shop/buyitem.go @@ -46,27 +46,16 @@ func BuyItem(ctx *aero.Context) string { } user.Balance -= totalPrice - err = user.Save() - - if err != nil { - return ctx.Error(http.StatusInternalServerError, "Error saving user data", err) - } + user.Save() // Add item to user inventory inventory := user.Inventory() inventory.AddItem(itemID, uint(quantity)) - err = inventory.Save() - - if err != nil { - return ctx.Error(http.StatusInternalServerError, "Error saving inventory", err) - } + inventory.Save() // Save purchase - err = arn.NewPurchase(user.ID, itemID, quantity, int(item.Price), "gem").Save() - - if err != nil { - return ctx.Error(http.StatusInternalServerError, "Error saving purchase", err) - } + purchase := arn.NewPurchase(user.ID, itemID, quantity, int(item.Price), "gem") + purchase.Save() return "ok" } diff --git a/pages/statistics/anime.go b/pages/statistics/anime.go index 87e20c28..19e4ed4e 100644 --- a/pages/statistics/anime.go +++ b/pages/statistics/anime.go @@ -2,13 +2,12 @@ package statistics import ( "github.com/aerogo/aero" - "github.com/animenotifier/arn" - "github.com/animenotifier/notify.moe/components" ) // Anime ... func Anime(ctx *aero.Context) string { - statistics := arn.StatisticsCategory{} - arn.DB.GetObject("Cache", "anime statistics", &statistics) - return ctx.HTML(components.Statistics(statistics.PieCharts...)) + // statistics := arn.StatisticsCategory{} + // arn.DB.GetObject("Cache", "anime statistics", &statistics) + // return ctx.HTML(components.Statistics(statistics.PieCharts...)) + return ctx.HTML("Not implemented") } diff --git a/pages/statistics/statistics.go b/pages/statistics/statistics.go index 04d1855d..a9219f76 100644 --- a/pages/statistics/statistics.go +++ b/pages/statistics/statistics.go @@ -2,13 +2,12 @@ package statistics import ( "github.com/aerogo/aero" - "github.com/animenotifier/arn" - "github.com/animenotifier/notify.moe/components" ) // Get ... func Get(ctx *aero.Context) string { - statistics := arn.StatisticsCategory{} - arn.DB.GetObject("Cache", "user statistics", &statistics) - return ctx.HTML(components.Statistics(statistics.PieCharts...)) + // statistics := arn.StatisticsCategory{} + // arn.DB.GetObject("Cache", "user statistics", &statistics) + // return ctx.HTML(components.Statistics(statistics.PieCharts...)) + return ctx.HTML("Not implemented") } diff --git a/pages/threads/threads.go b/pages/threads/threads.go index b9b7977e..435e1056 100644 --- a/pages/threads/threads.go +++ b/pages/threads/threads.go @@ -22,14 +22,13 @@ func Get(ctx *aero.Context) string { } // Fetch posts - postObjects, getErr := arn.DB.GetMany("Post", thread.Posts) + postObjects := arn.DB.GetMany("Post", thread.Posts) + posts := make([]*arn.Post, len(postObjects), len(postObjects)) - if getErr != nil { - return ctx.Error(http.StatusInternalServerError, "Could not retrieve posts", getErr) + for i, obj := range postObjects { + posts[i] = obj.(*arn.Post) } - posts := postObjects.([]*arn.Post) - // Sort posts arn.SortPostsLatestLast(posts) diff --git a/pages/users/users.go b/pages/users/users.go index 919af4af..b12b5fe2 100644 --- a/pages/users/users.go +++ b/pages/users/users.go @@ -10,11 +10,11 @@ import ( // Active ... func Active(ctx *aero.Context) string { - users, err := arn.GetListOfUsersCached("active users") + users := arn.FilterUsers(func(user *arn.User) bool { + return user.IsActive() && user.HasAvatar() + }) - if err != nil { - return ctx.Error(http.StatusInternalServerError, "Could not fetch user data", err) - } + arn.SortUsersLastSeen(users) return ctx.HTML(components.Users(users)) } diff --git a/patches/export-aero-db/export-aero-db.go b/patches/export-aero-db/export-aero-db.go index d66c872b..a03ddc11 100644 --- a/patches/export-aero-db/export-aero-db.go +++ b/patches/export-aero-db/export-aero-db.go @@ -11,7 +11,7 @@ import ( func main() { arn.DB.SetScanPriority("high") - aeroDB := database.New("db", arn.DBTypes) + aeroDB := database.New("arn", arn.DBTypes) defer aeroDB.Close() for typeName := range arn.DB.Types() {