返回提交历史
Modified
.gitignore
+1
-0
Modified
config.json
+3
-1
Modified
src/controllers/api/getShipController.ts
+17
-3
Modified
src/controllers/api/inventoryController.ts
+6
-0
Modified
src/controllers/api/loginController.ts
+1
-0
Modified
src/models/inventoryModel.ts
+5
-4
Added
src/models/shipModel.ts
+46
-0
Modified
src/services/loginService.ts
+2
-0
Added
src/services/shipService.ts
+17
-0
Added
src/types/commonTypes.ts
+3
-0
Modified
src/types/inventoryTypes.ts
+4
-7
Added
src/types/shipTypes.ts
+29
-0
Added
static/fixed_responses/postShip.json
+33
-0
Added
static/fixed_responses/testMissions.json
+1471
-0
Added
static/fixed_responses/testQuestKeys.json
+11
-0
XFEstudio/SpaceNinjaServer
Add Ship (#13)
6520284c
代码差异
15 个文件
+1649
-15
@@ -3,3 +3,4 @@
3
3
4
4
/.env
5
5
/static/data/*
6
yarn.lock
@@ -5,5 +5,7 @@
5
5
"version": "33.0.14",
6
6
"worldSeed": "GWvLyHiw7/Qr/60056xmAmDrn0Y9et2S3BYlLSkLDNBMtumSr3KxWV8He5Jz72yYq3tsY+cd53QeTf+bb54+llGTbYiQF+64BtiLWMVhWP1IUaP4SxWHXojlpQC13op/udHI1whc+8zrxEzzZmv/QlpvigAAbjBDtwu97Df0vgn+YrOKi4G3OhgIkTRocAAzD1P/BGbT8gaKE01H8rXl3+Gq6jCA1O1v800SL6DwKOgMsXVvWp7g2n/tPxJe/j9bmu4XFG0bSa5y5hikLKxvntA/5ut+iogv4MyMBe+TydVxjPqNbkKnby5l4KAL+3inpuPraeg4jcNMt0AwKG8NIQ==",
7
7
"skipStoryModeChoice": true,
8
"skipTutorial": true
8
"skipTutorial": true,
9
"testMission": true,
10
"testQuestKey": true
9
11
}
@@ -1,8 +1,22 @@
1
import { Account } from "@/src/models/loginModel";
2
import { Ship } from "@/src/models/shipModel";
3
import { createShip } from "@/src/services/shipService";
1
4
import { RequestHandler } from "express";
2
import getShip from "@/static/fixed_responses/getShip.json";
3
5
4
const getShipController: RequestHandler = (_req, res) => {
5
res.json(getShip);
6
// eslint-disable-next-line @typescript-eslint/no-misused-promises
7
const getShipController: RequestHandler = async (_req, res) => {
8
const accountId = _req.query.accountId;
9
const ship = await Ship.findOne({ ShipOwnerId: accountId });
10
if (!ship) {
11
const account = await Account.findOne({ _id: accountId });
12
if (account) {
13
await createShip(account._id);
14
const new_ship = await Ship.findOne({ ShipOwnerId: accountId });
15
res.json(new_ship);
16
return;
17
}
18
}
19
res.json(ship);
6
20
};
7
21
8
22
export { getShipController };
@@ -2,6 +2,9 @@
2
2
import { toInventoryResponse } from "@/src/helpers/inventoryHelpers";
3
3
import { Inventory } from "@/src/models/inventoryModel";
4
4
import { Request, RequestHandler, Response } from "express";
5
import config from "@/config.json";
6
import testMissions from "@/static/fixed_responses/testMissions.json";
7
import testQuestKeys from "@/static/fixed_responses/testQuestKeys.json";
5
8
6
9
const inventoryController: RequestHandler = async (request: Request, response: Response) => {
7
10
const accountId = request.query.accountId;
@@ -23,6 +26,9 @@ const inventoryController: RequestHandler = async (request: Request, response: R
23
26
24
27
const inventoreResponse = toInventoryResponse(inventoryJSON);
25
28
29
if (config.testMission) inventoreResponse.Missions = testMissions;
30
if (config.testQuestKey) inventoreResponse.QuestKeys = testQuestKeys;
31
26
32
response.json(inventoreResponse);
27
33
};
28
34
@@ -9,6 +9,7 @@ import { createAccount, isCorrectPassword } from "@/src/services/loginService";
9
9
import { ILoginResponse } from "@/src/types/loginTypes";
10
10
import { DTLS, groups, HUB, IRC, Nonce, NRS, platformCDNs } from "@/static/fixed_responses/login_static";
11
11
12
// eslint-disable-next-line @typescript-eslint/no-misused-promises
12
13
const loginController: RequestHandler = async (request, response) => {
13
14
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument
14
15
const body = JSON.parse(request.body); // parse octet stream of json data to json object
@@ -1,5 +1,6 @@
1
import { Document, Schema, model } from "mongoose";
2
import { IInventoryDatabase, IInventoryResponse, ISuitDatabase, ISuitDocument, Oid } from "../types/inventoryTypes";
1
import { Schema, model } from "mongoose";
2
import { IInventoryDatabase, ISuitDatabase } from "../types/inventoryTypes";
3
import { Oid } from "../types/commonTypes";
3
4
4
5
const polaritySchema = new Schema({
5
6
Slot: Number,
@@ -65,7 +66,7 @@ const suitSchema = new Schema({
65
66
});
66
67
67
68
suitSchema.set("toJSON", {
68
transform(_document, returnedObject: ISuitDocument) {
69
transform(_document, returnedObject) {
69
70
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
70
71
returnedObject.ItemId = { $oid: returnedObject._id.toString() } satisfies Oid;
71
72
delete returnedObject._id;
@@ -246,7 +247,7 @@ const inventorySchema = new Schema({
246
247
});
247
248
248
249
inventorySchema.set("toJSON", {
249
transform(_document, returnedObject: ISuitDocument) {
250
transform(_document, returnedObject) {
250
251
delete returnedObject._id;
251
252
delete returnedObject.__v;
252
253
}
@@ -0,0 +1,46 @@
1
import { Schema, model } from "mongoose";
2
import { IShipDatabase } from "../types/shipTypes";
3
import { Oid } from "../types/commonTypes";
4
5
const roomSchema = new Schema({
6
Name: String,
7
MaxCapacity: Number
8
});
9
10
roomSchema.set("toJSON", {
11
transform(_document, returnedObject) {
12
delete returnedObject._id;
13
}
14
});
15
16
const shipSchema = new Schema({
17
Rooms: [roomSchema],
18
Features: [Schema.Types.Mixed],
19
ContentUrlSignature: String
20
});
21
22
const apartmentSchema = new Schema({
23
Rooms: [roomSchema],
24
FavouriteLoadouts: [Schema.Types.Mixed]
25
});
26
27
const shipDatabaseSchema = new Schema({
28
ShipOwnerId: String,
29
Ship: shipSchema,
30
Apartment: apartmentSchema
31
});
32
33
shipDatabaseSchema.set("toJSON", {
34
transform(_document, returnedObject) {
35
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
36
returnedObject.Ship.ShipId = { $oid: returnedObject._id.toString() } satisfies Oid;
37
delete returnedObject._id;
38
delete returnedObject.Ship._id;
39
delete returnedObject.Apartment._id;
40
delete returnedObject.__v;
41
}
42
});
43
44
const Ship = model<IShipDatabase>("Ship", shipDatabaseSchema);
45
46
export { Ship };
@@ -1,6 +1,7 @@
1
1
import { Account } from "@/src/models/loginModel";
2
2
import { createInventory } from "@/src/services/inventoryService";
3
3
import { IDatabaseAccount } from "@/src/types/loginTypes";
4
import { createShip } from "./shipService";
4
5
5
6
const isCorrectPassword = (requestPassword: string, databasePassword: string): boolean => {
6
7
return requestPassword === databasePassword;
@@ -11,6 +12,7 @@ const createAccount = async (accountData: IDatabaseAccount) => {
11
12
try {
12
13
await account.save();
13
14
await createInventory(account._id);
15
await createShip(account._id);
14
16
return account.toJSON();
15
17
} catch (error) {
16
18
if (error instanceof Error) {
@@ -0,0 +1,17 @@
1
import { Ship } from "@/src/models/shipModel";
2
import new_ship from "@/static/fixed_responses/postShip.json";
3
import { Types } from "mongoose";
4
5
const createShip = async (accountOwnerId: Types.ObjectId) => {
6
try {
7
const ship = new Ship({ ...new_ship, ShipOwnerId: accountOwnerId });
8
await ship.save();
9
} catch (error) {
10
if (error instanceof Error) {
11
throw new Error(`error creating inventory" ${error.message}`);
12
}
13
throw new Error("error creating inventory that is not of instance Error");
14
}
15
};
16
17
export { createShip };
@@ -0,0 +1,3 @@
1
export interface Oid {
2
$oid: string;
3
}
@@ -1,6 +1,7 @@
1
1
/* eslint-disable @typescript-eslint/no-explicit-any */
2
2
3
3
import { Document, Types } from "mongoose";
4
import { Oid } from "./commonTypes";
4
5
5
6
export interface IInventoryDatabase extends IInventoryResponse {
6
7
accountOwnerId: Types.ObjectId;
@@ -187,10 +188,6 @@ export interface AdultOperatorLoadOut {
187
188
ItemId: Oid;
188
189
}
189
190
190
export interface Oid {
191
$oid: string;
192
}
193
194
191
export interface Color {
195
192
t0?: number;
196
193
t1?: number;
@@ -995,9 +992,9 @@ export interface PlayerSkills {
995
992
}
996
993
997
994
export interface QuestKey {
998
Progress: Progress[];
999
unlock: boolean;
1000
Completed: boolean;
995
Progress?: Progress[];
996
unlock?: boolean;
997
Completed?: boolean;
1001
998
ItemType: string;
1002
999
CompletionDate?: Date;
1003
1000
}
@@ -0,0 +1,29 @@
1
/* eslint-disable @typescript-eslint/no-explicit-any */
2
3
import { Types } from "mongoose";
4
import { Oid } from "./inventoryTypes";
5
6
export type IShipDatabase = IShipResponse;
7
8
export interface IShipResponse {
9
ShipOwnerId: Types.ObjectId;
10
Ship: IShipClass;
11
Apartment: IApartmentClass;
12
}
13
14
export interface IShipClass {
15
Rooms: IRoomsClass[];
16
ShipId: Oid;
17
Features: string[];
18
ContentUrlSignature: string;
19
}
20
21
export interface IRoomsClass {
22
Name: string;
23
MaxCapacity: number;
24
}
25
26
export interface IApartmentClass {
27
Rooms: IRoomsClass[];
28
FavouriteLoadouts: string[];
29
}