Added deletion to Kitsu imports
This commit is contained in:
43
pages/animeimport/deletekitsu.go
Normal file
43
pages/animeimport/deletekitsu.go
Normal file
@ -0,0 +1,43 @@
|
||||
package animeimport
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/animenotifier/arn"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/notify.moe/utils"
|
||||
)
|
||||
|
||||
// DeleteKitsu marks an anime for deletion.
|
||||
func DeleteKitsu(ctx *aero.Context) string {
|
||||
id := ctx.Get("id")
|
||||
|
||||
// Is the user allowed to delete?
|
||||
user := utils.GetUser(ctx)
|
||||
|
||||
if user == nil || (user.Role != "editor" && user.Role != "admin") {
|
||||
return ctx.Error(http.StatusUnauthorized, "Not authorized", nil)
|
||||
}
|
||||
|
||||
// Check that the anime really exists
|
||||
kitsuAnimeObj, err := arn.Kitsu.Get("Anime", id)
|
||||
|
||||
if kitsuAnimeObj == nil {
|
||||
return ctx.Error(http.StatusNotFound, "Kitsu anime not found", err)
|
||||
}
|
||||
|
||||
// Add to deleted IDs list
|
||||
deletedKitsuAnime, err := arn.GetIDList("deleted kitsu anime")
|
||||
|
||||
if err != nil {
|
||||
deletedKitsuAnime = arn.IDList{}
|
||||
}
|
||||
|
||||
deletedKitsuAnime = deletedKitsuAnime.Append(id)
|
||||
|
||||
// Save in database
|
||||
arn.DB.Set("IDList", "deleted kitsu anime", &deletedKitsuAnime)
|
||||
|
||||
return ""
|
||||
}
|
Reference in New Issue
Block a user