forked from OpenWF/SpaceNinjaServer
feat: getShip import (#2627)
Re #2592 Unsure about import note, is it okay that we leave the API path? Reviewed-on: OpenWF/SpaceNinjaServer#2627 Reviewed-by: Sainan <63328889+sainan@users.noreply.github.com> Co-authored-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com> Co-committed-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com>
This commit is contained in:
parent
ab214df1a8
commit
b0b68f474a
@ -1,8 +1,10 @@
|
||||
import { importInventory, importLoadOutPresets } from "@/src/services/importService";
|
||||
import { importInventory, importLoadOutPresets, importPersonalRooms } from "@/src/services/importService";
|
||||
import { getInventory } from "@/src/services/inventoryService";
|
||||
import { getLoadout } from "@/src/services/loadoutService";
|
||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||
import { getPersonalRooms } from "@/src/services/personalRoomsService";
|
||||
import { IInventoryClient } from "@/src/types/inventoryTypes/inventoryTypes";
|
||||
import { IGetShipResponse } from "@/src/types/personalRoomsTypes";
|
||||
import { RequestHandler } from "express";
|
||||
|
||||
export const importController: RequestHandler = async (req, res) => {
|
||||
@ -13,15 +15,21 @@ export const importController: RequestHandler = async (req, res) => {
|
||||
importInventory(inventory, request.inventory);
|
||||
await inventory.save();
|
||||
|
||||
if (request.inventory.LoadOutPresets) {
|
||||
if ("LoadOutPresets" in request.inventory && request.inventory.LoadOutPresets) {
|
||||
const loadout = await getLoadout(accountId);
|
||||
importLoadOutPresets(loadout, request.inventory.LoadOutPresets);
|
||||
await loadout.save();
|
||||
}
|
||||
|
||||
if ("Ship" in request.inventory || "Apartment" in request.inventory || "TailorShop" in request.inventory) {
|
||||
const personalRooms = await getPersonalRooms(accountId);
|
||||
importPersonalRooms(personalRooms, request.inventory);
|
||||
await personalRooms.save();
|
||||
}
|
||||
|
||||
res.end();
|
||||
};
|
||||
|
||||
interface IImportRequest {
|
||||
inventory: Partial<IInventoryClient>;
|
||||
inventory: Partial<IInventoryClient> | Partial<IGetShipResponse>;
|
||||
}
|
||||
|
@ -44,6 +44,22 @@ import {
|
||||
IKubrowPetDetailsClient,
|
||||
IKubrowPetDetailsDatabase
|
||||
} from "@/src/types/equipmentTypes";
|
||||
import {
|
||||
IApartmentClient,
|
||||
IApartmentDatabase,
|
||||
IFavouriteLoadout,
|
||||
IFavouriteLoadoutDatabase,
|
||||
IGetShipResponse,
|
||||
IOrbiterClient,
|
||||
IOrbiterDatabase,
|
||||
IPersonalRoomsDatabase,
|
||||
IPlantClient,
|
||||
IPlantDatabase,
|
||||
IPlanterClient,
|
||||
IPlanterDatabase,
|
||||
ITailorShop,
|
||||
ITailorShopDatabase
|
||||
} from "@/src/types/personalRoomsTypes";
|
||||
|
||||
const convertDate = (value: IMongoDate): Date => {
|
||||
return new Date(parseInt(value.$date.$numberLong));
|
||||
@ -429,3 +445,57 @@ export const importLoadOutPresets = (db: ILoadoutDatabase, client: ILoadOutPrese
|
||||
db.OPERATOR_ADULT = client.OPERATOR_ADULT.map(convertLoadOutConfig);
|
||||
db.DRIFTER = client.DRIFTER.map(convertLoadOutConfig);
|
||||
};
|
||||
|
||||
const convertShip = (client: IOrbiterClient): IOrbiterDatabase => {
|
||||
return {
|
||||
...client,
|
||||
ShipInterior: {
|
||||
...client.ShipInterior,
|
||||
Colors: Array.isArray(client.ShipInterior.Colors) ? {} : client.ShipInterior.Colors
|
||||
},
|
||||
FavouriteLoadoutId: client.FavouriteLoadoutId ? new Types.ObjectId(client.FavouriteLoadoutId.$oid) : undefined
|
||||
};
|
||||
};
|
||||
|
||||
const convertPlant = (client: IPlantClient): IPlantDatabase => {
|
||||
return {
|
||||
...client,
|
||||
EndTime: convertDate(client.EndTime)
|
||||
};
|
||||
};
|
||||
|
||||
const convertPlanter = (client: IPlanterClient): IPlanterDatabase => {
|
||||
return {
|
||||
...client,
|
||||
Plants: client.Plants.map(convertPlant)
|
||||
};
|
||||
};
|
||||
|
||||
const convertFavouriteLoadout = (client: IFavouriteLoadout): IFavouriteLoadoutDatabase => {
|
||||
return {
|
||||
...client,
|
||||
LoadoutId: new Types.ObjectId(client.LoadoutId.$oid)
|
||||
};
|
||||
};
|
||||
|
||||
const convertApartment = (client: IApartmentClient): IApartmentDatabase => {
|
||||
return {
|
||||
...client,
|
||||
Gardening: { Planters: client.Gardening.Planters.map(convertPlanter) },
|
||||
FavouriteLoadouts: client.FavouriteLoadouts ? client.FavouriteLoadouts.map(convertFavouriteLoadout) : []
|
||||
};
|
||||
};
|
||||
|
||||
const convertTailorShop = (client: ITailorShop): ITailorShopDatabase => {
|
||||
return {
|
||||
...client,
|
||||
Colors: Array.isArray(client.Colors) ? {} : client.Colors,
|
||||
FavouriteLoadouts: client.FavouriteLoadouts ? client.FavouriteLoadouts.map(convertFavouriteLoadout) : []
|
||||
};
|
||||
};
|
||||
|
||||
export const importPersonalRooms = (db: IPersonalRoomsDatabase, client: Partial<IGetShipResponse>): void => {
|
||||
if (client.Ship !== undefined) db.Ship = convertShip(client.Ship);
|
||||
if (client.Apartment !== undefined) db.Apartment = convertApartment(client.Apartment);
|
||||
if (client.TailorShop !== undefined) db.TailorShop = convertTailorShop(client.TailorShop);
|
||||
};
|
||||
|
@ -90,7 +90,7 @@ export interface IGardeningDatabase {
|
||||
export interface IApartmentClient {
|
||||
Gardening: IGardeningClient;
|
||||
Rooms: IRoom[];
|
||||
FavouriteLoadouts: IFavouriteLoadout[];
|
||||
FavouriteLoadouts?: IFavouriteLoadout[];
|
||||
VideoWallBackdrop?: string;
|
||||
Soundscape?: string;
|
||||
}
|
||||
@ -210,7 +210,7 @@ export interface ITailorShopDatabase {
|
||||
}
|
||||
|
||||
export interface ITailorShop extends Omit<ITailorShopDatabase, "FavouriteLoadouts"> {
|
||||
FavouriteLoadouts: IFavouriteLoadout[];
|
||||
FavouriteLoadouts?: IFavouriteLoadout[];
|
||||
}
|
||||
|
||||
export type RoomsType = { Name: string; MaxCapacity: number; PlacedDecos: Types.DocumentArray<IPlacedDecosDatabase> };
|
||||
|
@ -1147,7 +1147,10 @@
|
||||
</div>
|
||||
</div>
|
||||
<div data-route="/webui/import" data-title="Import | OpenWF WebUI">
|
||||
<p data-loc="import_importNote"></p>
|
||||
<p>
|
||||
<span data-loc="import_importNote"></span>
|
||||
<span data-loc="import_importNote2"></span>
|
||||
</p>
|
||||
<textarea class="form-control" id="import-inventory" style="height: calc(100vh - 300px)"></textarea>
|
||||
<button class="btn btn-primary mt-3" onclick="doImport();" data-loc="import_submit"></button>
|
||||
<p class="mt-3 mb-1" data-loc="import_samples"></p>
|
||||
|
@ -307,7 +307,8 @@ dict = {
|
||||
worldState_varziaFullyStocked: `Varzia hat volles Inventar`,
|
||||
worldState_varziaOverride: `Varzia-Angebotsüberschreibung`,
|
||||
|
||||
import_importNote: `Du kannst hier eine vollständige oder teilweise Inventarantwort (Client-Darstellung) einfügen. Alle Felder, die vom Importer unterstützt werden, <b>werden in deinem Account überschrieben</b>.`,
|
||||
import_importNote: `[UNTRANSLATED] You can provide a full or partial <code>inventory.php</code> or <code>getShip.php</code> response (client representation) here.`,
|
||||
import_importNote2: `Alle Felder, die vom Importer unterstützt werden, <b>werden in deinem Account überschrieben</b>.`,
|
||||
import_submit: `Absenden`,
|
||||
import_samples: `Beispiele:`,
|
||||
import_samples_maxFocus: `Alle Fokus-Schulen maximiert`,
|
||||
|
@ -306,7 +306,8 @@ dict = {
|
||||
worldState_varziaFullyStocked: `Varzia Fully Stocked`,
|
||||
worldState_varziaOverride: `Varzia Rotation Override`,
|
||||
|
||||
import_importNote: `You can provide a full or partial inventory response (client respresentation) here. All fields that are supported by the importer <b>will be overwritten</b> in your account.`,
|
||||
import_importNote: `You can provide a full or partial <code>inventory.php</code> or <code>getShip.php</code> response (client representation) here.`,
|
||||
import_importNote2: `All fields that are supported by the importer <b>will be overwritten</b> in your account.`,
|
||||
import_submit: `Submit`,
|
||||
import_samples: `Samples:`,
|
||||
import_samples_maxFocus: `All Focus Schools Maxed Out`,
|
||||
|
@ -307,7 +307,8 @@ dict = {
|
||||
worldState_varziaFullyStocked: `Varzia con stock completo`,
|
||||
worldState_varziaOverride: `Cambio en rotación de Varzia`,
|
||||
|
||||
import_importNote: `Puedes proporcionar una respuesta de inventario completa o parcial (representación del cliente) aquí. Todos los campos compatibles con el importador <b>serán sobrescritos</b> en tu cuenta.`,
|
||||
import_importNote: `[UNTRANSLATED] You can provide a full or partial <code>inventory.php</code> or <code>getShip.php</code> response (client representation) here.`,
|
||||
import_importNote2: `Todos los campos compatibles con el importador <b>serán sobrescritos</b> en tu cuenta.`,
|
||||
import_submit: `Enviar`,
|
||||
import_samples: `Muestras:`,
|
||||
import_samples_maxFocus: `Todas las escuelas de enfoque al máximo`,
|
||||
|
@ -307,7 +307,8 @@ dict = {
|
||||
worldState_varziaFullyStocked: `Stock de Varzia au max`,
|
||||
worldState_varziaOverride: `Rotation de Varzia`,
|
||||
|
||||
import_importNote: `Import manuel. Toutes les modifcations supportées par l'inventaire <b>écraseront celles présentes dans la base de données</b>.`,
|
||||
import_importNote: `[UNTRANSLATED] You can provide a full or partial <code>inventory.php</code> or <code>getShip.php</code> response (client representation) here.`,
|
||||
import_importNote2: `[UNTRANSLATED] All fields that are supported by the importer <b>will be overwritten</b> in your account.`,
|
||||
import_submit: `Soumettre`,
|
||||
import_samples: `Échantillons :`,
|
||||
import_samples_maxFocus: `Toutes les écoles de focus au rang max`,
|
||||
|
@ -307,7 +307,8 @@ dict = {
|
||||
worldState_varziaFullyStocked: `Полный ассортимент Варзии`,
|
||||
worldState_varziaOverride: `Изменение ротации Варзии`,
|
||||
|
||||
import_importNote: `Вы можете загрузить полный или частичный ответ инвентаря (клиентское представление) здесь. Все поддерживаемые поля <b>будут перезаписаны</b> в вашем аккаунте.`,
|
||||
import_importNote: `Вы можете загрузить полный или частичный ответ <code>inventory.php</code> или <code>getShip.php</code> (клиентское представление) здесь. `,
|
||||
import_importNote2: `Все поддерживаемые поля <b>будут перезаписаны</b> в вашем аккаунте.`,
|
||||
import_submit: `Отправить`,
|
||||
import_samples: `Пример:`,
|
||||
import_samples_maxFocus: `Все школы Фокуса макс. уровня`,
|
||||
|
@ -307,7 +307,8 @@ dict = {
|
||||
worldState_varziaFullyStocked: `Повний асортимент Варзії`,
|
||||
worldState_varziaOverride: `Зміна ротації Варзії`,
|
||||
|
||||
import_importNote: `Ви можете завантажити повну або часткову відповідь спорядження (клієнтське представлення) тут. Всі підтримувані поля <b>будуть перезаписані</b> у вашому акаунті.`,
|
||||
import_importNote: `[UNTRANSLATED] You can provide a full or partial <code>inventory.php</code> or <code>getShip.php</code> response (client representation) here.`,
|
||||
import_importNote2: `Всі підтримувані поля <b>будуть перезаписані</b> у вашому акаунті.`,
|
||||
import_submit: `Відправити`,
|
||||
import_samples: `Приклад:`,
|
||||
import_samples_maxFocus: `Всі школи Фокусу макс. рівня`,
|
||||
|
@ -307,7 +307,8 @@ dict = {
|
||||
worldState_varziaFullyStocked: `瓦奇娅开启全部库存商品`,
|
||||
worldState_varziaOverride: `瓦奇娅(Prime重生)轮换状态`,
|
||||
|
||||
import_importNote: `您可以在此处提供完整或部分库存响应(客户端表示)。支持的所有字段<b>将被覆盖</b>到您的账户中。`,
|
||||
import_importNote: `[UNTRANSLATED] You can provide a full or partial <code>inventory.php</code> or <code>getShip.php</code> response (client representation) here.`,
|
||||
import_importNote2: `支持的所有字段<b>将被覆盖</b>到您的账户中。`,
|
||||
import_submit: `提交`,
|
||||
import_samples: `示例:`,
|
||||
import_samples_maxFocus: `所有专精学派完全精通`,
|
||||
|
Loading…
x
Reference in New Issue
Block a user