diff --git a/README.md b/README.md index b714eeb..aabb833 100644 --- a/README.md +++ b/README.md @@ -58,3 +58,7 @@ Additional configuration options: - `swiftSegmentSize` [[ref]](https://github.com/mzur/flysystem-openstack-swift#configuration) - `swiftSegmentContainer` [[ref]](https://github.com/mzur/flysystem-openstack-swift#configuration) + +- `prefix` (default: `null`): Prefix to use for the names of the objects in the container. + +- `url` (default: `null`): Override URL to use for public URLs to objects. If this is not set, the public URL will point to the public URL of Swift. This configuration is useful if you use a reverse proxy to pass through requests to public Swift containers. diff --git a/src/SwiftAdapter.php b/src/SwiftAdapter.php new file mode 100644 index 0000000..4482427 --- /dev/null +++ b/src/SwiftAdapter.php @@ -0,0 +1,43 @@ +url = rtrim($url, '/'); + } + + /** + * Get the URL for the file at the given path. + * + * @param string $path + * @return string + */ + public function getUrl($path) + { + if ($this->url) { + return "{$this->url}/{$path}"; + } + + return $this->container->getObject($path)->getPublicUri(); + } +} diff --git a/src/SwiftServiceProvider.php b/src/SwiftServiceProvider.php index 48a9277..52f7704 100644 --- a/src/SwiftServiceProvider.php +++ b/src/SwiftServiceProvider.php @@ -6,7 +6,6 @@ use League\Flysystem\Filesystem; use Biigle\CachedOpenStack\OpenStack; use Illuminate\Support\ServiceProvider; -use Nimbusoft\Flysystem\OpenStack\SwiftAdapter; class SwiftServiceProvider extends ServiceProvider { @@ -23,7 +22,9 @@ public function boot() ->objectStoreV1() ->getContainer($config['container']); - $adapter = new SwiftAdapter($container); + $prefix = array_get($config, 'prefix', null); + $url = array_get($config, 'url', null); + $adapter = new SwiftAdapter($container, $prefix, $url); return new Filesystem($adapter, $this->getFlyConfig($config)); });