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: add toLegacyDate (#3922)

Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3922 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

28400ca0
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

2 个文件 +14 -5
Modified src/controllers/api/inventoryController.ts +4 -4
@@ -48,9 +48,9 @@ import {
48 48 convertIColorToLegacyColors,
49 49 convertIColorToLegacyColorsWithAtt,
50 50 convertToLegacyFingerprint,
51 fromMongoDate,
52 51 fromOid,
53 52 modernToU5Recipes,
53 toLegacyDate,
54 54 toLegacyOid,
55 55 toMongoDate2,
56 56 toOid,
@@ -740,10 +740,10 @@ export const getInventoryResponse = async (
740 740 }
741 741 // as well as a different date format
742 742 for (const pr of inventoryResponse.PendingRecipes) {
743 pr.CompletionDate = toMongoDate2(fromMongoDate(pr.CompletionDate), buildLabel);
743 toLegacyDate(pr.CompletionDate);
744 744 }
745 inventoryResponse.TrainingDate = toMongoDate2(inventory.TrainingDate, buildLabel);
746 inventoryResponse.NextRefill = toMongoDate2(inventory.NextRefill!, buildLabel);
745 toLegacyDate(inventoryResponse.TrainingDate);
746 toLegacyDate(inventoryResponse.NextRefill!);
747 747
748 748 if (version_compare(buildLabel, "2014.02.05.00.00") < 0) {
749 749 // Pre-U12 builds store mods in an array called Cards, and have no concept of RawUpgrades
Modified src/helpers/inventoryHelpers.ts +10 -1
@@ -53,12 +53,21 @@ export function toMongoDate2(value: Date | number, buildLabel: string | undefine
53 53 }
54 54
55 55 export const toLegacyOid = (oid: IOidWithLegacySupport): void => {
56 if (!("$id" in oid)) {
56 if ("$oid" in oid) {
57 57 oid.$id = oid.$oid;
58 58 delete oid.$oid;
59 59 }
60 60 };
61 61
62 export const toLegacyDate = (date: IMongoDateWithLegacySupport): void => {
63 if ("$date" in date) {
64 const ms = parseInt(date.$date.$numberLong);
65 delete (date as unknown as { $date?: never }).$date;
66 (date as { sec?: number }).sec = Math.floor(ms / 1000);
67 (date as { usec?: number }).usec = (ms % 1000) * 1000;
68 }
69 };
70
62 71 export const fromOid = (oid: IOidWithLegacySupport): string => {
63 72 return (oid.$oid ?? oid.$id)!;
64 73 };