Upgraded to latest aero version

This commit is contained in:
2019-06-01 13:55:49 +09:00
parent ae591e5e7e
commit 28db818c37
196 changed files with 645 additions and 593 deletions

View File

@ -9,7 +9,7 @@ import (
)
// Get ...
func Get(ctx *aero.Context) string {
func Get(ctx aero.Context) error {
user := utils.GetUser(ctx)
if user == nil {

View File

@ -1,6 +1,8 @@
package listimportanilist
import (
"errors"
"fmt"
"net/http"
"strconv"
@ -12,34 +14,34 @@ import (
)
// Preview shows an import preview.
func Preview(ctx *aero.Context) string {
func Preview(ctx aero.Context) error {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusBadRequest, "Not logged in")
}
matches, response := getMatches(ctx)
matches, err := getMatches(ctx)
if response != "" {
return response
if err != nil {
return ctx.Error(http.StatusBadRequest, err)
}
return ctx.HTML(components.ImportAnilist(user, matches))
}
// Finish ...
func Finish(ctx *aero.Context) string {
func Finish(ctx aero.Context) error {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusBadRequest, "Not logged in")
}
matches, response := getMatches(ctx)
matches, err := getMatches(ctx)
if response != "" {
return response
if err != nil {
return ctx.Error(http.StatusBadRequest, err)
}
animeList := user.AnimeList()
@ -71,31 +73,29 @@ func Finish(ctx *aero.Context) string {
}
// getMatches finds and returns all matches for the logged in user.
func getMatches(ctx *aero.Context) ([]*arn.AniListMatch, string) {
func getMatches(ctx aero.Context) ([]*arn.AniListMatch, error) {
user := utils.GetUser(ctx)
if user == nil {
return nil, ctx.Error(http.StatusBadRequest, "Not logged in")
return nil, errors.New("Not logged in")
}
// Get user
anilistUser, err := anilist.GetUser(user.Accounts.AniList.Nick)
if err != nil {
return nil, ctx.Error(http.StatusBadRequest, "User doesn't exist on AniList", err)
return nil, fmt.Errorf("User doesn't exist on AniList: %s", err.Error())
}
// Get anime list
anilistAnimeList, err := anilist.GetAnimeList(anilistUser.ID)
if err != nil {
return nil, ctx.Error(http.StatusBadRequest, "Couldn't load your anime list from AniList", err)
return nil, fmt.Errorf("Couldn't load your anime list from AniList: %s", err.Error())
}
// Find matches
matches := findAllMatches(anilistAnimeList)
return matches, ""
return matches, nil
}
// findAllMatches returns all matches for the anime inside an anilist anime list.

View File

@ -1,6 +1,8 @@
package listimportkitsu
import (
"errors"
"fmt"
"net/http"
"github.com/aerogo/aero"
@ -11,34 +13,34 @@ import (
)
// Preview shows an import preview.
func Preview(ctx *aero.Context) string {
func Preview(ctx aero.Context) error {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusBadRequest, "Not logged in")
}
matches, response := getMatches(ctx)
matches, err := getMatches(ctx)
if response != "" {
return response
if err != nil {
return ctx.Error(http.StatusBadRequest, err)
}
return ctx.HTML(components.ImportKitsu(user, matches))
}
// Finish ...
func Finish(ctx *aero.Context) string {
func Finish(ctx aero.Context) error {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusBadRequest, "Not logged in")
}
matches, response := getMatches(ctx)
matches, err := getMatches(ctx)
if response != "" {
return response
if err != nil {
return ctx.Error(http.StatusBadRequest, err)
}
animeList := user.AnimeList()
@ -82,23 +84,23 @@ func Finish(ctx *aero.Context) string {
}
// getMatches finds and returns all matches for the logged in user.
func getMatches(ctx *aero.Context) ([]*arn.KitsuMatch, string) {
func getMatches(ctx aero.Context) ([]*arn.KitsuMatch, error) {
user := utils.GetUser(ctx)
if user == nil {
return nil, ctx.Error(http.StatusBadRequest, "Not logged in")
return nil, errors.New("Not logged in")
}
kitsuUser, err := kitsu.GetUser(user.Accounts.Kitsu.Nick)
if err != nil {
return nil, ctx.Error(http.StatusBadRequest, "Couldn't load your user info from Kitsu", err)
return nil, fmt.Errorf("Couldn't load your user info from Kitsu: %s", err.Error())
}
library := kitsuUser.StreamLibraryEntries()
matches := findAllMatches(library)
return matches, ""
return matches, nil
}
// findAllMatches returns all matches for the anime inside an anilist anime list.

View File

@ -1,6 +1,8 @@
package listimportmyanimelist
import (
"errors"
"fmt"
"net/http"
"strconv"
@ -12,34 +14,34 @@ import (
)
// Preview shows an import preview.
func Preview(ctx *aero.Context) string {
func Preview(ctx aero.Context) error {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusBadRequest, "Not logged in")
}
matches, response := getMatches(ctx)
matches, err := getMatches(ctx)
if response != "" {
return response
if err != nil {
return ctx.Error(http.StatusBadRequest, err)
}
return ctx.HTML(components.ImportMyAnimeList(user, matches))
}
// Finish ...
func Finish(ctx *aero.Context) string {
func Finish(ctx aero.Context) error {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusBadRequest, "Not logged in")
}
matches, response := getMatches(ctx)
matches, err := getMatches(ctx)
if response != "" {
return response
if err != nil {
return ctx.Error(http.StatusBadRequest, err)
}
animeList := user.AnimeList()
@ -76,22 +78,22 @@ func Finish(ctx *aero.Context) string {
}
// getMatches finds and returns all matches for the logged in user.
func getMatches(ctx *aero.Context) ([]*arn.MyAnimeListMatch, string) {
func getMatches(ctx aero.Context) ([]*arn.MyAnimeListMatch, error) {
user := utils.GetUser(ctx)
if user == nil {
return nil, ctx.Error(http.StatusBadRequest, "Not logged in")
return nil, errors.New("Not logged in")
}
malAnimeList, err := mal.GetAnimeList(user.Accounts.MyAnimeList.Nick)
if err != nil {
return nil, ctx.Error(http.StatusBadRequest, "Couldn't load your anime list from MyAnimeList", err)
return nil, fmt.Errorf("Couldn't load your anime list from MyAnimeList: %s", err.Error())
}
matches := findAllMatches(malAnimeList)
return matches, ""
return matches, nil
}
// findAllMatches returns all matches for the anime inside an anilist anime list.