diff --git a/src/libs/blueos.ts b/src/libs/blueos.ts index 53fcf42a8..f416e8e73 100644 --- a/src/libs/blueos.ts +++ b/src/libs/blueos.ts @@ -3,29 +3,20 @@ import ky from 'ky' /* eslint-disable @typescript-eslint/no-explicit-any */ export const getBagOfHoldingFromVehicle = async ( vehicleAddress: string, - bagName: string -): Promise> => { + bagPath: string +): Promise | any> => { try { - return await ky.get(`http://${vehicleAddress}/bag/v1.0/get/${bagName}`, { timeout: 5000 }).json() + return await ky.get(`http://${vehicleAddress}/bag/v1.0/get/${bagPath}`, { timeout: 5000, retry: 0 }).json() } catch (error) { throw new Error(`Could not get bag of holdings for ${bagName}. ${error}`) } } -export const getCockpitStorageFromVehicle = async (vehicleAddress: string): Promise> => { - try { - return await getBagOfHoldingFromVehicle(vehicleAddress, 'cockpit') - } catch (error) { - throw new Error(`Could not get Cockpit's storage data from vehicle. ${error}`) - } -} - export const getKeyDataFromCockpitVehicleStorage = async ( vehicleAddress: string, storageKey: string ): Promise | undefined> => { - const cockpitVehicleStorage = await getCockpitStorageFromVehicle(vehicleAddress) - return cockpitVehicleStorage[storageKey] + return await getBagOfHoldingFromVehicle(vehicleAddress, `cockpit/${storageKey}`) } export const setBagOfHoldingOnVehicle = async ( @@ -40,32 +31,12 @@ export const setBagOfHoldingOnVehicle = async ( } } -export const setCockpitStorageOnVehicle = async ( - vehicleAddress: string, - storageData: Record | any -): Promise => { - try { - await setBagOfHoldingOnVehicle(vehicleAddress, 'cockpit', storageData) - } catch (error) { - throw new Error(`Could not set Cockpit's storage data on vehicle. ${error}`) - } -} - export const setKeyDataOnCockpitVehicleStorage = async ( vehicleAddress: string, storageKey: string, storageData: Record | any ): Promise => { - let previousVehicleStorage: Record = {} - try { - previousVehicleStorage = await getCockpitStorageFromVehicle(vehicleAddress) - } catch (error) { - console.error(error) - } - const newVehicleStorage = previousVehicleStorage - newVehicleStorage[storageKey] = storageData - - await setCockpitStorageOnVehicle(vehicleAddress, newVehicleStorage) + await setBagOfHoldingOnVehicle(vehicleAddress, `cockpit/${storageKey}`, storageData) } /* eslint-disable jsdoc/require-jsdoc */