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