返回提交历史
Modified
src/controllers/custom/importController.ts
+10
-5
Modified
src/services/importService.ts
+1
-45
XFEstudio/XFESpaceNinjaServer
chore: ask mongoose if import did anything (#3047)
Partially reverting 71785fffd7f7889264603d60bdbc963c405d81b8 for a much simpler solution. Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3047 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
4353f291
代码差异
2 个文件
+11
-50
@@ -15,16 +15,19 @@ export const importController: RequestHandler = async (req, res) => {
15
15
let anyKnownKey = false;
16
16
try {
17
17
const inventory = await getInventory(accountId);
18
if (importInventory(inventory, request.inventory)) {
18
importInventory(inventory, request.inventory);
19
if (inventory.isModified()) {
19
20
anyKnownKey = true;
20
21
await inventory.save();
21
22
}
22
23
23
24
if ("LoadOutPresets" in request.inventory && request.inventory.LoadOutPresets) {
24
anyKnownKey = true;
25
25
const loadout = await getLoadout(accountId);
26
26
importLoadOutPresets(loadout, request.inventory.LoadOutPresets);
27
await loadout.save();
27
if (loadout.isModified()) {
28
anyKnownKey = true;
29
await loadout.save();
30
}
28
31
}
29
32
30
33
if (
@@ -32,10 +35,12 @@ export const importController: RequestHandler = async (req, res) => {
32
35
"Apartment" in request.inventory ||
33
36
"TailorShop" in request.inventory
34
37
) {
35
anyKnownKey = true;
36
38
const personalRooms = await getPersonalRooms(accountId);
37
39
importPersonalRooms(personalRooms, request.inventory);
38
await personalRooms.save();
40
if (personalRooms.isModified()) {
41
anyKnownKey = true;
42
await personalRooms.save();
43
}
39
44
}
40
45
41
46
if (!anyKnownKey) {
@@ -254,21 +254,17 @@ const convertItemConfig = <T extends IItemConfig>(client: T): T => {
254
254
};
255
255
};
256
256
257
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): boolean => {
258
let anyKnownKey = false;
257
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
259
258
for (const key of equipmentKeys) {
260
259
if (client[key] !== undefined) {
261
anyKnownKey = true;
262
260
replaceArray<IEquipmentDatabase>(db[key], client[key].map(convertEquipment));
263
261
}
264
262
}
265
263
if (client.WeaponSkins !== undefined) {
266
anyKnownKey = true;
267
264
replaceArray<IWeaponSkinDatabase>(db.WeaponSkins, client.WeaponSkins.map(convertWeaponSkin));
268
265
}
269
266
for (const key of ["Upgrades", "CrewShipSalvagedWeaponSkins", "CrewShipWeaponSkins"] as const) {
270
267
if (client[key] !== undefined) {
271
anyKnownKey = true;
272
268
replaceArray<IUpgradeDatabase>(db[key], client[key].map(convertUpgrade));
273
269
}
274
270
}
@@ -284,7 +280,6 @@ export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<
284
280
"CrewShipRawSalvage"
285
281
] as const) {
286
282
if (client[key] !== undefined) {
287
anyKnownKey = true;
288
283
db[key].splice(0, db[key].length);
289
284
client[key].forEach(x => {
290
285
db[key].push({
@@ -296,13 +291,11 @@ export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<
296
291
}
297
292
for (const key of ["AdultOperatorLoadOuts", "OperatorLoadOuts", "KahlLoadOuts"] as const) {
298
293
if (client[key] !== undefined) {
299
anyKnownKey = true;
300
294
replaceArray<IOperatorConfigDatabase>(db[key], client[key].map(convertOperatorConfig));
301
295
}
302
296
}
303
297
for (const key of slotNames) {
304
298
if (client[key] !== undefined) {
305
anyKnownKey = true;
306
299
replaceSlots(db[key], client[key]);
307
300
}
308
301
}
@@ -319,7 +312,6 @@ export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<
319
312
"Counselor"
320
313
] as const) {
321
314
if (client[key] !== undefined) {
322
anyKnownKey = true;
323
315
db[key] = client[key];
324
316
}
325
317
}
@@ -346,7 +338,6 @@ export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<
346
338
"EchoesHexConquestCacheScoreMission"
347
339
] as const) {
348
340
if (client[key] !== undefined) {
349
anyKnownKey = true;
350
341
db[key] = client[key];
351
342
}
352
343
}
@@ -362,7 +353,6 @@ export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<
362
353
"ActiveAvatarImageType"
363
354
] as const) {
364
355
if (client[key] !== undefined) {
365
anyKnownKey = true;
366
356
db[key] = client[key];
367
357
}
368
358
}
@@ -379,7 +369,6 @@ export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<
379
369
"EchoesHexConquestActiveStickers"
380
370
] as const) {
381
371
if (client[key] !== undefined) {
382
anyKnownKey = true;
383
372
db[key] = client[key];
384
373
}
385
374
}
@@ -393,133 +382,103 @@ export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<
393
382
"EntratiVaultCountResetDate"
394
383
] as const) {
395
384
if (client[key] !== undefined) {
396
anyKnownKey = true;
397
385
db[key] = fromMongoDate(client[key]);
398
386
}
399
387
}
400
388
// IRewardAtten[]
401
389
for (const key of ["SortieRewardAttenuation", "SpecialItemRewardAttenuation"] as const) {
402
390
if (client[key] !== undefined) {
403
anyKnownKey = true;
404
391
db[key] = client[key];
405
392
}
406
393
}
407
394
if (client.XPInfo !== undefined) {
408
anyKnownKey = true;
409
395
db.XPInfo = client.XPInfo;
410
396
}
411
397
if (client.CurrentLoadOutIds !== undefined) {
412
anyKnownKey = true;
413
398
db.CurrentLoadOutIds = client.CurrentLoadOutIds;
414
399
}
415
400
if (client.Affiliations !== undefined) {
416
anyKnownKey = true;
417
401
db.Affiliations = client.Affiliations;
418
402
}
419
403
if (client.FusionTreasures !== undefined) {
420
anyKnownKey = true;
421
404
db.FusionTreasures = client.FusionTreasures;
422
405
}
423
406
if (client.FocusUpgrades !== undefined) {
424
anyKnownKey = true;
425
407
db.FocusUpgrades = client.FocusUpgrades;
426
408
}
427
409
if (client.EvolutionProgress !== undefined) {
428
anyKnownKey = true;
429
410
db.EvolutionProgress = client.EvolutionProgress;
430
411
}
431
412
if (client.InfestedFoundry !== undefined) {
432
anyKnownKey = true;
433
413
db.InfestedFoundry = convertInfestedFoundry(client.InfestedFoundry);
434
414
}
435
415
if (client.DialogueHistory !== undefined) {
436
anyKnownKey = true;
437
416
db.DialogueHistory = convertDialogueHistory(client.DialogueHistory);
438
417
}
439
418
if (client.CustomMarkers !== undefined) {
440
anyKnownKey = true;
441
419
db.CustomMarkers = client.CustomMarkers;
442
420
}
443
421
if (client.ChallengeProgress !== undefined) {
444
anyKnownKey = true;
445
422
db.ChallengeProgress = client.ChallengeProgress;
446
423
}
447
424
if (client.QuestKeys !== undefined) {
448
anyKnownKey = true;
449
425
replaceArray<IQuestKeyDatabase>(db.QuestKeys, client.QuestKeys.map(convertQuestKey));
450
426
}
451
427
if (client.LastRegionPlayed !== undefined) {
452
anyKnownKey = true;
453
428
db.LastRegionPlayed = client.LastRegionPlayed;
454
429
}
455
430
if (client.PendingRecipes !== undefined) {
456
anyKnownKey = true;
457
431
replaceArray<IPendingRecipeDatabase>(db.PendingRecipes, client.PendingRecipes.map(convertPendingRecipe));
458
432
}
459
433
if (client.TauntHistory !== undefined) {
460
anyKnownKey = true;
461
434
db.TauntHistory = client.TauntHistory;
462
435
}
463
436
if (client.LoreFragmentScans !== undefined) {
464
anyKnownKey = true;
465
437
db.LoreFragmentScans = client.LoreFragmentScans;
466
438
}
467
439
for (const key of ["PendingSpectreLoadouts", "SpectreLoadouts"] as const) {
468
440
if (client[key] !== undefined) {
469
anyKnownKey = true;
470
441
db[key] = client[key];
471
442
}
472
443
}
473
444
if (client.FocusXP !== undefined) {
474
anyKnownKey = true;
475
445
db.FocusXP = client.FocusXP;
476
446
}
477
447
for (const key of ["Alignment", "AlignmentReplay"] as const) {
478
448
if (client[key] !== undefined) {
479
anyKnownKey = true;
480
449
db[key] = client[key];
481
450
}
482
451
}
483
452
if (client.StepSequencers !== undefined) {
484
anyKnownKey = true;
485
453
db.StepSequencers = client.StepSequencers;
486
454
}
487
455
if (client.CompletedJobChains !== undefined) {
488
anyKnownKey = true;
489
456
db.CompletedJobChains = client.CompletedJobChains;
490
457
}
491
458
if (client.Nemesis !== undefined) {
492
anyKnownKey = true;
493
459
db.Nemesis = convertNemesis(client.Nemesis);
494
460
}
495
461
if (client.PlayerSkills !== undefined) {
496
anyKnownKey = true;
497
462
db.PlayerSkills = client.PlayerSkills;
498
463
}
499
464
if (client.LotusCustomization !== undefined) {
500
anyKnownKey = true;
501
465
db.LotusCustomization = convertItemConfig(client.LotusCustomization);
502
466
}
503
467
if (client.CollectibleSeries !== undefined) {
504
anyKnownKey = true;
505
468
db.CollectibleSeries = client.CollectibleSeries;
506
469
}
507
470
for (const key of ["LibraryAvailableDailyTaskInfo", "LibraryActiveDailyTaskInfo"] as const) {
508
471
if (client[key] !== undefined) {
509
anyKnownKey = true;
510
472
db[key] = client[key];
511
473
}
512
474
}
513
475
if (client.SongChallenges !== undefined) {
514
anyKnownKey = true;
515
476
db.SongChallenges = client.SongChallenges;
516
477
}
517
478
if (client.Missions !== undefined) {
518
anyKnownKey = true;
519
479
db.Missions = client.Missions;
520
480
}
521
481
if (client.FlavourItems !== undefined) {
522
anyKnownKey = true;
523
482
db.FlavourItems.splice(0, db.FlavourItems.length);
524
483
client.FlavourItems.forEach(x => {
525
484
db.FlavourItems.push({
@@ -528,14 +487,11 @@ export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<
528
487
});
529
488
}
530
489
if (client.Accolades !== undefined) {
531
anyKnownKey = true;
532
490
db.Accolades = client.Accolades;
533
491
}
534
492
if (client.Boosters !== undefined) {
535
anyKnownKey = true;
536
493
replaceArray<IBooster>(db.Boosters, client.Boosters);
537
494
}
538
return anyKnownKey;
539
495
};
540
496
541
497
export const importLoadOutConfig = (client: ILoadoutConfigClient): ILoadoutConfigDatabase => {