-
-
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
Changes from all commits
5e12cfe
1f3f5df
1717615
823c64f
4145a15
836f684
66c53bf
ad20e97
657e33f
92b2d72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
use Flarum\Settings\SettingsRepositoryInterface; | ||
use Illuminate\Contracts\Container\Container; | ||
use Illuminate\Contracts\Events\Dispatcher; | ||
use Illuminate\Contracts\Filesystem\Cloud as FilesystemInterface; | ||
use Illuminate\Contracts\Filesystem\Factory; | ||
use Illuminate\Database\ConnectionInterface; | ||
use Illuminate\Database\Schema\Builder; | ||
use Illuminate\Filesystem\Filesystem; | ||
|
@@ -48,6 +50,11 @@ class ExtensionManager | |
*/ | ||
protected $filesystem; | ||
|
||
/** | ||
* @var FilesystemInterface | ||
*/ | ||
protected $assetsFilesystem; | ||
|
||
/** | ||
* @var Collection|null | ||
*/ | ||
|
@@ -59,14 +66,16 @@ public function __construct( | |
Container $container, | ||
Migrator $migrator, | ||
Dispatcher $dispatcher, | ||
Filesystem $filesystem | ||
Filesystem $filesystem, | ||
Factory $filesystemFactory | ||
) { | ||
$this->config = $config; | ||
$this->paths = $paths; | ||
$this->container = $container; | ||
$this->migrator = $migrator; | ||
$this->dispatcher = $dispatcher; | ||
$this->filesystem = $filesystem; | ||
$this->assetsFilesystem = $filesystemFactory->disk('flarum-assets'); | ||
} | ||
|
||
/** | ||
|
@@ -252,12 +261,7 @@ public function uninstall($name) | |
*/ | ||
protected function publishAssets(Extension $extension) | ||
{ | ||
if ($extension->hasAssets()) { | ||
$this->filesystem->copyDirectory( | ||
$extension->getPath().'/assets', | ||
$this->paths->public.'/assets/extensions/'.$extension->getId() | ||
); | ||
} | ||
$extension->copyAssetsTo($this->assetsFilesystem); | ||
} | ||
|
||
/** | ||
|
@@ -267,7 +271,7 @@ protected function publishAssets(Extension $extension) | |
*/ | ||
protected function unpublishAssets(Extension $extension) | ||
{ | ||
$this->filesystem->deleteDirectory($this->paths->public.'/assets/extensions/'.$extension->getId()); | ||
$this->assetsFilesystem->deleteDirectory('extensions/'.$extension->getId()); | ||
} | ||
|
||
/** | ||
|
@@ -279,7 +283,7 @@ protected function unpublishAssets(Extension $extension) | |
*/ | ||
public function getAsset(Extension $extension, $path) | ||
askvortsov1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
return $this->paths->public.'/assets/extensions/'.$extension->getId().$path; | ||
return $this->assetsFilesystem->url($extension->getId()."/$path"); | ||
Comment on lines
-282
to
+286
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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 commentThe 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 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 commentThe reason will be displayed to describe this comment to others. Learn more. Let's tackle the promotion or redesign of this feature separately, then. |
||
} | ||
|
||
/** | ||
|
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.