返回提交历史
Modified
src/controllers/dynamic/getProfileViewingDataController.ts
+80
-49
Modified
src/routes/api.ts
+2
-0
Modified
src/routes/dynamic.ts
+2
-2
XFEstudio/SpaceNinjaServer
chore: handle profile viewing data request from old versions (#1970)
Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1970 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
ff3a9b38
代码差异
3 个文件
+84
-51
@@ -18,62 +18,71 @@ import {
18
18
ITypeXPItem
19
19
} from "@/src/types/inventoryTypes/inventoryTypes";
20
20
import { RequestHandler } from "express";
21
import { catBreadHash } from "@/src/helpers/stringHelpers";
21
import { catBreadHash, getJSONfromString } from "@/src/helpers/stringHelpers";
22
22
import { ExportCustoms, ExportDojoRecipes } from "warframe-public-export-plus";
23
23
import { IStatsClient } from "@/src/types/statTypes";
24
24
import { toStoreItem } from "@/src/services/itemDataService";
25
import { FlattenMaps } from "mongoose";
25
26
26
export const getProfileViewingDataController: RequestHandler = async (req, res) => {
27
if (req.query.playerId) {
28
const account = await Account.findById(req.query.playerId as string, "DisplayName");
29
if (!account) {
30
res.status(409).send("Could not find requested account");
31
return;
32
}
33
const inventory = (await Inventory.findOne({ accountOwnerId: account._id }))!;
27
const getProfileViewingDataByPlayerIdImpl = async (playerId: string): Promise<IProfileViewingData | undefined> => {
28
const account = await Account.findById(playerId, "DisplayName");
29
if (!account) {
30
return;
31
}
32
const inventory = (await Inventory.findOne({ accountOwnerId: account._id }))!;
34
33
35
const result: IPlayerProfileViewingDataResult = {
36
AccountId: toOid(account._id),
37
DisplayName: account.DisplayName,
38
PlayerLevel: inventory.PlayerLevel,
39
LoadOutInventory: {
40
WeaponSkins: [],
41
XPInfo: inventory.XPInfo
42
},
43
PlayerSkills: inventory.PlayerSkills,
44
ChallengeProgress: inventory.ChallengeProgress,
45
DeathMarks: inventory.DeathMarks,
46
Harvestable: inventory.Harvestable,
47
DeathSquadable: inventory.DeathSquadable,
48
Created: toMongoDate(inventory.Created),
49
MigratedToConsole: false,
50
Missions: inventory.Missions,
51
Affiliations: inventory.Affiliations,
52
DailyFocus: inventory.DailyFocus,
53
Wishlist: inventory.Wishlist,
54
Alignment: inventory.Alignment
55
};
56
await populateLoadout(inventory, result);
57
if (inventory.GuildId) {
58
const guild = (await Guild.findById(inventory.GuildId, "Name Tier XP Class Emblem"))!;
59
populateGuild(guild, result);
60
}
61
for (const key of allDailyAffiliationKeys) {
62
result[key] = inventory[key];
63
}
34
const result: IPlayerProfileViewingDataResult = {
35
AccountId: toOid(account._id),
36
DisplayName: account.DisplayName,
37
PlayerLevel: inventory.PlayerLevel,
38
LoadOutInventory: {
39
WeaponSkins: [],
40
XPInfo: inventory.XPInfo
41
},
42
PlayerSkills: inventory.PlayerSkills,
43
ChallengeProgress: inventory.ChallengeProgress,
44
DeathMarks: inventory.DeathMarks,
45
Harvestable: inventory.Harvestable,
46
DeathSquadable: inventory.DeathSquadable,
47
Created: toMongoDate(inventory.Created),
48
MigratedToConsole: false,
49
Missions: inventory.Missions,
50
Affiliations: inventory.Affiliations,
51
DailyFocus: inventory.DailyFocus,
52
Wishlist: inventory.Wishlist,
53
Alignment: inventory.Alignment
54
};
55
await populateLoadout(inventory, result);
56
if (inventory.GuildId) {
57
const guild = (await Guild.findById(inventory.GuildId, "Name Tier XP Class Emblem"))!;
58
populateGuild(guild, result);
59
}
60
for (const key of allDailyAffiliationKeys) {
61
result[key] = inventory[key];
62
}
64
63
65
const stats = (await Stats.findOne({ accountOwnerId: account._id }))!.toJSON<Partial<TStatsDatabaseDocument>>();
66
delete stats._id;
67
delete stats.__v;
68
delete stats.accountOwnerId;
64
const stats = (await Stats.findOne({ accountOwnerId: account._id }))!.toJSON<Partial<TStatsDatabaseDocument>>();
65
delete stats._id;
66
delete stats.__v;
67
delete stats.accountOwnerId;
69
68
70
res.json({
71
Results: [result],
72
TechProjects: [],
73
XpComponents: [],
74
//XpCacheExpiryDate, some IMongoDate in the future, no clue what it's for
75
Stats: stats
76
});
69
return {
70
Results: [result],
71
TechProjects: [],
72
XpComponents: [],
73
//XpCacheExpiryDate, some IMongoDate in the future, no clue what it's for
74
Stats: stats
75
};
76
};
77
78
export const getProfileViewingDataGetController: RequestHandler = async (req, res) => {
79
if (req.query.playerId) {
80
const data = await getProfileViewingDataByPlayerIdImpl(req.query.playerId as string);
81
if (data) {
82
res.json(data);
83
} else {
84
res.status(409).send("Could not find requested account");
85
}
77
86
} else if (req.query.guildId) {
78
87
const guild = await Guild.findById(req.query.guildId, "Name Tier XP Class Emblem TechProjects ClaimedXP");
79
88
if (!guild) {
@@ -170,6 +179,28 @@ export const getProfileViewingDataController: RequestHandler = async (req, res)
170
179
}
171
180
};
172
181
182
// For old versions, this was an authenticated POST request.
183
interface IGetProfileViewingDataRequest {
184
AccountId: string;
185
}
186
export const getProfileViewingDataPostController: RequestHandler = async (req, res) => {
187
const payload = getJSONfromString<IGetProfileViewingDataRequest>(String(req.body));
188
const data = await getProfileViewingDataByPlayerIdImpl(payload.AccountId);
189
if (data) {
190
res.json(data);
191
} else {
192
res.status(409).send("Could not find requested account");
193
}
194
};
195
196
interface IProfileViewingData {
197
Results: IPlayerProfileViewingDataResult[];
198
TechProjects: [];
199
XpComponents: [];
200
//XpCacheExpiryDate, some IMongoDate in the future, no clue what it's for
201
Stats: FlattenMaps<Partial<TStatsDatabaseDocument>>;
202
}
203
173
204
interface IPlayerProfileViewingDataResult extends Partial<IDailyAffiliations> {
174
205
AccountId: IOid;
175
206
DisplayName: string;
@@ -59,6 +59,7 @@ import { getGuildDojoController } from "@/src/controllers/api/getGuildDojoContro
59
59
import { getGuildLogController } from "@/src/controllers/api/getGuildLogController";
60
60
import { getIgnoredUsersController } from "@/src/controllers/api/getIgnoredUsersController";
61
61
import { getNewRewardSeedController } from "@/src/controllers/api/getNewRewardSeedController";
62
import { getProfileViewingDataPostController } from "@/src/controllers/dynamic/getProfileViewingDataController";
62
63
import { getShipController } from "@/src/controllers/api/getShipController";
63
64
import { getVendorInfoController } from "@/src/controllers/api/getVendorInfoController";
64
65
import { getVoidProjectionRewardsController } from "@/src/controllers/api/getVoidProjectionRewardsController";
@@ -247,6 +248,7 @@ apiRouter.post("/genericUpdate.php", genericUpdateController);
247
248
apiRouter.post("/getAlliance.php", getAllianceController);
248
249
apiRouter.post("/getFriends.php", getFriendsController);
249
250
apiRouter.post("/getGuildDojo.php", getGuildDojoController);
251
apiRouter.post("/getProfileViewingData.php", getProfileViewingDataPostController);
250
252
apiRouter.post("/getVoidProjectionRewards.php", getVoidProjectionRewardsController);
251
253
apiRouter.post("/gifting.php", giftingController);
252
254
apiRouter.post("/gildWeapon.php", gildWeaponController);
@@ -1,14 +1,14 @@
1
1
import express from "express";
2
2
import { aggregateSessionsController } from "@/src/controllers/dynamic/aggregateSessionsController";
3
3
import { getGuildAdsController } from "@/src/controllers/dynamic/getGuildAdsController";
4
import { getProfileViewingDataController } from "@/src/controllers/dynamic/getProfileViewingDataController";
4
import { getProfileViewingDataGetController } from "@/src/controllers/dynamic/getProfileViewingDataController";
5
5
import { worldStateController } from "@/src/controllers/dynamic/worldStateController";
6
6
7
7
const dynamicController = express.Router();
8
8
9
9
dynamicController.get("/aggregateSessions.php", aggregateSessionsController);
10
10
dynamicController.get("/getGuildAds.php", getGuildAdsController);
11
dynamicController.get("/getProfileViewingData.php", getProfileViewingDataController);
11
dynamicController.get("/getProfileViewingData.php", getProfileViewingDataGetController);
12
12
dynamicController.get("/worldState.php", worldStateController);
13
13
14
14
export { dynamicController };