chore: update Angular cache and TypeScript build info
This commit is contained in:
+42
-21
@@ -10,7 +10,7 @@ const handler = {
|
||||
* @returns {Promise<Array<any>>}
|
||||
*/
|
||||
async search(q, opts) {
|
||||
const { limit = 10 } = opts;
|
||||
const { limit = 10, page = 1 } = opts || {};
|
||||
try {
|
||||
// First, get OAuth token
|
||||
const authResponse = await fetch('https://id.twitch.tv/oauth2/token', {
|
||||
@@ -31,28 +31,49 @@ const handler = {
|
||||
|
||||
const { access_token } = await authResponse.json();
|
||||
|
||||
// Then search streams
|
||||
const response = await fetch(
|
||||
`https://api.twitch.tv/helix/search/channels?` +
|
||||
new URLSearchParams({
|
||||
query: q,
|
||||
first: Math.min(limit, 100).toString()
|
||||
}),
|
||||
{
|
||||
headers: {
|
||||
'Client-ID': process.env.TWITCH_CLIENT_ID,
|
||||
'Authorization': `Bearer ${access_token}`
|
||||
}
|
||||
}
|
||||
);
|
||||
// Then search channels with cursor-based pagination
|
||||
const perPage = Math.min(Math.max(1, Number(limit || 10)), 100);
|
||||
const targetPage = Math.max(1, Number(page || 1));
|
||||
let after = '';
|
||||
let currentPage = 1;
|
||||
let lastData = [];
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Twitch API error: ${response.status}`);
|
||||
while (currentPage <= targetPage) {
|
||||
const params = new URLSearchParams({
|
||||
query: q,
|
||||
first: String(perPage)
|
||||
});
|
||||
if (after) params.set('after', after);
|
||||
|
||||
const response = await fetch(
|
||||
`https://api.twitch.tv/helix/search/channels?` + params.toString(),
|
||||
{
|
||||
headers: {
|
||||
'Client-ID': process.env.TWITCH_CLIENT_ID,
|
||||
'Authorization': `Bearer ${access_token}`
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Twitch API error: ${response.status}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
|
||||
if (currentPage === targetPage) {
|
||||
lastData = Array.isArray(data.data) ? data.data : [];
|
||||
break;
|
||||
}
|
||||
const nextCursor = data?.pagination?.cursor;
|
||||
if (!nextCursor) {
|
||||
lastData = [];
|
||||
break;
|
||||
}
|
||||
after = String(nextCursor);
|
||||
currentPage++;
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
return data.data?.map(item => ({
|
||||
return lastData.map(item => ({
|
||||
title: item.title || item.display_name,
|
||||
id: item.id,
|
||||
url: `https://www.twitch.tv/${item.broadcaster_login}`,
|
||||
@@ -60,7 +81,7 @@ const handler = {
|
||||
uploaderName: item.display_name,
|
||||
type: 'stream',
|
||||
isLive: item.is_live || item.started_at
|
||||
})) || [];
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('Twitch search error:', error);
|
||||
return [];
|
||||
|
||||
Reference in New Issue
Block a user