-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-animepahe-pagination.js
More file actions
85 lines (69 loc) · 3.1 KB
/
test-animepahe-pagination.js
File metadata and controls
85 lines (69 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Test AnimePahe pagination fix
const ANIMEPAHE_BASE_URL = 'https://animepahe-api-iota.vercel.app';
async function testAnimePahePagination() {
try {
console.log('Testing AnimePahe Pagination Fix...\n');
// Test with One Piece
const searchQuery = 'One Piece';
console.log(`1. Searching for "${searchQuery}"...`);
const searchResponse = await fetch(
`${ANIMEPAHE_BASE_URL}/api/search?q=${encodeURIComponent(searchQuery)}`
);
const searchData = await searchResponse.json();
if (!searchData.data || searchData.data.length === 0) {
console.log('No results found');
return;
}
const anime = searchData.data[0];
console.log(`Found: ${anime.title}`);
console.log(`Total episodes from search: ${anime.episodes}`);
console.log(`Session: ${anime.session}\n`);
// Test episodes endpoint
console.log('2. Fetching first page of episodes...');
const episodesResponse = await fetch(
`${ANIMEPAHE_BASE_URL}/api/${anime.session}/releases?sort=episode_asc&page=1`
);
const episodesData = await episodesResponse.json();
const paginationInfo = episodesData.paginationInfo || {};
console.log('Pagination Info:', JSON.stringify(paginationInfo, null, 2));
// Calculate pages
const perPage = paginationInfo.perPage || 30;
const totalFromSearch = anime.episodes;
const totalFromAPI = paginationInfo.total;
console.log(`\n3. Pagination calculation:`);
console.log(` Episodes from search: ${totalFromSearch}`);
console.log(` Episodes from API: ${totalFromAPI}`);
console.log(` Per page: ${perPage}`);
const totalToUse = totalFromAPI || totalFromSearch || 0;
const calculatedPages = Math.ceil(totalToUse / perPage);
const apiLastPage = paginationInfo.lastPage;
console.log(` Calculated pages: ${calculatedPages}`);
console.log(` API last_page: ${apiLastPage}`);
console.log(` Pages to fetch: ${Math.max(calculatedPages, apiLastPage)}`);
// Test fetching a few more pages
console.log(`\n4. Testing page 2...`);
const page2Response = await fetch(
`${ANIMEPAHE_BASE_URL}/api/${anime.session}/releases?sort=episode_asc&page=2`
);
const page2Data = await page2Response.json();
console.log(` Page 2 episodes: ${page2Data.data?.length || 0}`);
if (calculatedPages > 2) {
console.log(`\n5. Testing last page (${calculatedPages})...`);
const lastPageResponse = await fetch(
`${ANIMEPAHE_BASE_URL}/api/${anime.session}/releases?sort=episode_asc&page=${calculatedPages}`
);
const lastPageData = await lastPageResponse.json();
console.log(` Last page episodes: ${lastPageData.data?.length || 0}`);
console.log(` Last page structure:`, JSON.stringify({
total: lastPageData.total,
current_page: lastPageData.current_page,
last_page: lastPageData.last_page,
data_length: lastPageData.data?.length
}, null, 2));
}
console.log('\n✅ Test complete!');
} catch (error) {
console.error('Error:', error);
}
}
testAnimePahePagination();