mirror of
https://github.com/recloudstream/cloudstream-extensions-multilingual.git
synced 2024-08-15 03:15:14 +00:00
Removed some ? and make payload more clear to read
This commit is contained in:
parent
8978e4a0f9
commit
430361602d
1 changed files with 71 additions and 16 deletions
|
@ -39,20 +39,43 @@ class SkillShareProvider : MainAPI() { // all providers must be an instance of M
|
||||||
|
|
||||||
override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse {
|
override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse {
|
||||||
val sortAttribute = request.data
|
val sortAttribute = request.data
|
||||||
if (page == 1)
|
if (page == 1) //reset the cursor to "" if the first page is requested
|
||||||
cursor[sortAttribute] = ""
|
cursor[sortAttribute] = ""
|
||||||
|
|
||||||
val payload=
|
val payload=
|
||||||
"""{ "query": "query GetClassesByType(${'$'}filter: ClassFilters!, ${'$'}pageSize: Int, ${'$'}cursor: String, ${'$'}type: ClassListType!, ${'$'}sortAttribute: ClassListByTypeSortAttribute) { classListByType(type: ${'$'}type, where: ${'$'}filter, first: ${'$'}pageSize, after: ${'$'}cursor, sortAttribute: ${'$'}sortAttribute) { nodes { id title url sku smallCoverUrl largeCoverUrl } } }", "variables": { "type": "TRENDING_CLASSES", "filter": { "subCategory": "", "classLength": [] }, "pageSize": 30, "cursor": "${cursor[sortAttribute]}", "sortAttribute": "$sortAttribute" }, "operationName": "GetClassesByType" }"""
|
"""
|
||||||
|
{
|
||||||
|
"query":"query GetClassesByType(${'$'}filter: ClassFilters!, ${'$'}pageSize: Int, ${'$'}cursor: String, ${'$'}type: ClassListType!, ${'$'}sortAttribute: ClassListByTypeSortAttribute) {
|
||||||
|
classListByType(type: ${'$'}type, where: ${'$'}filter, first: ${'$'}pageSize, after: ${'$'}cursor, sortAttribute: ${'$'}sortAttribute) {
|
||||||
|
nodes {
|
||||||
|
id
|
||||||
|
title
|
||||||
|
url
|
||||||
|
sku
|
||||||
|
smallCoverUrl
|
||||||
|
largeCoverUrl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}",
|
||||||
|
"variables":{
|
||||||
|
"type":"TRENDING_CLASSES",
|
||||||
|
"filter":{
|
||||||
|
"subCategory":"",
|
||||||
|
"classLength":[]
|
||||||
|
},
|
||||||
|
"pageSize":30,
|
||||||
|
"cursor":"${cursor[sortAttribute]}",
|
||||||
|
"sortAttribute":"$sortAttribute"
|
||||||
|
},
|
||||||
|
"operationName":"GetClassesByType"
|
||||||
|
}
|
||||||
|
""".replace(Regex("\n")," ")
|
||||||
|
|
||||||
val responseBody = queryMovieApi(payload)
|
val responseBody = queryMovieApi(payload)
|
||||||
val parsedJson = parseJson<ApiData>(responseBody).data!!.classListByType!!.nodes
|
val parsedJson = parseJson<ApiData>(responseBody).data.classListByType.nodes
|
||||||
val home = parsedJson.map {
|
val home = parsedJson.map {
|
||||||
it.toSearchResult()
|
it.toSearchResult()
|
||||||
}
|
}
|
||||||
home.let {
|
cursor[sortAttribute] = parsedJson.lastOrNull()?.id ?: "" //set the right cursor for the nextPage to work
|
||||||
cursor[sortAttribute] =
|
|
||||||
parsedJson.last().id.toString()
|
|
||||||
}
|
|
||||||
return newHomePageResponse(
|
return newHomePageResponse(
|
||||||
arrayListOf(HomePageList(request.name, home, isHorizontalImages = true)),
|
arrayListOf(HomePageList(request.name, home, isHorizontalImages = true)),
|
||||||
hasNext = home.isNotEmpty(),
|
hasNext = home.isNotEmpty(),
|
||||||
|
@ -61,10 +84,42 @@ class SkillShareProvider : MainAPI() { // all providers must be an instance of M
|
||||||
|
|
||||||
override suspend fun search(query: String): List<SearchResponse> {
|
override suspend fun search(query: String): List<SearchResponse> {
|
||||||
val payload =
|
val payload =
|
||||||
"""{"query":"fragment ClassFields on Class {\n id\n\tsmallCoverUrl\n largeCoverUrl\n sku\n title\n url\n}\n\nquery GetClassesQuery(${"$"}query: String!, ${"$"}where: SearchFilters!, ${"$"}after: String!, ${"$"}first: Int!) {\n search(query: ${"$"}query, where: ${"$"}where, analyticsTags: [\"src:browser\", \"src:browser:search\"], after: ${"$"}after, first: ${"$"}first) {\n edges {\n node {\n ...ClassFields\n }\n }\n }\n}\n","variables":{"query":"$query","where":{"level":["ALL_LEVELS","BEGINNER","INTERMEDIATE","ADVANCED"]},"after":"-1","first":30},"operationName":"GetClassesQuery"}"""
|
"""
|
||||||
|
{
|
||||||
|
"query":"fragment ClassFields on Class {
|
||||||
|
id
|
||||||
|
smallCoverUrl
|
||||||
|
largeCoverUrl
|
||||||
|
sku
|
||||||
|
title
|
||||||
|
url
|
||||||
|
}
|
||||||
|
|
||||||
|
query GetClassesQuery(${"$"}query: String!, ${"$"}where: SearchFilters!, ${"$"}after: String!, ${"$"}first: Int!) {
|
||||||
|
search(query: ${"$"}query, where: ${"$"}where, analyticsTags: [\"src:browser\", \"src:browser:search\"], after: ${"$"}after, first: ${"$"}first) {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
...ClassFields
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}",
|
||||||
|
"variables":{
|
||||||
|
"query":"$query",
|
||||||
|
"where":{
|
||||||
|
"level":
|
||||||
|
["ALL_LEVELS","BEGINNER","INTERMEDIATE","ADVANCED"]
|
||||||
|
},
|
||||||
|
"after":"-1",
|
||||||
|
"first":30
|
||||||
|
},
|
||||||
|
"operationName":"GetClassesQuery"
|
||||||
|
}
|
||||||
|
""".replace(Regex("\n")," ")
|
||||||
|
|
||||||
val responseBody = queryMovieApi(payload)
|
val responseBody = queryMovieApi(payload)
|
||||||
val home = parseJson<SearchApiData>(responseBody).data!!.search!!.edges.map {
|
val home = parseJson<SearchApiData>(responseBody).data.search.edges.map {
|
||||||
it.node!!.toSearchResult()
|
it.node.toSearchResult()
|
||||||
}
|
}
|
||||||
return home
|
return home
|
||||||
}
|
}
|
||||||
|
@ -139,19 +194,19 @@ class SkillShareProvider : MainAPI() { // all providers must be an instance of M
|
||||||
|
|
||||||
data class ApiClassListByType( //mainpage
|
data class ApiClassListByType( //mainpage
|
||||||
|
|
||||||
@JsonProperty("classListByType") var classListByType: ApiNodes? = ApiNodes()
|
@JsonProperty("classListByType") var classListByType: ApiNodes = ApiNodes()
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
data class ApiData( //mainpage
|
data class ApiData( //mainpage
|
||||||
|
|
||||||
@JsonProperty("data") var data: ApiClassListByType? = ApiClassListByType()
|
@JsonProperty("data") var data: ApiClassListByType = ApiClassListByType()
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
data class SearchApiNodes( //search
|
data class SearchApiNodes( //search
|
||||||
|
|
||||||
@JsonProperty("node") var node: ApiNode? = ApiNode()
|
@JsonProperty("node") var node: ApiNode = ApiNode()
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -163,13 +218,13 @@ class SkillShareProvider : MainAPI() { // all providers must be an instance of M
|
||||||
|
|
||||||
data class SearchApiSearch( //search
|
data class SearchApiSearch( //search
|
||||||
|
|
||||||
@JsonProperty("search") var search: SearchApiEdges? = SearchApiEdges()
|
@JsonProperty("search") var search: SearchApiEdges = SearchApiEdges()
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
data class SearchApiData( //search
|
data class SearchApiData( //search
|
||||||
|
|
||||||
@JsonProperty("data") var data: SearchApiSearch? = SearchApiSearch()
|
@JsonProperty("data") var data: SearchApiSearch = SearchApiSearch()
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue