craftcms / google-cloud

Google Cloud Storage volume type for Craft CMS.
https://plugins.craftcms.com/google-cloud
MIT License
11 stars 10 forks source link

Allow overriding the default file visibility set by FlysystemFS #35

Closed Numkil closed 3 months ago

Numkil commented 10 months ago

Description

Hi everyone, here is a little PR with an addition we have made to the FS in some of our private projects. Allowing us to override the default Object Visibility for new files.

At this moment the Object Visibility for new files created in the cloud is directly tied with the 'HasUrls' option in the craft\flysystem\base\FlysystemFs class

protected function visibility(): string{ return $this->hasUrls ? Visibility::PUBLIC : Visibility::PRIVATE; }

However we have use cases where we have a private cloud bucket but we do want to set a URL for the files in our filesystem in Craft. This way we can redirect people who want to access a file from the bucket to a controller where we check authentication and then stream the file to the client. This way we can still use the normal getUrl method in our twig files even though there is no direct URL to the file in question.

At this moment you can already do this with the plugin however uploading a new file in the backend will throw a 500 error as the FileSystem will try and set the Object Visibility to 'Public' which will fail when the bucket is private only.

No hard feelings if this doesn't seem useful for other people :) Just thought it would be nice to share as we have chosen this route a few times.

Numkil commented 9 months ago

@brandonkelly

Would this be a change you would be interested to merge in this project? I would very much appreciate it if you gave this a look.

timkelty commented 3 months ago

@Numkil Thanks! I made a couple tweaks on top of your commits, so I I'm going to close this PR in favor of: https://github.com/craftcms/google-cloud/pull/37

brandonkelly commented 3 months ago

Just tagged version 2.2.0 with this pulled in (via #37).