Add fail option to asset request / response

This commit is contained in:
Mitchell McCaffrey 2021-06-24 09:50:56 +10:00
parent b3cc4b324d
commit ef7f27c122

View File

@ -390,12 +390,22 @@ function NetworkedMapAndTokens({ session }) {
async function handlePeerData({ id, data, reply }) { async function handlePeerData({ id, data, reply }) {
if (id === "assetRequest") { if (id === "assetRequest") {
const asset = await getAsset(data.id); const asset = await getAsset(data.id);
reply("assetResponse", asset, undefined, asset.id); if (asset) {
reply("assetResponseSuccess", asset, undefined, data.id);
} else {
reply("assetResponseFail", data.id, undefined, data.id);
}
} }
if (id === "assetResponse") { if (id === "assetResponseSuccess") {
await putAsset(data); const asset = data;
requestingAssetsRef.current.delete(data.id); await putAsset(asset);
requestingAssetsRef.current.delete(asset.id);
}
if (id === "assetResponseFail") {
const assetId = data;
requestingAssetsRef.current.delete(assetId);
} }
} }