feat: profileStats endpoint for U8 #3003

Merged
Sainan merged 4 commits from AMelonInsideLemon/SpaceNinjaServer:view-stats-u8 into main 2025-11-06 00:17:52 -08:00
3 changed files with 8 additions and 7 deletions

View File

@@ -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);

View File

@@ -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");
Sainan marked this conversation as resolved Outdated

You can remove this for the time being.

You can remove this for the time being.
const playerStats = await getStats(accountId);

View File

@@ -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);