Noname968 / airin

Watch Anime Without Interruptions! Enjoy Ad-Free Streaming and AniList Integration only on Airin!
https://aniplaynow.live
GNU General Public License v3.0
64 stars 31 forks source link

How To Setup .env Consumet api?? #4

Closed Brent001 closed 4 months ago

Brent001 commented 4 months ago

Anime Episodes Does not load in local deployment

Error fetching episode history by epid Error: Failed to get Episode at w (C:\Users\HP\Documents\Code\aniplay-2.0.4.next\server\app\anime\watch[[...watchid]]\page.js:1:194439) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async V (C:\Users\HP\Documents\Code\aniplay-2.0.4.next\server\app\anime\watch[[...watchid]]\page.js:1:195654) Error fetching episode history by epid Error: Failed to get Episode at w (C:\Users\HP\Documents\Code\aniplay-2.0.4.next\server\app\anime\watch[[...watchid]]\page.js:1:194439) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async V (C:\Users\HP\Documents\Code\aniplay-2.0.4.next\server\app\anime\watch[[...watchid]]\page.js:1:195654) Error fetching episode history by epid Error: Failed to get Episode at w (C:\Users\HP\Documents\Code\aniplay-2.0.4.next\server\app\anime\watch[[...watchid]]\page.js:1:194439) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async V (C:\Users\HP\Documents\Code\aniplay-2.0.4.next\server\app\anime\watch[[...watchid]]\page.js:1:195654)****

Noname968 commented 4 months ago

Did u add consumet api url? The above errors can be ignored they are related to database.

Noname968 commented 4 months ago

Just found the issue it seems that u did not provide redis url i did not handle that case in the code, I just fixed it and i will release the new code by today.

In app/api/epsiode/route.js file replace this function and u are good to go

const fetchAndCacheData = async (id, meta, redis, cacheTime) => {
  const [consumet, anify, cover] = await Promise.all([
    fetchConsumetEpisodes(id),
    fetchAnifyEpisodes(id),
    fetchEpisodeImages(id, meta)
  ]);

  // Check if redis is available
  if (redis) {
    if (consumet.length > 0 || anify.length > 0) {
      await redis.setex(`episode:${id}`, cacheTime, JSON.stringify([...consumet, ...anify]));
    }

    const combinedData = [...consumet, ...anify];
    let data = combinedData;

    if (meta) {
      data = await CombineEpisodeMeta(combinedData, JSON.parse(meta));
    } else if (cover && cover?.length > 0) {
      try {
        await redis.setex(`meta:${id}`, cacheTime, JSON.stringify(cover));
        data = await CombineEpisodeMeta(combinedData, cover);
      } catch (error) {
        console.error("Error serializing cover:", error.message);
      }
    }

    return data;
  } else {
    console.error("Redis URL not provided. Caching not possible.");
    return [...consumet, ...anify];
  }
};