Skip to content
This repository has been archived by the owner on Jul 14, 2024. It is now read-only.

Commit

Permalink
fixed redis error for manga (#95)
Browse files Browse the repository at this point in the history
* fixed schedules

* fixed redis

* Update [...id].js

* Update index.js
  • Loading branch information
Aijazmakerb authored Oct 22, 2023
1 parent 2389d9a commit 100edf2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
10 changes: 6 additions & 4 deletions pages/api/v2/info/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ export default async function handler(req, res) {
try {
let cached;
// const data = await fetchInfo(id);
cached = await redis.get(`manga:${id}`);
if (redis) {
cached = await redis.get(`manga:${id}`);

if (cached) {
return res.status(200).json(JSON.parse(cached));
if (cached) {
return res.status(200).json(JSON.parse(cached));
}
}

const manga = await fetchInfo(id);
Expand All @@ -51,7 +53,7 @@ export default async function handler(req, res) {
return res.status(404).json({ error: "Manga not found" });
}

await redis.set(`manga:${id}`, JSON.stringify(manga), "ex", 60 * 60 * 24);
if (redis) await redis.set(`manga:${id}`, JSON.stringify(manga), "ex", 60 * 60 * 24);

res.status(200).json(manga);
} catch (error) {
Expand Down
25 changes: 14 additions & 11 deletions pages/en/manga/[...id].js
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,14 @@ export async function getServerSideProps(context) {
},
};
} else {
const getCached = await redis.get(`mangaPage:${mangadexId}`);
if (redis) {
const getCached = await redis.get(`mangaPage:${mangadexId}`);

if (getCached) {
cached = JSON.parse(getCached);
if (getCached) {
cached = JSON.parse(getCached);
}
}

// let chapters;

if (cached) {
data = cached.data;
info = cached.info;
Expand Down Expand Up @@ -389,12 +389,15 @@ export async function getServerSideProps(context) {
color: textColor,
};

await redis.set(
`mangaPage:${mangadexId}`,
JSON.stringify({ data, info, color }),
"ex",
60 * 60 * 24
);
if(redis)
{
await redis.set(
`mangaPage:${mangadexId}`,
JSON.stringify({ data, info, color }),
"ex",
60 * 60 * 24
);
}
}
}

Expand Down

0 comments on commit 100edf2

Please sign in to comment.