fix: also store charges and state in fit-links (#90)
This commit is contained in:
@@ -31,7 +31,7 @@ Hammerhead II x1
|
||||
`;
|
||||
|
||||
export const hashFit =
|
||||
"fit:v1:H4sIAAAAAAAAClXOMQ7CMAwF0L2n6AE8xD92bLMiRhi4AQMSrND7i7itGrG9JHb+R4QLnet8fyzL8zOf5tv7+7pcaWIoiTY04u7WrcGrLe/LZk+zppkA7CODdTBIGOydKFTVoiRzzfMdIFZrmYdKHOyWlEEdW0ZQW3N7hYNxsJZBHsRgL+ammRagypZBU9RO3yid1bKuEkRyylDy0CxIxTBthXQdScmmIt7I/+72D6JNPx7qugdyAQAA";
|
||||
"fit:v2:H4sIAAAAAAAACmWQMZJDMQhD+38WChBgwx32Ijtb5P5d4ONkdpLOTwhbFjKT6efx90uXk+pmJqE+I9YKEueblC0WyXpDvABrZy2OTTR8UTIPwtp4UIQApNz3C/5DkiRYbwA3RA70TowLINl+8qHMJoYBIxPgTLwnHAOb4FtKOlkuxJeSn0p95lORLwVVQ+i6n9FKI77nTbXqbntPpqgrKoWVEDXN2pNtY01tWBM8rcAjTj9OtaJ6aBV5+qHdM345owlT0hPutE6T0AEAAA==";
|
||||
|
||||
export const fullFits = [
|
||||
{
|
||||
|
||||
@@ -18,9 +18,7 @@ async function decompress(base64compressedBytes: string): Promise<string> {
|
||||
return result;
|
||||
}
|
||||
|
||||
async function decodeEsiFit(fitVersion: string, fitCompressed: string): Promise<EsiFit | undefined> {
|
||||
if (fitVersion != "v1") return undefined;
|
||||
|
||||
async function decodeEsiFitV1(fitCompressed: string): Promise<EsiFit | undefined> {
|
||||
const fitEncoded = await decompress(fitCompressed);
|
||||
|
||||
const fitLines = fitEncoded.trim().split("\n");
|
||||
@@ -43,6 +41,39 @@ async function decodeEsiFit(fitVersion: string, fitCompressed: string): Promise<
|
||||
};
|
||||
}
|
||||
|
||||
async function decodeEsiFitV2(fitCompressed: string): Promise<EsiFit | undefined> {
|
||||
const fitEncoded = await decompress(fitCompressed);
|
||||
|
||||
const fitLines = fitEncoded.trim().split("\n");
|
||||
const fitHeader = fitLines[0].split(",");
|
||||
|
||||
const fitItems = fitLines.slice(1).map((line) => {
|
||||
const item = line.split(",");
|
||||
|
||||
let charge = undefined;
|
||||
if (item[3]) {
|
||||
charge = {
|
||||
type_id: parseInt(item[3]),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
flag: parseInt(item[0]),
|
||||
type_id: parseInt(item[1]),
|
||||
quantity: parseInt(item[2]),
|
||||
charge,
|
||||
state: item[4] || undefined,
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
ship_type_id: parseInt(fitHeader[0]),
|
||||
name: fitHeader[1],
|
||||
description: fitHeader[2],
|
||||
items: fitItems,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a hash from window.location.hash to an ESI fit.
|
||||
*/
|
||||
@@ -55,7 +86,13 @@ export async function eveShipFitHash(fitHash: string): Promise<EsiFit | undefine
|
||||
|
||||
if (fitPrefix !== "fit") return undefined;
|
||||
|
||||
const esiFit = await decodeEsiFit(fitVersion, fitEncoded);
|
||||
let esiFit = undefined;
|
||||
switch (fitVersion) {
|
||||
case "v1":
|
||||
esiFit = await decodeEsiFitV1(fitEncoded);
|
||||
case "v2":
|
||||
esiFit = await decodeEsiFitV2(fitEncoded);
|
||||
}
|
||||
return esiFit;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,10 +22,10 @@ async function encodeEsiFit(esiFit: EsiFit): Promise<string> {
|
||||
let result = `${esiFit.ship_type_id},${esiFit.name},${esiFit.description}\n`;
|
||||
|
||||
for (const item of esiFit.items) {
|
||||
result += `${item.flag},${item.type_id},${item.quantity}\n`;
|
||||
result += `${item.flag},${item.type_id},${item.quantity},${item.charge?.type_id ?? ""},${item.state ?? ""}\n`;
|
||||
}
|
||||
|
||||
return "v1:" + (await compress(result));
|
||||
return "v2:" + (await compress(result));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user