From e58655e3f47e2644d4d510da5a1f66e6ad2e79e3 Mon Sep 17 00:00:00 2001 From: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com> Date: Thu, 6 Nov 2025 00:17:52 -0800 Subject: [PATCH] feat: profileStats endpoint for U8 (#3003) Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3003 Reviewed-by: Sainan <63328889+sainan@users.noreply.github.com> Co-authored-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com> Co-committed-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com> --- src/controllers/api/getFriendsController.ts | 11 ++++++----- src/controllers/stats/viewController.ts | 3 +-- src/routes/stats.ts | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/controllers/api/getFriendsController.ts b/src/controllers/api/getFriendsController.ts index 797b44b9..ab3fe0a5 100644 --- a/src/controllers/api/getFriendsController.ts +++ b/src/controllers/api/getFriendsController.ts @@ -1,13 +1,14 @@ -import { toOid } from "../../helpers/inventoryHelpers.ts"; +import { toOid2 } from "../../helpers/inventoryHelpers.ts"; import { Friendship } from "../../models/friendModel.ts"; import { addAccountDataToFriendInfo, addInventoryDataToFriendInfo } from "../../services/friendService.ts"; -import { getAccountIdForRequest } from "../../services/loginService.ts"; +import { getAccountForRequest } from "../../services/loginService.ts"; import type { IFriendInfo } from "../../types/friendTypes.ts"; import type { Request, RequestHandler, Response } from "express"; // POST with {} instead of GET as of 38.5.0 export const getFriendsController: RequestHandler = async (req: Request, res: Response) => { - const accountId = await getAccountIdForRequest(req); + const account = await getAccountForRequest(req); + const accountId = account._id.toString(); const response: IGetFriendsResponse = { Current: [], IncomingFriendRequests: [], @@ -20,14 +21,14 @@ export const getFriendsController: RequestHandler = async (req: Request, res: Re for (const externalFriendship of externalFriendships) { if (!internalFriendships.find(x => x.friend.equals(externalFriendship.owner))) { response.IncomingFriendRequests.push({ - _id: toOid(externalFriendship.owner), + _id: toOid2(externalFriendship.owner, account.BuildLabel), Note: externalFriendship.Note }); } } for (const internalFriendship of internalFriendships) { const friendInfo: IFriendInfo = { - _id: toOid(internalFriendship.friend) + _id: toOid2(internalFriendship.friend, account.BuildLabel) }; if (externalFriendships.find(x => x.owner.equals(internalFriendship.friend))) { response.Current.push(friendInfo); diff --git a/src/controllers/stats/viewController.ts b/src/controllers/stats/viewController.ts index 861dacdc..72911bfc 100644 --- a/src/controllers/stats/viewController.ts +++ b/src/controllers/stats/viewController.ts @@ -1,11 +1,10 @@ import type { RequestHandler } from "express"; -import { getAccountIdForRequest } from "../../services/loginService.ts"; import { getInventory } from "../../services/inventoryService.ts"; import { getStats } from "../../services/statsService.ts"; import type { IStatsClient } from "../../types/statTypes.ts"; const viewController: RequestHandler = async (req, res) => { - const accountId = await getAccountIdForRequest(req); + const accountId = String(req.query.id ?? req.query.lookupId); const inventory = await getInventory(accountId, "XPInfo"); const playerStats = await getStats(accountId); diff --git a/src/routes/stats.ts b/src/routes/stats.ts index 22d54d28..8f3dfe5b 100644 --- a/src/routes/stats.ts +++ b/src/routes/stats.ts @@ -6,6 +6,7 @@ import { leaderboardController } from "../controllers/stats/leaderboardControlle const statsRouter = express.Router(); statsRouter.get("/view.php", viewController); +statsRouter.get("/profileStats.php", viewController); statsRouter.post("/upload.php", uploadController); statsRouter.post("/leaderboardWeekly.php", leaderboardController); statsRouter.post("/leaderboardArchived.php", leaderboardController);