From 2a53ba6826fdf7c78e1aa17390196bc0fc415326 Mon Sep 17 00:00:00 2001 From: nameless Date: Fri, 10 Nov 2023 10:45:39 +0000 Subject: [PATCH] feat: tagcount endpoint removes tagCountMap from user endpoint, returns it only via admin-only endpoint --- api/statsRoute.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/api/statsRoute.ts b/api/statsRoute.ts index 8bd1f76..09f814e 100644 --- a/api/statsRoute.ts +++ b/api/statsRoute.ts @@ -5,6 +5,7 @@ import { generationStore } from "../app/generationStore.ts"; import { globalStats } from "../app/globalStats.ts"; import { getUserDailyStats } from "../app/userDailyStatsStore.ts"; import { getUserStats } from "../app/userStatsStore.ts"; +import { withAdmin } from "./withUser.ts"; const STATS_INTERVAL_MIN = 3; @@ -91,7 +92,6 @@ export const statsRoute = createPathFilter({ data: { imageCount: stats.imageCount, pixelCount: stats.pixelCount, - tagCountMap: stats.tagCountMap, timestamp: stats.timestamp, }, }, @@ -99,6 +99,27 @@ export const statsRoute = createPathFilter({ }, ), }), + "users/{userId}/tagcount": createMethodFilter({ + GET: createEndpoint( + { query: { sessionId: { type: "string" } }, body: null }, + async ({ params, query }) => { + return withAdmin(query, async () => { + const userId = Number(params.userId); + const stats = await getUserStats(userId); + return { + status: 200, + body: { + type: "application/json", + data: { + tagCountMap: stats.tagCountMap, + timestamp: stats.timestamp, + }, + }, + }; + }); + }, + ), + }), "users/{userId}/daily/{year}/{month}/{day}": createMethodFilter({ GET: createEndpoint( { query: null, body: null },