engine_components icon indicating copy to clipboard operation
engine_components copied to clipboard

Be able to pass a callback function to url

Open eng-luciano-julien opened this issue 1 year ago • 1 comments

Description 📝

I am using cloudfront to serve the files saved on backend, so I have a base url and a signed part after the file name. https://.cloudfront.net/geometry-1.frag?Policy=&Key-Pair-Id=&Signature= Also, this signed url has an expiration time, that why I believe a callback function give the full flexibility needed for all use cases.

Suggested solution 💡

I suggest to change in fragment-stream-loader.ts the this.url calls, like that: const groupUrl = await this.url(globalDataFileId); const fetched = await fetch(await this.url(indexesFile));

To be able to accept also string, it need also a condicional or a function that check that.

Alternative ⛕

No response

Additional context ☝️

No response

Validations ✅

  • [X] Read the docs.
  • [X] Check that there isn't already an issue that requests the same feature to avoid creating a duplicate.

eng-luciano-julien avatar Mar 02 '24 17:03 eng-luciano-julien

Hi, my backend requires authorization using an additional header in the fetch method, when I save ".frag" and ".json" files and load the json geometry file I request it like this: image Maybe an above solusion would be good for me too, alternatively I suggest to add an authorization header to the StreamLoader’s settings: "loader.authorizationHeader" (like the “loader.url")

robertbiskup avatar Apr 17 '24 12:04 robertbiskup

Solved from version @thatopen/[email protected] and @thatopen/[email protected]. I'm publishing later today.

Now you can specify a custom loading function like this:

import * as FRAGS from "@thatopen/fragments";

// To fetch properties
FRAGS.FragmentsGroup.fetch = (url: string) => {
   // Your logic....
   return result as Promise<Response>;
}

// To fetch geometries and other files
ifcStreamer.fetch = (url: string) => {
   // Your logic....
   return result as Promise<Response>;
}

Let me know if this doesn't work!

agviegas avatar Jul 16 '24 11:07 agviegas