-
-
Notifications
You must be signed in to change notification settings - Fork 842
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
Use Laravel filesystem interface for assets and avatars #2729
Conversation
[ci skip] [skip ci]
[ci skip] [skip ci]
[ci skip] [skip ci]
[ci skip] [skip ci]
|
||
public function getAssetUrl($assetPath): string | ||
{ | ||
return $this->assetsFilesystem->url($assetPath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@luceos Is this type of code what you were referring to when we talked about potential lag due to indexing the other day? It's a very clean and convenient way to get what we need, but if it might result in lag, that's something we should take into account.
Yay for a A more general question, though: If the goal is to fix #1783, is this really the only way to achieve this? Injecting a filesystem (as the old code does) still allows S3 or other backends to be configured, and it would be a less invasive change. Injecting a factory means that more knowledge about the concept of "disks" and how Flarum configures itself is littered throughout the codebase. Plus, a higher grade of coupling to Laravel which I spent a lot of time on reducing. 🙈 IMHO, this is service provider territory (mapping configuration to objects / instances). This coud be done through contextual bindings as you outlined in #1783 (comment), or similar to this: $container->singleton('flarum.disk.avatars', function () {
return new S3Filesystem();
});
// For clients that need this filesystem, use contextual binding or concrete factories:
$container->bind(MyController::Class, function ($app) {
return new MyController('other', 'args', $app['flarum.disk.avatars']);
}); |
I've thought about this, but I'm not sure there's a good solution. I would strongly prefer a solution where extensions can use the filesystem without having to register custom service providers. As you pointed out in #2437 (comment), service providers aren't use case driven. IMO, they should be used only when truly appropriate, EG by overriding bindings. I also don't think it would be appropriate to have per-disk interfaces, as that doesn't scale too well (although it's possible, interfaces could extend To be honest, I think I prefer the current approach of injecting a disk manager (and obtaining the relevant disk) to the old system of injecting a Filesystem, for several reasons:
|
Over the years I have become less snappy to get a complete Illuminate component into Flarum due to the wisdom of among other Franz. But in this scenario, looking at the problems I tried to resolve using the fof filesystem drivers package, I can only agree that using disks makes for much cleaner and useful code. |
return $this->paths->public.'/assets/extensions/'.$extension->getId().$path; | ||
return $this->assetsFilesystem->url($extension->getId()."/$path"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't find where this method is used to properly tell, but aren't we replacing a path with a url here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't used. Frankly I'm not sure why we even have it. I removed it in the first version of this PR, but reverted that change as it was a bit too spontaneous.
If assets aren't always on disk, then the URL to assets won't always be a path. If we want to keep it, I'll update the docblock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it was used in very early versions of Flarum, today though I don't think that anyone uses it. I think that it would be safe to remove this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this can be removed, @askvortsov1 is onto something here.
In case you use an S3 bucket to store assets files to your public directory you need to be able to resolve the actual, full URL that the asset is published as. Disks in Laravel support this functionality using the url
method.
However, I don't think any extension currently is using it and that might be a problem in itself 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's tackle the promotion or redesign of this feature separately, then.
TODO: document that adapters for |
Part of #1783
Part of flarum/issue-archive#121
Changes proposed in this pull request:
This PR refactors filesystem-involved code to use Laravel filesystem disks instead of the underlying Flysystem adaptors. I've refactored code relating to assets and avatars. Storage and cache will need to wait for a different PR.
I also considered introducing a "vendor filesystem". On paper it sounds nice, but there's too many places where we assume code will be located in the local filesystem. That's also a very fair assumption IMO. See 5e12cfe for how it looks with a partial transition to a vendor filesystem. I decided to revert that change, it wasn't a good solution IMO.
Reviewers should focus on:
Confirmed
composer test
).