MCPcopy Index your code
hub / github.com/MALSync/MALSync / checkForFiller

Method checkForFiller

src/pages-sync/syncPage.ts:1356–1403  ·  view source on GitHub ↗
(malid: number, episode: number)

Source from the content-addressed store, hash-verified

1354 }
1355
1356 private async checkForFiller(malid: number, episode: number) {
1357 const page = Math.ceil(episode / 100);
1358
1359 const cacheObj = new Cache(`fillers/${malid}/${page}`, 7 * 24 * 60 * 60 * 1000);
1360
1361 if (!(await cacheObj.hasValueAndIsNotEmpty())) {
1362 const url = `https://api.jikan.moe/v4/anime/${malid}/episodes?page=${page}`;
1363 const request = await api.request.xhr('GET', url).then(async response => {
1364 try {
1365 if (response.status === 200 && response.responseText) {
1366 const data = JSON.parse(response.responseText);
1367 if (data.data && data.data.length) {
1368 return data.data
1369 .map(e => ({
1370 filler: e.filler,
1371 recap: e.recap,
1372 episode_id: e.mal_id, // mal_id is the episode_id in the v4 API very stupid
1373 }))
1374 .filter(e => e.filler || e.recap);
1375 }
1376 }
1377 } catch (e) {
1378 // do nothing.
1379 }
1380 return [];
1381 });
1382 await cacheObj.setValue(request);
1383 }
1384 const episodes = await cacheObj.getValue();
1385
1386 if (episodes && episodes.length) {
1387 const episodeData = episodes.find(e => e.episode_id === episode);
1388 if (episodeData && (episodeData.filler || episodeData.recap)) {
1389 const type = episodeData.filler ? 'filler' : 'recap';
1390 utils.flashConfirm(
1391 api.storage.lang(`filler_${type}_confirm`),
1392 'filler',
1393 () => {
1394 this.openNextEp();
1395 },
1396 () => {
1397 // do nothing.
1398 },
1399 true,
1400 );
1401 }
1402 }
1403 }
1404}

Callers 1

handlePageMethod · 0.95

Calls 6

hasValueAndIsNotEmptyMethod · 0.95
setValueMethod · 0.95
getValueMethod · 0.95
openNextEpMethod · 0.95
xhrMethod · 0.80
langMethod · 0.80

Tested by

no test coverage detected