chore: handle profile viewing data request from old versions (#1970)
Reviewed-on: #1970 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
parent
18fbd51efb
commit
ff3a9b382c
@ -18,62 +18,71 @@ import {
|
|||||||
ITypeXPItem
|
ITypeXPItem
|
||||||
} from "@/src/types/inventoryTypes/inventoryTypes";
|
} from "@/src/types/inventoryTypes/inventoryTypes";
|
||||||
import { RequestHandler } from "express";
|
import { RequestHandler } from "express";
|
||||||
import { catBreadHash } from "@/src/helpers/stringHelpers";
|
import { catBreadHash, getJSONfromString } from "@/src/helpers/stringHelpers";
|
||||||
import { ExportCustoms, ExportDojoRecipes } from "warframe-public-export-plus";
|
import { ExportCustoms, ExportDojoRecipes } from "warframe-public-export-plus";
|
||||||
import { IStatsClient } from "@/src/types/statTypes";
|
import { IStatsClient } from "@/src/types/statTypes";
|
||||||
import { toStoreItem } from "@/src/services/itemDataService";
|
import { toStoreItem } from "@/src/services/itemDataService";
|
||||||
|
import { FlattenMaps } from "mongoose";
|
||||||
|
|
||||||
export const getProfileViewingDataController: RequestHandler = async (req, res) => {
|
const getProfileViewingDataByPlayerIdImpl = async (playerId: string): Promise<IProfileViewingData | undefined> => {
|
||||||
|
const account = await Account.findById(playerId, "DisplayName");
|
||||||
|
if (!account) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const inventory = (await Inventory.findOne({ accountOwnerId: account._id }))!;
|
||||||
|
|
||||||
|
const result: IPlayerProfileViewingDataResult = {
|
||||||
|
AccountId: toOid(account._id),
|
||||||
|
DisplayName: account.DisplayName,
|
||||||
|
PlayerLevel: inventory.PlayerLevel,
|
||||||
|
LoadOutInventory: {
|
||||||
|
WeaponSkins: [],
|
||||||
|
XPInfo: inventory.XPInfo
|
||||||
|
},
|
||||||
|
PlayerSkills: inventory.PlayerSkills,
|
||||||
|
ChallengeProgress: inventory.ChallengeProgress,
|
||||||
|
DeathMarks: inventory.DeathMarks,
|
||||||
|
Harvestable: inventory.Harvestable,
|
||||||
|
DeathSquadable: inventory.DeathSquadable,
|
||||||
|
Created: toMongoDate(inventory.Created),
|
||||||
|
MigratedToConsole: false,
|
||||||
|
Missions: inventory.Missions,
|
||||||
|
Affiliations: inventory.Affiliations,
|
||||||
|
DailyFocus: inventory.DailyFocus,
|
||||||
|
Wishlist: inventory.Wishlist,
|
||||||
|
Alignment: inventory.Alignment
|
||||||
|
};
|
||||||
|
await populateLoadout(inventory, result);
|
||||||
|
if (inventory.GuildId) {
|
||||||
|
const guild = (await Guild.findById(inventory.GuildId, "Name Tier XP Class Emblem"))!;
|
||||||
|
populateGuild(guild, result);
|
||||||
|
}
|
||||||
|
for (const key of allDailyAffiliationKeys) {
|
||||||
|
result[key] = inventory[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
const stats = (await Stats.findOne({ accountOwnerId: account._id }))!.toJSON<Partial<TStatsDatabaseDocument>>();
|
||||||
|
delete stats._id;
|
||||||
|
delete stats.__v;
|
||||||
|
delete stats.accountOwnerId;
|
||||||
|
|
||||||
|
return {
|
||||||
|
Results: [result],
|
||||||
|
TechProjects: [],
|
||||||
|
XpComponents: [],
|
||||||
|
//XpCacheExpiryDate, some IMongoDate in the future, no clue what it's for
|
||||||
|
Stats: stats
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getProfileViewingDataGetController: RequestHandler = async (req, res) => {
|
||||||
if (req.query.playerId) {
|
if (req.query.playerId) {
|
||||||
const account = await Account.findById(req.query.playerId as string, "DisplayName");
|
const data = await getProfileViewingDataByPlayerIdImpl(req.query.playerId as string);
|
||||||
if (!account) {
|
if (data) {
|
||||||
|
res.json(data);
|
||||||
|
} else {
|
||||||
res.status(409).send("Could not find requested account");
|
res.status(409).send("Could not find requested account");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
const inventory = (await Inventory.findOne({ accountOwnerId: account._id }))!;
|
|
||||||
|
|
||||||
const result: IPlayerProfileViewingDataResult = {
|
|
||||||
AccountId: toOid(account._id),
|
|
||||||
DisplayName: account.DisplayName,
|
|
||||||
PlayerLevel: inventory.PlayerLevel,
|
|
||||||
LoadOutInventory: {
|
|
||||||
WeaponSkins: [],
|
|
||||||
XPInfo: inventory.XPInfo
|
|
||||||
},
|
|
||||||
PlayerSkills: inventory.PlayerSkills,
|
|
||||||
ChallengeProgress: inventory.ChallengeProgress,
|
|
||||||
DeathMarks: inventory.DeathMarks,
|
|
||||||
Harvestable: inventory.Harvestable,
|
|
||||||
DeathSquadable: inventory.DeathSquadable,
|
|
||||||
Created: toMongoDate(inventory.Created),
|
|
||||||
MigratedToConsole: false,
|
|
||||||
Missions: inventory.Missions,
|
|
||||||
Affiliations: inventory.Affiliations,
|
|
||||||
DailyFocus: inventory.DailyFocus,
|
|
||||||
Wishlist: inventory.Wishlist,
|
|
||||||
Alignment: inventory.Alignment
|
|
||||||
};
|
|
||||||
await populateLoadout(inventory, result);
|
|
||||||
if (inventory.GuildId) {
|
|
||||||
const guild = (await Guild.findById(inventory.GuildId, "Name Tier XP Class Emblem"))!;
|
|
||||||
populateGuild(guild, result);
|
|
||||||
}
|
|
||||||
for (const key of allDailyAffiliationKeys) {
|
|
||||||
result[key] = inventory[key];
|
|
||||||
}
|
|
||||||
|
|
||||||
const stats = (await Stats.findOne({ accountOwnerId: account._id }))!.toJSON<Partial<TStatsDatabaseDocument>>();
|
|
||||||
delete stats._id;
|
|
||||||
delete stats.__v;
|
|
||||||
delete stats.accountOwnerId;
|
|
||||||
|
|
||||||
res.json({
|
|
||||||
Results: [result],
|
|
||||||
TechProjects: [],
|
|
||||||
XpComponents: [],
|
|
||||||
//XpCacheExpiryDate, some IMongoDate in the future, no clue what it's for
|
|
||||||
Stats: stats
|
|
||||||
});
|
|
||||||
} else if (req.query.guildId) {
|
} else if (req.query.guildId) {
|
||||||
const guild = await Guild.findById(req.query.guildId, "Name Tier XP Class Emblem TechProjects ClaimedXP");
|
const guild = await Guild.findById(req.query.guildId, "Name Tier XP Class Emblem TechProjects ClaimedXP");
|
||||||
if (!guild) {
|
if (!guild) {
|
||||||
@ -170,6 +179,28 @@ export const getProfileViewingDataController: RequestHandler = async (req, res)
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// For old versions, this was an authenticated POST request.
|
||||||
|
interface IGetProfileViewingDataRequest {
|
||||||
|
AccountId: string;
|
||||||
|
}
|
||||||
|
export const getProfileViewingDataPostController: RequestHandler = async (req, res) => {
|
||||||
|
const payload = getJSONfromString<IGetProfileViewingDataRequest>(String(req.body));
|
||||||
|
const data = await getProfileViewingDataByPlayerIdImpl(payload.AccountId);
|
||||||
|
if (data) {
|
||||||
|
res.json(data);
|
||||||
|
} else {
|
||||||
|
res.status(409).send("Could not find requested account");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
interface IProfileViewingData {
|
||||||
|
Results: IPlayerProfileViewingDataResult[];
|
||||||
|
TechProjects: [];
|
||||||
|
XpComponents: [];
|
||||||
|
//XpCacheExpiryDate, some IMongoDate in the future, no clue what it's for
|
||||||
|
Stats: FlattenMaps<Partial<TStatsDatabaseDocument>>;
|
||||||
|
}
|
||||||
|
|
||||||
interface IPlayerProfileViewingDataResult extends Partial<IDailyAffiliations> {
|
interface IPlayerProfileViewingDataResult extends Partial<IDailyAffiliations> {
|
||||||
AccountId: IOid;
|
AccountId: IOid;
|
||||||
DisplayName: string;
|
DisplayName: string;
|
||||||
|
@ -59,6 +59,7 @@ import { getGuildDojoController } from "@/src/controllers/api/getGuildDojoContro
|
|||||||
import { getGuildLogController } from "@/src/controllers/api/getGuildLogController";
|
import { getGuildLogController } from "@/src/controllers/api/getGuildLogController";
|
||||||
import { getIgnoredUsersController } from "@/src/controllers/api/getIgnoredUsersController";
|
import { getIgnoredUsersController } from "@/src/controllers/api/getIgnoredUsersController";
|
||||||
import { getNewRewardSeedController } from "@/src/controllers/api/getNewRewardSeedController";
|
import { getNewRewardSeedController } from "@/src/controllers/api/getNewRewardSeedController";
|
||||||
|
import { getProfileViewingDataPostController } from "@/src/controllers/dynamic/getProfileViewingDataController";
|
||||||
import { getShipController } from "@/src/controllers/api/getShipController";
|
import { getShipController } from "@/src/controllers/api/getShipController";
|
||||||
import { getVendorInfoController } from "@/src/controllers/api/getVendorInfoController";
|
import { getVendorInfoController } from "@/src/controllers/api/getVendorInfoController";
|
||||||
import { getVoidProjectionRewardsController } from "@/src/controllers/api/getVoidProjectionRewardsController";
|
import { getVoidProjectionRewardsController } from "@/src/controllers/api/getVoidProjectionRewardsController";
|
||||||
@ -247,6 +248,7 @@ apiRouter.post("/genericUpdate.php", genericUpdateController);
|
|||||||
apiRouter.post("/getAlliance.php", getAllianceController);
|
apiRouter.post("/getAlliance.php", getAllianceController);
|
||||||
apiRouter.post("/getFriends.php", getFriendsController);
|
apiRouter.post("/getFriends.php", getFriendsController);
|
||||||
apiRouter.post("/getGuildDojo.php", getGuildDojoController);
|
apiRouter.post("/getGuildDojo.php", getGuildDojoController);
|
||||||
|
apiRouter.post("/getProfileViewingData.php", getProfileViewingDataPostController);
|
||||||
apiRouter.post("/getVoidProjectionRewards.php", getVoidProjectionRewardsController);
|
apiRouter.post("/getVoidProjectionRewards.php", getVoidProjectionRewardsController);
|
||||||
apiRouter.post("/gifting.php", giftingController);
|
apiRouter.post("/gifting.php", giftingController);
|
||||||
apiRouter.post("/gildWeapon.php", gildWeaponController);
|
apiRouter.post("/gildWeapon.php", gildWeaponController);
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
import express from "express";
|
import express from "express";
|
||||||
import { aggregateSessionsController } from "@/src/controllers/dynamic/aggregateSessionsController";
|
import { aggregateSessionsController } from "@/src/controllers/dynamic/aggregateSessionsController";
|
||||||
import { getGuildAdsController } from "@/src/controllers/dynamic/getGuildAdsController";
|
import { getGuildAdsController } from "@/src/controllers/dynamic/getGuildAdsController";
|
||||||
import { getProfileViewingDataController } from "@/src/controllers/dynamic/getProfileViewingDataController";
|
import { getProfileViewingDataGetController } from "@/src/controllers/dynamic/getProfileViewingDataController";
|
||||||
import { worldStateController } from "@/src/controllers/dynamic/worldStateController";
|
import { worldStateController } from "@/src/controllers/dynamic/worldStateController";
|
||||||
|
|
||||||
const dynamicController = express.Router();
|
const dynamicController = express.Router();
|
||||||
|
|
||||||
dynamicController.get("/aggregateSessions.php", aggregateSessionsController);
|
dynamicController.get("/aggregateSessions.php", aggregateSessionsController);
|
||||||
dynamicController.get("/getGuildAds.php", getGuildAdsController);
|
dynamicController.get("/getGuildAds.php", getGuildAdsController);
|
||||||
dynamicController.get("/getProfileViewingData.php", getProfileViewingDataController);
|
dynamicController.get("/getProfileViewingData.php", getProfileViewingDataGetController);
|
||||||
dynamicController.get("/worldState.php", worldStateController);
|
dynamicController.get("/worldState.php", worldStateController);
|
||||||
|
|
||||||
export { dynamicController };
|
export { dynamicController };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user