flydrive icon indicating copy to clipboard operation
flydrive copied to clipboard

getUrl method across all drivers

Open rodrigoroma opened this issue 6 years ago • 3 comments

Hi!

Looking at AwsS3.js code, I found getUrl and getSignedUrl methods but I couldn't find those methods on LocalFileSystem.js driver. It would be interesting to have a standartized getUrl method across all drivers.

The local driver should accept a baseUrl option in its configuration object to determine the base URL to be preppended in the file being acessed. Drivers that don't support acessing the file through a URL could throw an exception.

To pass additional configuration to the getUrl method (like if the URL should be signed or not or the expiry of link) it could use an options object as a second parameter. Some parameters could be ignored depending on the driver.

x.getUrl("file.jpg", {
  signedUrl: true,
  expiry: 600
});

rodrigoroma avatar Aug 04 '19 19:08 rodrigoroma

Hey @rodrigoroma! 👋

Thinking about this, we could add something like the following:

disks: {
    driver: 'local',
    root: process.cwd(),
    computeUrl: (location: string) => {
      // ...
    }
  },
}

We give the power to the user to add a callback method inside their configuration. This method will let you compute the URL with what you need and we will use that to return it inside the LocalStorage driver.

What do you think?

RomainLanz avatar May 19 '20 22:05 RomainLanz

Hi @RomainLanz!

It seens good.

rodrigoroma avatar May 20 '20 10:05 rodrigoroma

@RomainLanz Why not simply concatenating it to a prefix?

disks: {
    driver: 'local',
    root: process.cwd(),
    url: https://domain.com
  },
} 

and then:

Drive.disk().getUrl('/path/to/file')
// returns "https://domain.com/path/to/file"

omidamraei avatar Jun 24 '21 14:06 omidamraei