Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to extend adapter? #70

Open
maa-x opened this issue Jul 5, 2024 · 4 comments
Open

How to extend adapter? #70

maa-x opened this issue Jul 5, 2024 · 4 comments

Comments

@maa-x
Copy link

maa-x commented Jul 5, 2024

I have extended AdapterLocal to add a method to generate public URLs.

However, there is no convenient way to use this adapter with the Storage class that I can see.

There's a few ways I can think of to make this work, but the easiest might simply be to make _adapter protected. Let me know your thoughts

@abudaan
Copy link
Member

abudaan commented Jul 28, 2024

You can extend the Storage by extending the public API. But then you would have to implement the new features that you've added to the local adapter to all other adapters as well otherwise you break the abstraction layer which is the main feature and "raison d'être" of this library.

What you can do to use the functionality that you've added to AdapterLocal is:

const configuration = {
  type: StorageType.LOCAL,
  directory: "path/to/directory",
};
const storage = new Storage(configuration);
const adapter = storage.getAdapter() as AdapterLocal;
adapter.yourMethod();

// or:
(storage.adapter as AdapterLocal).yourMethod();

@abudaan
Copy link
Member

abudaan commented Jul 30, 2024

Alternately you could use the adapter stand-alone:

const configuration = {
  type: StorageType.LOCAL,
  directory: "path/to/directory",
};
const adapter = new AdapterLocal();
adapter.yourMethod();

You can use the full API on an adapter instance directly. You'd only be missing switchAdapter and getAdapter.

@abudaan
Copy link
Member

abudaan commented Jul 30, 2024

You can extend the protected method _getFileAsUrl in the local adapter. If you add an extra boolean option publicUrl to the options object you can switch between local urls (filepaths) and public urls.

@maa-x
Copy link
Author

maa-x commented Jul 30, 2024

But then I'd lose the storage abstraction, with callers needing to handle the different storage backends.

What I was hoping was to override the getFileAsUrl method to allow it to generate a public URL, using a custom URL generator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants