Skip to content

Commit

Permalink
feat: show custom lists
Browse files Browse the repository at this point in the history
  • Loading branch information
5rahim committed Jun 7, 2024
1 parent bbab2c1 commit caa7b65
Show file tree
Hide file tree
Showing 15 changed files with 306 additions and 39 deletions.
31 changes: 31 additions & 0 deletions codegen/generated/handlers.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,37 @@
"returnTypescriptType": "AL_AnimeCollection"
}
},
{
"name": "HandleGetRawAnimeCollection",
"trimmedName": "GetRawAnimeCollection",
"comments": [
"HandleGetRawAnimeCollection",
"",
"\t@summary returns the user's AniList anime collection without filtering out custom lists.",
"\t@desc Calling GET will return the cached anime collection.",
"\t@returns anilist.AnimeCollection",
"\t@route /api/v1/anilist/collection/raw [GET,POST]",
""
],
"filepath": "internal/handlers/anilist.go",
"filename": "anilist.go",
"api": {
"summary": "returns the user's AniList anime collection without filtering out custom lists.",
"descriptions": [
"Calling GET will return the cached anime collection."
],
"endpoint": "/api/v1/anilist/collection/raw",
"methods": [
"GET",
"POST"
],
"params": [],
"bodyFields": [],
"returns": "anilist.AnimeCollection",
"returnGoType": "anilist.AnimeCollection",
"returnTypescriptType": "AL_AnimeCollection"
}
},
{
"name": "HandleEditAnilistListEntry",
"trimmedName": "EditAnilistListEntry",
Expand Down
66 changes: 61 additions & 5 deletions codegen/generated/public_structs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3557,6 +3557,24 @@
"public": true,
"comments": []
},
{
"name": "Name",
"jsonName": "name",
"goType": "string",
"typescriptType": "string",
"required": false,
"public": true,
"comments": []
},
{
"name": "IsCustomList",
"jsonName": "isCustomList",
"goType": "bool",
"typescriptType": "boolean",
"required": false,
"public": true,
"comments": []
},
{
"name": "Entries",
"jsonName": "entries",
Expand Down Expand Up @@ -5936,6 +5954,24 @@
"public": true,
"comments": []
},
{
"name": "Name",
"jsonName": "name",
"goType": "string",
"typescriptType": "string",
"required": false,
"public": true,
"comments": []
},
{
"name": "IsCustomList",
"jsonName": "isCustomList",
"goType": "bool",
"typescriptType": "boolean",
"required": false,
"public": true,
"comments": []
},
{
"name": "Entries",
"jsonName": "entries",
Expand Down Expand Up @@ -24265,7 +24301,19 @@
"required": false,
"public": false,
"comments": [
" should be retrieved with Get funcs in routes"
" TODO: Rename to animeCollection"
]
},
{
"name": "rawAnimeCollection",
"jsonName": "rawAnimeCollection",
"goType": "anilist.AnimeCollection",
"typescriptType": "AL_AnimeCollection",
"usedStructName": "anilist.AnimeCollection",
"required": false,
"public": false,
"comments": [
" (retains custom lists)"
]
},
{
Expand All @@ -24276,8 +24324,18 @@
"usedStructName": "anilist.MangaCollection",
"required": false,
"public": false,
"comments": []
},
{
"name": "rawMangaCollection",
"jsonName": "rawMangaCollection",
"goType": "anilist.MangaCollection",
"typescriptType": "AL_MangaCollection",
"usedStructName": "anilist.MangaCollection",
"required": false,
"public": false,
"comments": [
" should be retrieved with Get funcs in routes"
" (retains custom lists)"
]
},
{
Expand All @@ -24288,9 +24346,7 @@
"usedStructName": "models.Account",
"required": false,
"public": false,
"comments": [
" should be retrieved with Get funcs in routes"
]
"comments": []
},
{
"name": "WSEventManager",
Expand Down
40 changes: 36 additions & 4 deletions internal/api/anilist/client_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions internal/api/anilist/queries/manga.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ query MangaCollection ($userName: String) {
MediaListCollection(userName: $userName, type: MANGA) {
lists {
status
name
isCustomList
entries {
id
score(format: POINT_100)
Expand Down
2 changes: 2 additions & 0 deletions internal/api/anilist/queries/media.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ query AnimeCollection ($userName: String) {
MediaListCollection(userName: $userName, type: ANIME) {
lists {
status
name
isCustomList
entries {
id
score(format: POINT_100)
Expand Down
8 changes: 5 additions & 3 deletions internal/core/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ type (
AnilistClientWrapper anilist.ClientWrapperInterface
NyaaSearchCache *nyaa.SearchCache
AnimeToshoSearchCache *animetosho.SearchCache
anilistCollection *anilist.AnimeCollection // should be retrieved with Get funcs in routes
mangaCollection *anilist.MangaCollection // should be retrieved with Get funcs in routes
account *models.Account // should be retrieved with Get funcs in routes
anilistCollection *anilist.AnimeCollection // TODO: Rename to animeCollection
rawAnimeCollection *anilist.AnimeCollection // (retains custom lists)
mangaCollection *anilist.MangaCollection
rawMangaCollection *anilist.MangaCollection // (retains custom lists)
account *models.Account
WSEventManager *events.WSEventManager
ListSyncCache *listsync.Cache
AutoDownloader *autodownloader.AutoDownloader
Expand Down
52 changes: 51 additions & 1 deletion internal/core/app_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ func (a *App) GetAnilistCollection(bypassCache bool) (*anilist.AnimeCollection,

}

// GetRawAnilistCollection is the same as GetAnilistCollection but returns the raw collection that includes custom lists
func (a *App) GetRawAnilistCollection(bypassCache bool) (*anilist.AnimeCollection, error) {

// Get Anilist Collection from App if it exists
if !bypassCache && a.rawAnimeCollection != nil {
return a.rawAnimeCollection, nil
}

_, err := a.RefreshAnilistCollection()
if err != nil {
return nil, err
}

return a.rawAnimeCollection, nil

}

// RefreshAnilistCollection queries Anilist for the user's collection
func (a *App) RefreshAnilistCollection() (*anilist.AnimeCollection, error) {

Expand All @@ -39,7 +56,16 @@ func (a *App) RefreshAnilistCollection() (*anilist.AnimeCollection, error) {
return nil, err
}

// Remove lists with no status
// Save the raw collection to App (retains the lists with no status)
collectionCopy := *collection
a.rawAnimeCollection = &collectionCopy
listCollectionCopy := *collection.MediaListCollection
a.rawAnimeCollection.MediaListCollection = &listCollectionCopy
listsCopy := make([]*anilist.AnimeCollection_MediaListCollection_Lists, len(collection.MediaListCollection.Lists))
copy(listsCopy, collection.MediaListCollection.Lists)
a.rawAnimeCollection.MediaListCollection.Lists = listsCopy

// Remove lists with no status (custom lists)
collection.MediaListCollection.Lists = lo.Filter(collection.MediaListCollection.Lists, func(list *anilist.AnimeCollection_MediaListCollection_Lists, _ int) bool {
return list.Status != nil
})
Expand Down Expand Up @@ -93,6 +119,22 @@ func (a *App) GetMangaCollection(bypassCache bool) (*anilist.MangaCollection, er

}

// GetRawMangaCollection does not exclude custom lists
func (a *App) GetRawMangaCollection(bypassCache bool) (*anilist.MangaCollection, error) {

// Get Anilist Collection from App if it exists
if !bypassCache && a.mangaCollection != nil {
return a.mangaCollection, nil
}

_, err := a.RefreshMangaCollection()
if err != nil {
return nil, err
}

return a.rawMangaCollection, nil
}

// RefreshMangaCollection queries Anilist for the user's manga collection
func (a *App) RefreshMangaCollection() (*anilist.MangaCollection, error) {

Expand All @@ -107,6 +149,14 @@ func (a *App) RefreshMangaCollection() (*anilist.MangaCollection, error) {
return nil, err
}

collectionCopy := *collection
a.rawMangaCollection = &collectionCopy
listCollectionCopy := *collection.MediaListCollection
a.rawMangaCollection.MediaListCollection = &listCollectionCopy
listsCopy := make([]*anilist.MangaCollection_MediaListCollection_Lists, len(collection.MediaListCollection.Lists))
copy(listsCopy, collection.MediaListCollection.Lists)
a.rawMangaCollection.MediaListCollection.Lists = listsCopy

// Remove lists with no status
collection.MediaListCollection.Lists = lo.Filter(collection.MediaListCollection.Lists, func(list *anilist.MangaList, _ int) bool {
return list.Status != nil
Expand Down
19 changes: 19 additions & 0 deletions internal/handlers/anilist.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ func HandleGetAnilistCollection(c *RouteCtx) error {
return c.RespondWithData(anilistCollection)
}

// HandleGetRawAnimeCollection
//
// @summary returns the user's AniList anime collection without filtering out custom lists.
// @desc Calling GET will return the cached anime collection.
// @returns anilist.AnimeCollection
// @route /api/v1/anilist/collection/raw [GET,POST]
func HandleGetRawAnimeCollection(c *RouteCtx) error {

bypassCache := c.Fiber.Method() == "POST"

// Get the user's anilist collection
anilistCollection, err := c.App.GetRawAnilistCollection(bypassCache)
if err != nil {
return c.RespondWithError(err)
}

return c.RespondWithData(anilistCollection)
}

// HandleEditAnilistListEntry
//
// @summary updates the user's list entry on Anilist.
Expand Down
4 changes: 3 additions & 1 deletion internal/handlers/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@ func InitRoutes(app *core.App, fiberApp *fiber.App) {
v1Anilist := v1.Group("/anilist")

v1Anilist.Get("/collection", makeHandler(app, HandleGetAnilistCollection))

v1Anilist.Post("/collection", makeHandler(app, HandleGetAnilistCollection))

v1Anilist.Get("/collection/raw", makeHandler(app, HandleGetRawAnimeCollection))
v1Anilist.Post("/collection/raw", makeHandler(app, HandleGetRawAnimeCollection))

v1Anilist.Get("/media-details/:id", makeHandler(app, HandleGetAnilistMediaDetails))

v1Anilist.Get("/studio-details/:id", makeHandler(app, HandleGetAnilistStudioDetails))
Expand Down
10 changes: 10 additions & 0 deletions seanime-web/src/api/generated/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ export const API_ENDPOINTS = {
methods: ["GET", "POST"],
endpoint: "/api/v1/anilist/collection",
},
/**
* @description
* Route returns the user's AniList anime collection without filtering out custom lists.
* Calling GET will return the cached anime collection.
*/
GetRawAnimeCollection: {
key: "ANILIST-get-raw-anime-collection",
methods: ["GET", "POST"],
endpoint: "/api/v1/anilist/collection/raw",
},
/**
* @description
* Route updates the user's list entry on Anilist.
Expand Down
Loading

0 comments on commit caa7b65

Please sign in to comment.