refactor: move cache seconds calculation logic into reusable function (#4532)
* refactor: move cache seconds calculation logic into reusable function * dev --------- Co-authored-by: Alexandr <qwerty541zxc@gmail.com>
This commit is contained in:
1 parent
fde13639aa
commit
ade7d53653
6 files changed
+60
-60
No files matched your search
+8
-15
@@ -2,13 +2,9 @@
|
||||
|
||||
import { renderRepoCard } from "../src/cards/repo.js";
|
||||
import { blacklist } from "../src/common/blacklist.js";
|
||||
import { resolveCacheSeconds } from "../src/common/cache.js";
|
||||
import { whitelist } from "../src/common/envs.js";
|
||||
import {
|
||||
clampValue,
|
||||
CONSTANTS,
|
||||
parseBoolean,
|
||||
renderError,
|
||||
} from "../src/common/utils.js";
|
||||
import { CONSTANTS, parseBoolean, renderError } from "../src/common/utils.js";
|
||||
import { fetchRepo } from "../src/fetchers/repo.js";
|
||||
import { isLocaleAvailable } from "../src/translations.js";
|
||||
|
||||
@@ -80,15 +76,12 @@ export default async (req, res) => {
|
||||
|
||||
try {
|
||||
const repoData = await fetchRepo(username, repo);
|
||||
|
||||
let cacheSeconds = clampValue(
|
||||
parseInt(cache_seconds || CONSTANTS.PIN_CARD_CACHE_SECONDS, 10),
|
||||
CONSTANTS.ONE_DAY,
|
||||
CONSTANTS.TEN_DAY,
|
||||
);
|
||||
cacheSeconds = process.env.CACHE_SECONDS
|
||||
? parseInt(process.env.CACHE_SECONDS, 10) || cacheSeconds
|
||||
: cacheSeconds;
|
||||
const cacheSeconds = resolveCacheSeconds({
|
||||
requested: cache_seconds,
|
||||
def: CONSTANTS.PIN_CARD_CACHE_SECONDS,
|
||||
min: CONSTANTS.ONE_DAY,
|
||||
max: CONSTANTS.TEN_DAY,
|
||||
});
|
||||
|
||||
res.setHeader(
|
||||
"Cache-Control",
|
||||
|
||||
Reference in new issue
Block a user