返回提交历史
Modified
src/controllers/stats/uploadController.ts
+5
-4
Modified
src/controllers/stats/viewController.ts
+2
-2
Modified
src/models/statsModel.ts
+12
-2
Modified
src/services/statsService.ts
+361
-237
Modified
src/types/statTypes.ts
+12
-4
XFEstudio/SpaceNinjaServer
feat(stats): log unknown categories in updateStats (#947)
Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/947 Reviewed-by: Sainan <sainan@calamity.inc> Co-authored-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com> Co-committed-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com>
2dade02f
代码差异
5 个文件
+392
-249
@@ -1,14 +1,15 @@
1
1
import { getJSONfromString } from "@/src/helpers/stringHelpers";
2
2
import { getAccountIdForRequest } from "@/src/services/loginService";
3
import { getStats, uploadStats } from "@/src/services/statsService";
4
import { IStatsUpload } from "@/src/types/statTypes";
3
import { getStats, updateStats } from "@/src/services/statsService";
4
import { IStatsUpdate } from "@/src/types/statTypes";
5
5
import { RequestHandler } from "express";
6
6
7
7
const uploadController: RequestHandler = async (req, res) => {
8
const payload = getJSONfromString<IStatsUpload>(String(req.body));
8
// eslint-disable-next-line @typescript-eslint/no-unused-vars
9
const { PS, ...payload } = getJSONfromString<IStatsUpdate>(String(req.body));
9
10
const accountId = await getAccountIdForRequest(req);
10
11
const playerStats = await getStats(accountId);
11
await uploadStats(playerStats, payload);
12
await updateStats(playerStats, payload);
12
13
res.status(200).end();
13
14
};
14
15
@@ -5,14 +5,14 @@ import allScans from "@/static/fixed_responses/allScans.json";
5
5
import { ExportEnemies } from "warframe-public-export-plus";
6
6
import { getInventory } from "@/src/services/inventoryService";
7
7
import { getStats } from "@/src/services/statsService";
8
import { IStatsView } from "@/src/types/statTypes";
8
import { IStatsClient } from "@/src/types/statTypes";
9
9
10
10
const viewController: RequestHandler = async (req, res) => {
11
11
const accountId = await getAccountIdForRequest(req);
12
12
const inventory = await getInventory(accountId, "XPInfo");
13
13
const playerStats = await getStats(accountId);
14
14
15
const responseJson: IStatsView = playerStats.toJSON();
15
const responseJson = playerStats.toJSON() as IStatsClient;
16
16
responseJson.Weapons ??= [];
17
17
for (const item of inventory.XPInfo) {
18
18
const weaponIndex = responseJson.Weapons.findIndex(element => element.type == item.ItemType);
@@ -1,5 +1,5 @@
1
1
import { Document, Schema, Types, model } from "mongoose";
2
import { IEnemy, IMission, IScan, ITutorial, IAbility, IWeapon, IStatsDatabase } from "@/src/types/statTypes";
2
import { IEnemy, IMission, IScan, ITutorial, IAbility, IWeapon, IStatsDatabase, IRace } from "@/src/types/statTypes";
3
3
4
4
const abilitySchema = new Schema<IAbility>(
5
5
{
@@ -58,6 +58,13 @@ const weaponSchema = new Schema<IWeapon>(
58
58
{ _id: false }
59
59
);
60
60
61
const raceSchema = new Schema<IRace>(
62
{
63
highScore: Number
64
},
65
{ _id: false }
66
);
67
61
68
const statsSchema = new Schema<IStatsDatabase>({
62
69
accountOwnerId: { type: Schema.Types.ObjectId, required: true },
63
70
CiphersSolved: Number,
@@ -69,6 +76,8 @@ const statsSchema = new Schema<IStatsDatabase>({
69
76
MissionsCompleted: Number,
70
77
MissionsQuit: Number,
71
78
MissionsFailed: Number,
79
MissionsInterrupted: Number,
80
MissionsDumped: Number,
72
81
TimePlayedSec: Number,
73
82
PickupCount: Number,
74
83
Tutorial: { type: Map, of: tutorialSchema, default: {} },
@@ -81,7 +90,8 @@ const statsSchema = new Schema<IStatsDatabase>({
81
90
Missions: { type: [missionSchema], default: [] },
82
91
Deaths: Number,
83
92
HealCount: Number,
84
ReviveCount: Number
93
ReviveCount: Number,
94
Races: { type: Map, of: raceSchema, default: {} }
85
95
});
86
96
87
97
statsSchema.set("toJSON", {
@@ -1,6 +1,6 @@
1
1
import { Types } from "mongoose";
2
2
3
export interface IStatsView {
3
export interface IStatsClient {
4
4
CiphersSolved?: number;
5
5
CiphersFailed?: number;
6
6
CipherTime?: number;
@@ -10,9 +10,11 @@ export interface IStatsView {
10
10
MissionsCompleted?: number;
11
11
MissionsQuit?: number;
12
12
MissionsFailed?: number;
13
MissionsInterrupted?: number;
14
MissionsDumped?: number;
13
15
TimePlayedSec?: number;
14
16
PickupCount?: number;
15
Tutorial?: { [key: string]: ITutorial };
17
Tutorial?: Map<string, ITutorial>;
16
18
Abilities?: IAbility[];
17
19
Rating?: number;
18
20
Income?: number;
@@ -23,9 +25,10 @@ export interface IStatsView {
23
25
Deaths?: number;
24
26
HealCount?: number;
25
27
ReviveCount?: number;
28
Races?: Map<string, IRace>;
26
29
}
27
30
28
export interface IStatsDatabase extends IStatsView {
31
export interface IStatsDatabase extends IStatsClient {
29
32
accountOwnerId: Types.ObjectId;
30
33
}
31
34
@@ -68,7 +71,11 @@ export interface IWeapon {
68
71
fired?: number;
69
72
}
70
73
71
export interface IStatsUpload {
74
export interface IRace {
75
highScore: number;
76
}
77
78
export interface IStatsUpdate {
72
79
displayName: string;
73
80
guildId?: string;
74
81
PS?: string;
@@ -128,6 +135,7 @@ export interface IUploadEntry {
128
135
export interface IStatsMax {
129
136
WEAPON_XP?: IUploadEntry;
130
137
MISSION_SCORE?: IUploadEntry;
138
RACE_SCORE?: IUploadEntry;
131
139
}
132
140
133
141
export interface IStatsSet {