Added deletion to Kitsu imports
This commit is contained in:
parent
9eae7ebce5
commit
8cb44131cf
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 ""
|
||||
}
|
@ -14,9 +14,14 @@ import (
|
||||
func NewKitsuAnime(ctx *aero.Context) string {
|
||||
user := utils.GetUser(ctx)
|
||||
finder := arn.NewAnimeFinder("kitsu/anime")
|
||||
deletedIDs, err := arn.GetIDList("deleted kitsu anime")
|
||||
|
||||
if err != nil {
|
||||
deletedIDs = arn.IDList{}
|
||||
}
|
||||
|
||||
animes := arn.FilterKitsuAnime(func(anime *kitsu.Anime) bool {
|
||||
return finder.GetAnime(anime.ID) == nil
|
||||
return finder.GetAnime(anime.ID) == nil && !arn.Contains(deletedIDs, anime.ID)
|
||||
})
|
||||
|
||||
sort.Slice(animes, func(i, j int) bool {
|
||||
|
@ -28,6 +28,9 @@ component NewKitsuAnime(animes []*kitsu.Anime, url string, user *arn.User)
|
||||
if len(anime.Attributes.StartDate) >= 4
|
||||
span= anime.Attributes.StartDate[:4]
|
||||
td
|
||||
button.action(data-action="importKitsuAnime", data-trigger="click", data-id=anime.ID)
|
||||
Icon("download")
|
||||
span Import
|
||||
.buttons
|
||||
button.action(data-action="importKitsuAnime", data-trigger="click", data-id=anime.ID)
|
||||
RawIcon("download")
|
||||
|
||||
button.action(data-action="deleteKitsuAnime", data-trigger="click", data-id=anime.ID)
|
||||
RawIcon("trash")
|
@ -266,6 +266,7 @@ func Configure(app *aero.Application) {
|
||||
|
||||
// Import anime
|
||||
app.Post("/api/import/kitsu/anime/:id", animeimport.Kitsu)
|
||||
app.Post("/api/delete/kitsu/anime/:id", animeimport.DeleteKitsu)
|
||||
|
||||
// Upload
|
||||
app.Post("/api/upload/avatar", upload.Avatar)
|
||||
|
@ -23,6 +23,10 @@ export function newAnimeDiffIgnore(arn: AnimeNotifier, button: HTMLButtonElement
|
||||
|
||||
// Import Kitsu anime
|
||||
export async function importKitsuAnime(arn: AnimeNotifier, button: HTMLButtonElement) {
|
||||
if(!confirm("Are you sure you want to import this anime?")) {
|
||||
return
|
||||
}
|
||||
|
||||
let newTab = window.open()
|
||||
let animeId = button.dataset.id
|
||||
let response = await fetch(`/api/import/kitsu/anime/${animeId}`, {
|
||||
@ -38,6 +42,17 @@ export async function importKitsuAnime(arn: AnimeNotifier, button: HTMLButtonEle
|
||||
}
|
||||
}
|
||||
|
||||
// Delete Kitsu anime
|
||||
export async function deleteKitsuAnime(arn: AnimeNotifier, button: HTMLButtonElement) {
|
||||
if(!confirm("Are you sure you want to delete this anime?")) {
|
||||
return
|
||||
}
|
||||
|
||||
let animeId = button.dataset.id
|
||||
await arn.post(`/api/delete/kitsu/anime/${animeId}`)
|
||||
arn.reloadContent()
|
||||
}
|
||||
|
||||
// Multi-search anime
|
||||
export async function multiSearchAnime(arn: AnimeNotifier, textarea: HTMLTextAreaElement) {
|
||||
let results = document.getElementById("multi-search-anime") as HTMLDivElement
|
||||
|
@ -804,12 +804,12 @@ export default class AnimeNotifier {
|
||||
return Diff.innerHTML(element, html)
|
||||
}
|
||||
|
||||
post(url: string, body: any) {
|
||||
post(url: string, body?: any) {
|
||||
if(this.isLoading) {
|
||||
return Promise.resolve(null)
|
||||
}
|
||||
|
||||
if(typeof body !== "string") {
|
||||
if(body !== undefined && typeof body !== "string") {
|
||||
body = JSON.stringify(body)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user