Implemented kitsu import
This commit is contained in:
parent
771e6b026c
commit
9339dc054a
@ -1,19 +1,49 @@
|
|||||||
package animeimport
|
package animeimport
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/animenotifier/kitsu"
|
||||||
|
"github.com/fatih/color"
|
||||||
|
|
||||||
|
"github.com/animenotifier/arn"
|
||||||
|
|
||||||
"github.com/aerogo/aero"
|
"github.com/aerogo/aero"
|
||||||
|
"github.com/animenotifier/notify.moe/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Kitsu anime import.
|
// Kitsu anime import.
|
||||||
func Kitsu(ctx *aero.Context) string {
|
func Kitsu(ctx *aero.Context) string {
|
||||||
// id := ctx.Get("id")
|
id := ctx.Get("id")
|
||||||
// user := utils.GetUser(ctx)
|
user := utils.GetUser(ctx)
|
||||||
|
|
||||||
if true {
|
if user == nil || (user.Role != "editor" && user.Role != "admin") {
|
||||||
return ctx.Error(http.StatusUnauthorized, "Not authorized", nil)
|
return ctx.Error(http.StatusUnauthorized, "Not authorized", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kitsuAnimeObj, err := arn.Kitsu.Get("Anime", id)
|
||||||
|
|
||||||
|
if kitsuAnimeObj == nil {
|
||||||
|
return ctx.Error(http.StatusNotFound, "Kitsu anime not found", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
kitsuAnime := kitsuAnimeObj.(*kitsu.Anime)
|
||||||
|
|
||||||
|
// Convert
|
||||||
|
anime, characters, relations, episodes := arn.NewAnimeFromKitsuAnime(kitsuAnime)
|
||||||
|
|
||||||
|
// Add user ID to the anime
|
||||||
|
anime.CreatedBy = user.ID
|
||||||
|
|
||||||
|
// Save in database
|
||||||
|
anime.Save()
|
||||||
|
characters.Save()
|
||||||
|
relations.Save()
|
||||||
|
episodes.Save()
|
||||||
|
|
||||||
|
// Log
|
||||||
|
fmt.Println(color.GreenString("✔"), anime.ID, anime.Title.Canonical)
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
@ -30,12 +30,15 @@ export function malDiffFilterAnime(arn: AnimeNotifier, input: HTMLInputElement)
|
|||||||
|
|
||||||
// Import Kitsu anime
|
// Import Kitsu anime
|
||||||
export async function importKitsuAnime(arn: AnimeNotifier, button: HTMLButtonElement) {
|
export async function importKitsuAnime(arn: AnimeNotifier, button: HTMLButtonElement) {
|
||||||
let response = await fetch(`/api/import/kitsu/anime/${button.dataset.id}`, {
|
let newTab = window.open()
|
||||||
|
let animeId = button.dataset.id
|
||||||
|
let response = await fetch(`/api/import/kitsu/anime/${animeId}`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
credentials: "same-origin"
|
credentials: "same-origin"
|
||||||
})
|
})
|
||||||
|
|
||||||
if(response.ok) {
|
if(response.ok) {
|
||||||
|
newTab.location.href = `/anime/${animeId}`
|
||||||
arn.reloadContent()
|
arn.reloadContent()
|
||||||
} else {
|
} else {
|
||||||
arn.statusMessage.showError(await response.text())
|
arn.statusMessage.showError(await response.text())
|
||||||
|
Loading…
Reference in New Issue
Block a user