XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

SpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 1 Star 0
返回提交历史

XFEstudio/SpaceNinjaServer

chore: use strings for findSessions response (#3107)

Types.ObjectId does JSON-stringify in the same way, but I think being explicit here is a bit more sane. Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3107 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

07fcf6fe
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

3 个文件 +18 -10
Modified src/controllers/api/findSessionsController.ts +2 -2
@@ -8,9 +8,9 @@ export const findSessionsController: RequestHandler = (_req, res) => {
8 8 logger.debug("FindSession Request ", req);
9 9 if (req.id != undefined) {
10 10 logger.debug("Found ID");
11 const session = getSession(req.id);
11 const sessions = getSession(req.id);
12 12
13 if (session.length) res.json({ queryId: req.queryId, Sessions: session });
13 if (sessions.length) res.json({ queryId: req.queryId, Sessions: sessions });
14 14 else res.json({});
15 15 } else if (req.originalSessionId != undefined) {
16 16 logger.debug("Found OriginalSessionID");
Modified src/managers/sessionManager.ts +6 -8
@@ -1,4 +1,4 @@
1 import type { ISession, IFindSessionRequest } from "../types/session.ts";
1 import type { ISession, IFindSessionRequest, IFindSessionResponseSession } from "../types/session.ts";
2 2 import { logger } from "../utils/logger.ts";
3 3 import { JSONParse } from "json-with-bigint";
4 4 import { Types } from "mongoose";
@@ -46,17 +46,15 @@ function getSessionByID(sessionId: string | Types.ObjectId): ISession | undefine
46 46 return sessions.find(session => session.sessionId.equals(sessionId));
47 47 }
48 48
49 function getSession(
50 sessionIdOrRequest: string | Types.ObjectId | IFindSessionRequest
51 ): { createdBy: Types.ObjectId; id: Types.ObjectId }[] {
49 function getSession(sessionIdOrRequest: string | Types.ObjectId | IFindSessionRequest): IFindSessionResponseSession[] {
52 50 if (typeof sessionIdOrRequest === "string" || sessionIdOrRequest instanceof Types.ObjectId) {
53 51 const session = sessions.find(session => session.sessionId.equals(sessionIdOrRequest));
54 52 if (session) {
55 53 logger.debug("Found Sessions:", { session });
56 54 return [
57 55 {
58 createdBy: session.creatorId,
59 id: session.sessionId
56 createdBy: session.creatorId.toString(),
57 id: session.sessionId.toString()
60 58 }
61 59 ];
62 60 }
@@ -78,8 +76,8 @@ function getSession(
78 76 return true;
79 77 });
80 78 return matchingSessions.map(session => ({
81 createdBy: session.creatorId,
82 id: session.sessionId
79 createdBy: session.creatorId.toString(),
80 id: session.sessionId.toString()
83 81 }));
84 82 }
85 83
Modified src/types/session.ts +10 -0
@@ -40,3 +40,13 @@ export interface IFindSessionRequest {
40 40 xplatform?: boolean;
41 41 queryId?: number;
42 42 }
43
44 export interface IFindSessionResponse {
45 queryId: number;
46 Sesions: IFindSessionResponseSession[];
47 }
48
49 export interface IFindSessionResponseSession {
50 createdBy: string;
51 id: string;
52 }