Skip to content

Commit

Permalink
fix(api/stats): make profile optional
Browse files Browse the repository at this point in the history
  • Loading branch information
DuckySoLucky committed Jan 7, 2025
1 parent 89148c5 commit fbeca46
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 48 deletions.
33 changes: 0 additions & 33 deletions src/routes/api/stats/[paramPlayer=player]/+server.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { dev } from "$app/environment";
import { fetchMuseum, fetchPlayer, getProfile } from "$lib/server/lib";
import { getStats } from "$lib/server/stats";
import { json } from "@sveltejs/kit";
import zlib from "zlib";
import type { RequestHandler } from "./$types";

export const GET: RequestHandler = async ({ params, request, cookies }) => {
export const GET: RequestHandler = async ({ params, cookies }) => {
const timeNow = Date.now();
const { paramPlayer, paramProfile } = params;

Expand All @@ -14,20 +14,9 @@ export const GET: RequestHandler = async ({ params, request, cookies }) => {
const packs = JSON.parse(cookies.get("disabledPacks") || "[]");
const stats = await getStats(profile, player, { museum, packs: packs });

const acceptEncoding = request.headers.get("accept-encoding");
const supportsGzip = acceptEncoding?.includes("gzip");
if (supportsGzip) {
const compressed = zlib.gzipSync(JSON.stringify(stats));
console.log(`/api/stats/${paramPlayer} took ${Date.now() - timeNow}ms`);

return new Response(compressed, {
headers: {
"content-encoding": "gzip",
"content-type": "application/json"
}
});
if (dev) {
console.log(`/api/stats/${paramPlayer}${paramProfile !== "undefined" ? `/${paramProfile}` : ""} took ${Date.now() - timeNow}ms`);
}

console.log(`/api/stats/${paramPlayer}/${paramProfile} took ${Date.now() - timeNow}ms`);
return json(stats);
};

0 comments on commit fbeca46

Please sign in to comment.