chore: some initial handling of legacy oid format #2033
@ -29,6 +29,7 @@ import { version_compare } from "@/src/services/worldStateService";
 | 
			
		||||
import { getPersonalRooms } from "@/src/services/personalRoomsService";
 | 
			
		||||
import { IPersonalRoomsClient } from "@/src/types/personalRoomsTypes";
 | 
			
		||||
import { Ship } from "@/src/models/shipModel";
 | 
			
		||||
import { toLegacyOid } from "@/src/helpers/inventoryHelpers";
 | 
			
		||||
 | 
			
		||||
export const inventoryController: RequestHandler = async (request, response) => {
 | 
			
		||||
    const account = await getAccountForRequest(request);
 | 
			
		||||
@ -306,19 +307,29 @@ export const getInventoryResponse = async (
 | 
			
		||||
    // Set 2FA enabled so trading post can be used
 | 
			
		||||
    inventoryResponse.HWIDProtectEnabled = true;
 | 
			
		||||
 | 
			
		||||
    if (buildLabel) {
 | 
			
		||||
        // Fix nemesis for older versions
 | 
			
		||||
    if (
 | 
			
		||||
        inventoryResponse.Nemesis &&
 | 
			
		||||
        buildLabel &&
 | 
			
		||||
        !isNemesisCompatibleWithVersion(inventoryResponse.Nemesis, buildLabel)
 | 
			
		||||
    ) {
 | 
			
		||||
        if (inventoryResponse.Nemesis && !isNemesisCompatibleWithVersion(inventoryResponse.Nemesis, buildLabel)) {
 | 
			
		||||
            inventoryResponse.Nemesis = undefined;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    if (buildLabel && version_compare(buildLabel, "2018.02.22.14.34") < 0) {
 | 
			
		||||
        if (version_compare(buildLabel, "2018.02.22.14.34") < 0) {
 | 
			
		||||
            const personalRoomsDb = await getPersonalRooms(inventory.accountOwnerId.toString());
 | 
			
		||||
            const personalRooms = personalRoomsDb.toJSON<IPersonalRoomsClient>();
 | 
			
		||||
            inventoryResponse.Ship = personalRooms.Ship;
 | 
			
		||||
 | 
			
		||||
            if (version_compare(buildLabel, "2017.03.06.15.49") < 0) {
 | 
			
		||||
                // U19.4 and below use $id instead of $oid
 | 
			
		||||
                for (const category of equipmentKeys) {
 | 
			
		||||
                    for (const item of inventoryResponse[category]) {
 | 
			
		||||
                        toLegacyOid(item.ItemId);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                for (const upgrade of inventoryResponse.Upgrades) {
 | 
			
		||||
                    toLegacyOid(upgrade.ItemId);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return inventoryResponse;
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
import { IMongoDate, IOid } from "@/src/types/commonTypes";
 | 
			
		||||
import { IMongoDate, IOid, IOidWithLegacySupport } from "@/src/types/commonTypes";
 | 
			
		||||
import { Types } from "mongoose";
 | 
			
		||||
import { TRarity } from "warframe-public-export-plus";
 | 
			
		||||
 | 
			
		||||
@ -6,6 +6,17 @@ export const toOid = (objectId: Types.ObjectId): IOid => {
 | 
			
		||||
    return { $oid: objectId.toString() } satisfies IOid;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const toLegacyOid = (oid: IOidWithLegacySupport): void => {
 | 
			
		||||
    if (!("$id" in oid)) {
 | 
			
		||||
        oid.$id = oid.$oid;
 | 
			
		||||
        delete oid.$oid;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const fromOid = (oid: IOidWithLegacySupport): string => {
 | 
			
		||||
    return (oid.$oid ?? oid.$id)!;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const toMongoDate = (date: Date): IMongoDate => {
 | 
			
		||||
    return { $date: { $numberLong: date.getTime().toString() } };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -70,6 +70,7 @@ import { createShip } from "./shipService";
 | 
			
		||||
import {
 | 
			
		||||
    catbrowDetails,
 | 
			
		||||
    fromMongoDate,
 | 
			
		||||
    fromOid,
 | 
			
		||||
    kubrowDetails,
 | 
			
		||||
    kubrowFurPatternsWeights,
 | 
			
		||||
    kubrowWeights,
 | 
			
		||||
@ -1491,9 +1492,9 @@ export const applyClientEquipmentUpdates = (
 | 
			
		||||
    const category = inventory[categoryName];
 | 
			
		||||
 | 
			
		||||
    gearArray.forEach(({ ItemId, XP, InfestationDate }) => {
 | 
			
		||||
        const item = category.id(ItemId.$oid);
 | 
			
		||||
        const item = category.id(fromOid(ItemId));
 | 
			
		||||
        if (!item) {
 | 
			
		||||
            throw new Error(`No item with id ${ItemId.$oid} in ${categoryName}`);
 | 
			
		||||
            throw new Error(`No item with id ${fromOid(ItemId)} in ${categoryName}`);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (XP) {
 | 
			
		||||
 | 
			
		||||
@ -62,6 +62,7 @@ import { getLiteSortie, getSortie, idToBountyCycle, idToDay, idToWeek, pushClass
 | 
			
		||||
import { config } from "./configService";
 | 
			
		||||
import libraryDailyTasks from "@/static/fixed_responses/libraryDailyTasks.json";
 | 
			
		||||
import { ISyndicateMissionInfo } from "../types/worldStateTypes";
 | 
			
		||||
import { fromOid } from "../helpers/inventoryHelpers";
 | 
			
		||||
 | 
			
		||||
const getRotations = (rewardInfo: IRewardInfo, tierOverride?: number): number[] => {
 | 
			
		||||
    // For Spy missions, e.g. 3 vaults cracked = A, B, C
 | 
			
		||||
@ -399,7 +400,7 @@ export const addMissionInventoryUpdates = async (
 | 
			
		||||
                break;
 | 
			
		||||
            case "Upgrades":
 | 
			
		||||
                value.forEach(clientUpgrade => {
 | 
			
		||||
                    const upgrade = inventory.Upgrades.id(clientUpgrade.ItemId.$oid)!;
 | 
			
		||||
                    const upgrade = inventory.Upgrades.id(fromOid(clientUpgrade.ItemId))!;
 | 
			
		||||
                    upgrade.UpgradeFingerprint = clientUpgrade.UpgradeFingerprint; // primitive way to copy over the riven challenge progress
 | 
			
		||||
                });
 | 
			
		||||
                break;
 | 
			
		||||
 | 
			
		||||
@ -4,6 +4,11 @@ export interface IOid {
 | 
			
		||||
    $oid: string;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface IOidWithLegacySupport {
 | 
			
		||||
    $oid?: string;
 | 
			
		||||
    $id?: string;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface IMongoDate {
 | 
			
		||||
    $date: {
 | 
			
		||||
        $numberLong: string;
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
import { IMongoDate, IOid } from "@/src/types/commonTypes";
 | 
			
		||||
import { IMongoDate, IOid, IOidWithLegacySupport } from "@/src/types/commonTypes";
 | 
			
		||||
import { Types } from "mongoose";
 | 
			
		||||
import {
 | 
			
		||||
    ICrewShipCustomization,
 | 
			
		||||
@ -92,7 +92,7 @@ export interface IEquipmentClient
 | 
			
		||||
        IEquipmentDatabase,
 | 
			
		||||
        "_id" | "InfestationDate" | "Expiry" | "UpgradesExpiry" | "UmbraDate" | "CrewMembers" | "Details"
 | 
			
		||||
    > {
 | 
			
		||||
    ItemId: IOid;
 | 
			
		||||
    ItemId: IOidWithLegacySupport;
 | 
			
		||||
    InfestationDate?: IMongoDate;
 | 
			
		||||
    Expiry?: IMongoDate;
 | 
			
		||||
    UpgradesExpiry?: IMongoDate;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user