updated bruno files

This commit is contained in:
John O'Keefe 2024-07-24 09:15:52 -04:00
parent d7233a52ba
commit dcf7322b0c
9 changed files with 428 additions and 85 deletions

View File

@ -1,6 +1,7 @@
package main
package AniList
import (
"AniTrack"
"bytes"
"context"
"encoding/json"
@ -15,25 +16,84 @@ import (
"sync"
)
type JWT struct {
type AniListJWT struct {
TokenType string `json:"token_type"`
ExpiresIn int `json:"expires_in"`
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
}
var jwt JWT
type AniListUser struct {
Data struct {
Viewer struct {
ID int `json:"id"`
Name string `json:"name"`
} `json:"Viewer"`
} `json:"data"`
}
func AniListQuery(body interface{}, login bool) interface{} {
type AniListCurrentUserWatchList struct {
Data struct {
Page struct {
PageInfo struct {
Total int `json:"total"`
PerPage int `json:"perPage"`
CurrentPage int `json:"currentPage"`
LastPage int `json:"lastPage"`
HasNextPage bool `json:"hasNextPage"`
} `json:"pageInfo"`
MediaList []struct {
ID int `json:"id"`
MediaID int `json:"mediaId"`
Media struct {
ID int `json:"id"`
IDMal int `json:"idMal"`
Title struct {
Romaji string `json:"romaji"`
English string `json:"english"`
Native string `json:"native"`
} `json:"title"`
Description string `json:"description"`
CoverImage struct {
Large string `json:"large"`
} `json:"coverImage"`
Season string `json:"season"`
SeasonYear int `json:"seasonYear"`
Episodes int `json:"episodes"`
} `json:"media"`
Status string `json:"status"`
Notes string `json:"notes"`
Progress int `json:"progress"`
Score int `json:"score"`
Repeat int `json:"repeat"`
User struct {
Statistics struct {
Anime struct {
Count int `json:"count"`
Statuses []struct {
Status string `json:"status"`
Count int `json:"count"`
} `json:"statuses"`
} `json:"anime"`
} `json:"statistics"`
} `json:"user"`
} `json:"mediaList"`
} `json:"Page"`
} `json:"data"`
}
var jwt AniListJWT
func AniListQuery(body interface{}, login bool) (json.RawMessage, string) {
reader, _ := json.Marshal(body)
response, err := http.NewRequest("POST", "https://graphql.anilist.co", bytes.NewBuffer(reader))
if err != nil {
log.Printf("Failed at response, %s\n", err)
}
if login && (JWT{}) != jwt {
if login && (AniListJWT{}) != jwt {
response.Header.Add("Authorization", "Bearer "+jwt.AccessToken)
} else if login {
return "Please login to AniList to make this request"
return nil, "Please login to AniList to make this request"
}
response.Header.Add("Content-Type", "application/json")
response.Header.Add("Accept", "application/json")
@ -48,16 +108,17 @@ func AniListQuery(body interface{}, login bool) interface{} {
returnedBody, err := io.ReadAll(res.Body)
var post interface{}
err = json.Unmarshal(returnedBody, &post)
if err != nil {
log.Printf("Failed at unmarshal, %s\n", err)
}
return post
//var post interface{}
//err = json.Unmarshal(returnedBody, &post)
//if err != nil {
// log.Printf("Failed at unmarshal, %s\n", err)
//}
//
//return post
return returnedBody, ""
}
func (a *App) GetAniListItem(aniId int) any {
func (a *main.App) GetAniListItem(aniId int) any {
type Variables struct {
ID int `json:"id"`
ListType string `json:"listType"`
@ -101,10 +162,18 @@ func (a *App) GetAniListItem(aniId int) any {
},
}
return AniListQuery(body, false)
returnedBody, _ := AniListQuery(body, false)
var post interface{}
err := json.Unmarshal(returnedBody, &post)
if err != nil {
log.Printf("Failed at unmarshal, %s\n", err)
}
return post
}
func (a *App) AniListSearch(query string) any {
func (a *main.App) AniListSearch(query string) any {
type Variables struct {
Search string `json:"search"`
ListType string `json:"listType"`
@ -143,12 +212,20 @@ func (a *App) AniListSearch(query string) any {
ListType: "ANIME",
},
}
return AniListQuery(body, false)
returnedBody, _ := AniListQuery(body, false)
var post interface{}
err := json.Unmarshal(returnedBody, &post)
if err != nil {
log.Printf("Failed at unmarshal, %s\n", err)
}
return post
}
var ctxShutdown, cancel = context.WithCancel(context.Background())
func (a *App) AniListLogin() {
func (a *main.App) AniListLogin() {
getAniListCodeUrl := "https://anilist.co/api/v2/oauth/authorize?client_id=" + os.Getenv("ANILIST_APP_ID") + "&redirect_uri=" + os.Getenv("ANILIST_CALLBACK_URI") + "&response_type=code"
runtime.BrowserOpenURL(a.ctx, getAniListCodeUrl)
@ -195,7 +272,7 @@ func handleAniListCallback(wg *sync.WaitGroup) {
}()
}
func getAniListAuthorizationToken(content string) JWT {
func getAniListAuthorizationToken(content string) AniListJWT {
apiUrl := "https://anilist.co/api/v2/oauth/token"
resource := "/api/v2/oauth/token"
data := url.Values{}
@ -227,7 +304,7 @@ func getAniListAuthorizationToken(content string) JWT {
returnedBody, err := io.ReadAll(res.Body)
var post JWT
var post AniListJWT
err = json.Unmarshal(returnedBody, &post)
if err != nil {
log.Printf("Failed at unmarshal, %s\n", err)
@ -235,3 +312,38 @@ func getAniListAuthorizationToken(content string) JWT {
return post
}
func (a *main.App) GetAniListLoggedInUserId() AniListUser {
if (AniListJWT{}) == jwt {
a.AniListLogin()
}
body := struct {
Query string `json:"query"`
}{
Query: `
query {
Viewer {
id
name
}
}
`,
}
user, _ := AniListQuery(body, true)
var post AniListUser
err := json.Unmarshal(user, &post)
if err != nil {
log.Printf("Failed at unmarshal, %s\n", err)
}
fmt.Println("UserInfo: ", post)
return post
}
func (a *main.App) GetAniListUserWatchingList() {
}

1
AniListTypes.go Normal file
View File

@ -0,0 +1 @@
package main

1
AniListUserFunctions.go Normal file
View File

@ -0,0 +1 @@
package main

View File

@ -29,16 +29,6 @@ body:graphql {
coverImage {
large
}
tags {
id
name
description
category
rank
isGeneralSpoiler
isMediaSpoiler
isAdult
}
}
}
@ -50,3 +40,19 @@ body:graphql:vars {
"listType": "ANIME"
}
}
docs {
Title
Image
Description
Episodes
Status
Season
External & Streaming Links
}

View File

@ -0,0 +1,103 @@
meta {
name: AniList MediaList User Query
type: graphql
seq: 6
}
post {
url: https://graphql.anilist.co
body: graphql
auth: none
}
headers {
Content-Type: "application/json"
Accept: "application/json"
}
body:graphql {
# Write your query or mutation here
query(
$page: Int
$perPage: Int
$userId: Int
$listType: MediaType
$status: MediaListStatus
) {
Page(page: $page, perPage: $perPage) {
pageInfo {
total
perPage
currentPage
lastPage
hasNextPage
}
mediaList(userId: $userId, type: $listType, status: $status) {
id
mediaId
userId
media {
id
idMal
title {
romaji
english
native
}
description
coverImage {
large
}
season
seasonYear
episodes
}
status
notes
progress
score
repeat
user {
id
statistics {
anime {
count
statuses {
status
count
}
}
}
}
}
}
}
}
body:graphql:vars {
{
"page": 1,
"perPage": 20,
"userId": 413504,
"listType": "ANIME",
"status": "CURRENT"
}
}
docs {
Title
Image
Description
Episodes
Status
Season
External & Streaming Links
User Stuff Per Item
Status
Score
Episode Progress
Total Rewatches
Notes
}

View File

@ -0,0 +1,28 @@
meta {
name: AniList MediaList User
type: http
seq: 5
}
post {
url: https://graphql.anilist.co
body: none
auth: none
}
docs {
Title
Image
Description
Episodes
Status
Season
External & Streaming Links
User Stuff Per Item
Status
Score
Episode Progress
Total Rewatches
Notes
}

View File

@ -1,55 +0,0 @@
export interface AniListItem {
data: {
Media: {
id: number,
idMal: number,
title: {
romaji: string,
english: string,
},
description: string,
coverImage: {
medium: string,
large: string,
extraLarge: string,
color: string,
},
tags: [{
id: number,
name: string,
description: string,
category: string,
rank: number,
isGeneralSpoiler: boolean,
isMediaSpoiler: boolean,
isAdult: boolean
}]
}
}
}
export interface AniSearchList {
data: {
Page: {
pageInfo: {
total: number,
currentPage: number,
lastPage: number,
hasNextPage: boolean,
perPage: number
},
media: [{
id: number,
idMal: number,
title: {
romaji: string,
english: string,
},
coverImage: {
extraLarge: string,
color: string,
},
}],
},
}
}

View File

@ -0,0 +1,147 @@
export interface AniListItem {
data: {
Media: {
id: number,
idMal: number,
title: {
romaji: string,
english: string,
},
description: string,
coverImage: {
medium: string,
large: string,
extraLarge: string,
color: string,
},
tags: [{
id: number,
name: string,
description: string,
category: string,
rank: number,
isGeneralSpoiler: boolean,
isMediaSpoiler: boolean,
isAdult: boolean
}]
}
}
}
export interface AniSearchList {
data: {
Page: {
pageInfo: {
total: number,
currentPage: number,
lastPage: number,
hasNextPage: boolean,
perPage: number
},
media: [{
id: number,
idMal: number,
title: {
romaji: string,
english: string,
native: string,
},
coverImage: {
extraLarge: string,
color: string,
},
}],
},
}
}
export interface AniListUser {
"data": {
"Viewer": {
id: number,
name: string,
}
}
}
export interface AniListCurrentUserWatchList {
data: Data;
}
export interface Data {
Page: Page;
}
export interface Page {
pageInfo: PageInfo;
mediaList: MediaList[];
}
export interface MediaList {
id: number;
mediaId: number;
userId: number;
media: Media;
status: StatusEnum;
notes: string | null;
progress: number;
score: number;
repeat: number;
user: User;
}
export interface Media {
id: number;
idMal: number;
title: Title;
description: string;
coverImage: CoverImage;
season: string;
seasonYear: number;
episodes: number;
}
export interface CoverImage {
large: string;
}
export interface Title {
romaji: string | null;
english: string | null;
native: string;
}
export enum StatusEnum {
Completed = "COMPLETED",
Current = "CURRENT",
Dropped = "DROPPED",
Planning = "PLANNING",
Repeating = "REPEATING",
}
export interface User {
id: number;
statistics: Statistics;
}
export interface Statistics {
anime: Anime;
}
export interface Anime {
count: number;
statuses: StatusElement[];
}
export interface StatusElement {
status: StatusEnum;
count: number;
}
export interface PageInfo {
total: number;
perPage: number;
currentPage: number;
lastPage: number;
hasNextPage: boolean;
}