From c141fba1db206939550a419d8b63de0573ce73ec Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 18 Nov 2024 21:07:41 +0000 Subject: [PATCH] change track to post --- .../src/controller/player.controller.ts | 4 ++-- projects/common/src/utils/player-utils.ts | 22 +++++++++---------- projects/common/src/utils/utils.ts | 18 +++++++++++++-- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/projects/backend/src/controller/player.controller.ts b/projects/backend/src/controller/player.controller.ts index d48ce503..137345ab 100644 --- a/projects/backend/src/controller/player.controller.ts +++ b/projects/backend/src/controller/player.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Get } from "elysia-decorators"; +import { Controller, Get, Post } from "elysia-decorators"; import { PlayerService } from "../service/player.service"; import { t } from "elysia"; import { PlayerTrackedSince } from "@ssr/common/player/player-tracked-since"; @@ -32,7 +32,7 @@ export default class PlayerController { return superJson ? SuperJSON.stringify(player) : player; } - @Get("/track/:id", { + @Post("/track/:id", { config: {}, params: t.Object({ id: t.String({ required: true }), diff --git a/projects/common/src/utils/player-utils.ts b/projects/common/src/utils/player-utils.ts index 3cb7d64e..7d46829d 100644 --- a/projects/common/src/utils/player-utils.ts +++ b/projects/common/src/utils/player-utils.ts @@ -1,14 +1,14 @@ -import {PlayerHistory} from "../player/player-history"; -import {kyFetchJson, kyFetchText} from "./utils"; -import {Config} from "../config"; -import {AroundPlayer} from "../types/around-player"; -import {AroundPlayerResponse} from "../response/around-player-response"; +import { PlayerHistory } from "../player/player-history"; +import { kyFetchJson, kyFetchText, kyPostJson } from "./utils"; +import { Config } from "../config"; +import { AroundPlayer } from "../types/around-player"; +import { AroundPlayerResponse } from "../response/around-player-response"; import ScoreSaberPlayer from "../player/impl/scoresaber-player"; -import {formatDateMinimal, getMidnightAlignedDate} from "./time-utils"; -import {PpBoundaryResponse} from "../response/pp-boundary-response"; -import {PlayedMapsCalendarResponse} from "../response/played-maps-calendar-response"; -import {ScoreSaberScore} from "../model/score/impl/scoresaber-score"; -import {Page} from "../pagination"; +import { formatDateMinimal, getMidnightAlignedDate } from "./time-utils"; +import { PpBoundaryResponse } from "../response/pp-boundary-response"; +import { PlayedMapsCalendarResponse } from "../response/played-maps-calendar-response"; +import { ScoreSaberScore } from "../model/score/impl/scoresaber-score"; +import { Page } from "../pagination"; import SuperJSON from "superjson"; /** @@ -53,7 +53,7 @@ export function getValueFromHistory(history: PlayerHistory, field: string): numb * @param playerId the player id */ export async function trackPlayer(playerId: string) { - await kyFetchJson(`${Config.apiUrl}/player/track/${playerId}`); + await kyPostJson(`${Config.apiUrl}/player/track/${playerId}`); } /** diff --git a/projects/common/src/utils/utils.ts b/projects/common/src/utils/utils.ts index fd79494e..d4c129d1 100644 --- a/projects/common/src/utils/utils.ts +++ b/projects/common/src/utils/utils.ts @@ -1,6 +1,6 @@ import ky from "ky"; -import {formatNumberWithCommas, formatPp} from "./number-utils"; -import {KyOptions} from "ky/distribution/types/options"; +import { formatNumberWithCommas, formatPp } from "./number-utils"; +import { KyOptions } from "ky/distribution/types/options"; /** * Checks if we're in production @@ -50,6 +50,20 @@ export async function kyFetchJson(url: string, options?: KyOptions): Promise< } } +/** + * Posts data top the given url. + * + * @param url the url to post to + * @param options the ky options to use + */ +export async function kyPostJson(url: string, options?: KyOptions): Promise { + try { + return await ky.post(url, options).json(); + } catch (error) { + return undefined; + } +} + /** * Fetches data from the given url. *