diff --git a/src/backend/server/api.ts b/src/backend/server/api.ts index e957a628..a98467b8 100644 --- a/src/backend/server/api.ts +++ b/src/backend/server/api.ts @@ -346,6 +346,23 @@ export const setupApi = (app: Express, logger: Logger, appLoggerStream: PassThro return res.json(asSerializablePlaySelect(playRes)); }); + app.delete('/api/cache/:cacheType', async (req, res) => { + const cache = await getRoot().items.cache(); + logger.verbose(`User request cache deletion for ${req.params.cacheType}`); + switch(req.params.cacheType) { + case 'external-api': + await cache.cacheApi.clear(); + break; + case 'transforms': + await cache.cacheTransform.clear(); + break; + default: + return res.sendStatus(404); + } + logger.verbose('Cache cleared!'); + return res.sendStatus(204); + }); + /** * * diff --git a/src/client/components/settings/settings.tsx b/src/client/components/settings/settings.tsx index 729abd8e..81dfe9ae 100644 --- a/src/client/components/settings/settings.tsx +++ b/src/client/components/settings/settings.tsx @@ -2,11 +2,19 @@ import { useCallback } from "react" import { VStack, Heading, - SegmentGroup} from "@chakra-ui/react" + SegmentGroup, + Group, + Box, + Button +} from "@chakra-ui/react" import { useTheme } from "next-themes" import { BsCircleHalf } from "react-icons/bs"; import { LuMoon, LuSun } from "react-icons/lu" -import { makeChakraIcon } from "../icons/ChakraIcons"; +import { CheckIcon, makeChakraIcon } from "../icons/ChakraIcons"; +import { useMutation } from "@tanstack/react-query"; +import ky from "ky"; +import type { CacheClearType } from "../../../core/Api"; +import { EphemeralElement } from "../Badges"; const DarkIcon = makeChakraIcon(LuMoon); const LightIcon = makeChakraIcon(LuSun); @@ -28,6 +36,11 @@ export const SettingsContainer = () => { break; } },[setTheme]); + + const {mutate, isPending, variables, isSuccess} = useMutation({ + mutationFn: (clearType: CacheClearType) => ky.delete(`/api/cache/${clearType}`) + }); + return ( Appearance @@ -50,6 +63,27 @@ export const SettingsContainer = () => { + Cache + + + + + + ) } \ No newline at end of file diff --git a/src/core/Api.ts b/src/core/Api.ts index a79fff09..b43e090a 100644 --- a/src/core/Api.ts +++ b/src/core/Api.ts @@ -209,3 +209,4 @@ export type CompareDateSingle = { date: D; }; +export type CacheClearType = 'external-api' | 'transforms'; \ No newline at end of file