MCPcopy Index your code
hub / github.com/Dispatcharr/Dispatcharr / getChannels

Method getChannels

frontend/src/api.js:218–258  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

216 }
217
218 static async getChannels() {
219 try {
220 // Paginate through channels to avoid heavy single response
221 const pageSize = 200;
222 const allChannels = [];
223
224 // Get first page to get total results count
225 const data = await request(
226 `${host}/api/channels/channels/?page=1&page_size=${pageSize}`
227 );
228
229 // Backward compatibility: if endpoint returns an array (legacy), just return it
230 if (Array.isArray(data)) {
231 return data;
232 }
233
234 allChannels.concat(Array.isArray(data?.results) ? data.results : []);
235
236 const totalPages = Math.max(1, Math.ceil(data.count / pageSize)) - 1;
237 const apiCalls = [];
238 for (let page = 2; page <= totalPages; page++) {
239 apiCalls.push(
240 new Promise(async (resolve) => {
241 const response = await request(
242 `${host}/api/channels/channels/?page=${page}&page_size=${pageSize}`
243 );
244
245 return resolve(
246 Array.isArray(response?.results) ? response.results : []
247 );
248 })
249 );
250 }
251
252 const allResults = await Limiter.all(5, apiCalls);
253
254 return allResults;
255 } catch (e) {
256 errorNotification('Failed to retrieve channels', e);
257 }
258 }
259
260 /**
261 * Retrieve a lightweight summary of channels (id, name, logo_id,

Callers 1

channels.jsxFile · 0.80

Calls 2

requestFunction · 0.85
errorNotificationFunction · 0.85

Tested by

no test coverage detected