mirror of
https://iceshrimp.dev/crimekillz/iceshrimp-161sh.git
synced 2024-11-22 04:03:49 +01:00
refactor: ♻️ read patrons from local file for fallback instead of empty array
This commit is contained in:
parent
c4d4e850b2
commit
94b16ba9a3
@ -1,5 +1,11 @@
|
||||
import define from "../define.js";
|
||||
import { redisClient } from "@/db/redis.js";
|
||||
import * as fs from "node:fs";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { dirname } from "node:path";
|
||||
|
||||
const _filename = fileURLToPath(import.meta.url);
|
||||
const _dirname = dirname(_filename);
|
||||
|
||||
export const meta = {
|
||||
tags: ["meta"],
|
||||
@ -35,7 +41,10 @@ export default define(meta, paramDef, async (ps) => {
|
||||
)
|
||||
.then((response) => response.json())
|
||||
.catch(() => {
|
||||
patrons = cachedPatrons ? JSON.parse(cachedPatrons) : [];
|
||||
const staticPatrons = JSON.parse(
|
||||
fs.readFileSync(`${_dirname}/../../../../../../patrons.json`, "utf-8"),
|
||||
);
|
||||
patrons = cachedPatrons ? JSON.parse(cachedPatrons) : staticPatrons;
|
||||
});
|
||||
await redisClient.set("patrons", JSON.stringify(patrons), "EX", 3600);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user