aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pages/api/v2/info/index.js10
-rw-r--r--pages/en/manga/[...id].js25
2 files changed, 20 insertions, 15 deletions
diff --git a/pages/api/v2/info/index.js b/pages/api/v2/info/index.js
index 95770bd..39795d3 100644
--- a/pages/api/v2/info/index.js
+++ b/pages/api/v2/info/index.js
@@ -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);
@@ -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) {
diff --git a/pages/en/manga/[...id].js b/pages/en/manga/[...id].js
index 106bce2..6d2b016 100644
--- a/pages/en/manga/[...id].js
+++ b/pages/en/manga/[...id].js
@@ -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;
@@ -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
+ );
+ }
}
}