async function handleHcapiPubSubUnwrap()

in eventhandlers.js [84:105]


async function handleHcapiPubSubUnwrap(ctx, perfCtx) {
  const dicomWebPath = Buffer.from(ctx.message.data, "base64").toString();
  const uriPath = hcapi.createUriPath(dicomWebPath);
  const buffer = await hcapi.downloadToMemory(uriPath);
  perfCtx.addRef("afterHcapiDownloadToMemory");
  const writeObj = {
    timestamp: new Date(),
    path: dicomWebPath,
    version: null, // TODO: Fix when HCAPI supports versions
    info: JSON.stringify({
      event: consts.HCAPI_FINALIZE,
      storage: { size: buffer.length, type: consts.STORAGE_TYPE_DICOMWEB },
    }),
    metadata: await getMetadata(buffer, uriPath),
  };
  perfCtx.addRef("afterGetMetadata");
  await bq.insert(writeObj);
  perfCtx.addRef("afterBqInsert");
  if (DEBUG_MODE) {
    console.log(JSON.stringify(writeObj));
  }
}