forked from OpenWF/SpaceNinjaServer
		
	chore: handle profile viewing data request from old versions (#1970)
Reviewed-on: OpenWF/SpaceNinjaServer#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,16 +18,15 @@ 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> => {
 | 
				
			||||||
    if (req.query.playerId) {
 | 
					    const account = await Account.findById(playerId, "DisplayName");
 | 
				
			||||||
        const account = await Account.findById(req.query.playerId as string, "DisplayName");
 | 
					 | 
				
			||||||
    if (!account) {
 | 
					    if (!account) {
 | 
				
			||||||
            res.status(409).send("Could not find requested account");
 | 
					 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    const inventory = (await Inventory.findOne({ accountOwnerId: account._id }))!;
 | 
					    const inventory = (await Inventory.findOne({ accountOwnerId: account._id }))!;
 | 
				
			||||||
@ -67,13 +66,23 @@ export const getProfileViewingDataController: RequestHandler = async (req, res)
 | 
				
			|||||||
    delete stats.__v;
 | 
					    delete stats.__v;
 | 
				
			||||||
    delete stats.accountOwnerId;
 | 
					    delete stats.accountOwnerId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        res.json({
 | 
					    return {
 | 
				
			||||||
        Results: [result],
 | 
					        Results: [result],
 | 
				
			||||||
        TechProjects: [],
 | 
					        TechProjects: [],
 | 
				
			||||||
        XpComponents: [],
 | 
					        XpComponents: [],
 | 
				
			||||||
        //XpCacheExpiryDate, some IMongoDate in the future, no clue what it's for
 | 
					        //XpCacheExpiryDate, some IMongoDate in the future, no clue what it's for
 | 
				
			||||||
        Stats: stats
 | 
					        Stats: stats
 | 
				
			||||||
        });
 | 
					    };
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const getProfileViewingDataGetController: RequestHandler = async (req, res) => {
 | 
				
			||||||
 | 
					    if (req.query.playerId) {
 | 
				
			||||||
 | 
					        const data = await getProfileViewingDataByPlayerIdImpl(req.query.playerId as string);
 | 
				
			||||||
 | 
					        if (data) {
 | 
				
			||||||
 | 
					            res.json(data);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            res.status(409).send("Could not find requested account");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    } 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