mirror of
https://github.com/AnimeThemes/animethemes-web.git
synced 2026-07-11 01:24:31 +02:00
fix: Fixed playlists not paginating (#212)
This commit is contained in:
@@ -64,6 +64,10 @@ NEXT_PUBLIC_STAGING=true
|
||||
|
||||
; To enable verbose logging.
|
||||
NEXT_PUBLIC_VERBOSE_LOGS=true
|
||||
|
||||
; Set the page size to fetch when resolving paginated resources.
|
||||
; If not set, 25 will be used.
|
||||
NEXT_PUBLIC_PAGINATION_PAGE_SIZE=10
|
||||
```
|
||||
|
||||
For more information on environment variables see the [Next.js documentation](https://nextjs.org/docs/basic-features/environment-variables).
|
||||
|
||||
@@ -2,7 +2,7 @@ import pLimit from "p-limit";
|
||||
import type { ResolveTree } from "graphql-parse-resolve-info";
|
||||
import { parseResolveInfo } from "graphql-parse-resolve-info";
|
||||
import devLog from "utils/devLog";
|
||||
import { CLIENT_API_URL, SERVER_API_KEY, SERVER_API_URL, AUTH_REFERER } from "utils/config.mjs";
|
||||
import { CLIENT_API_URL, SERVER_API_KEY, SERVER_API_URL, AUTH_REFERER, PAGINATION_PAGE_SIZE } from "utils/config.mjs";
|
||||
import type { GraphQLFieldResolver, GraphQLOutputType, GraphQLResolveInfo } from "graphql";
|
||||
import type { Path } from "graphql/jsutils/Path";
|
||||
import type { IncomingMessage } from "node:http";
|
||||
@@ -303,7 +303,7 @@ export function apiResolver(config: ApiResolverConfig): GraphQLFieldResolver<Rec
|
||||
} else {
|
||||
devLog.info(`Collecting: ${url}`);
|
||||
const results = [];
|
||||
let nextUrl = `${url}${url.includes("?") ? "&" : "?"}page[size]=25`;
|
||||
let nextUrl = `${url}${url.includes("?") ? "&" : "?"}page[size]=${PAGINATION_PAGE_SIZE ?? 25}`;
|
||||
while (nextUrl) {
|
||||
const json = await fetchJson(nextUrl, { headers }) as Record<string, unknown> & { links: { next: string } };
|
||||
context.apiRequests++;
|
||||
|
||||
@@ -99,7 +99,8 @@ const resolvers: IResolvers = {
|
||||
playlistAll: apiResolver({
|
||||
endpoint: (_, { limit, orderBy, orderDesc }) =>
|
||||
`/playlist?sort=${orderDesc ? "-" : ""}${orderBy}&page[size]=${limit}&fields[playlist]=id,name,visibility,tracks_count`,
|
||||
extractor: (result) => result.playlists
|
||||
extractor: (result) => result.playlists,
|
||||
pagination: true,
|
||||
}),
|
||||
me: () => ({}),
|
||||
},
|
||||
@@ -111,6 +112,7 @@ const resolvers: IResolvers = {
|
||||
playlistAll: apiResolver({
|
||||
endpoint: (_, { filterVideoId }) => `/me/playlist?fields[playlist]=id,name,visibility,tracks_count${filterVideoId ? `&filter[track][video_id]=${filterVideoId}` : ``}`,
|
||||
extractor: (result) => result.playlists,
|
||||
pagination: true,
|
||||
}),
|
||||
},
|
||||
Year: {
|
||||
|
||||
@@ -23,7 +23,9 @@ const AUTH_PATH = process.env.NEXT_PUBLIC_AUTH_PATH;
|
||||
|
||||
const STAGING = !!process.env.NEXT_PUBLIC_STAGING;
|
||||
const VERBOSE_LOGS = !!process.env.NEXT_PUBLIC_VERBOSE_LOGS;
|
||||
|
||||
const PAGINATION_PAGE_SIZE = process.env.NEXT_PUBLIC_PAGINATION_PAGE_SIZE
|
||||
? Number(process.env.NEXT_PUBLIC_PAGINATION_PAGE_SIZE)
|
||||
: null;
|
||||
|
||||
function validateConfig() {
|
||||
let isValid = true;
|
||||
@@ -59,5 +61,6 @@ export {
|
||||
STAGING,
|
||||
VERBOSE_LOGS,
|
||||
AUTH_REFERER,
|
||||
PAGINATION_PAGE_SIZE,
|
||||
validateConfig,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user