Added `temporaryUrlTTL` configuration option, switched is_a() to instanceof
This commit is contained in:
parent
aea4857eba
commit
ef4f1e49ee
|
|
@ -252,6 +252,11 @@ return [
|
|||
| folder - a folder prefix for storing all generated files inside.
|
||||
| path - the public path relative to the application base URL,
|
||||
| or you can specify a full URL path.
|
||||
|
|
||||
| Optionally, you can specify how long temporary URLs to protected files
|
||||
| in cloud storage (ex. AWS, RackSpace) are valid for by setting
|
||||
| temporaryUrlTTL to a value in seconds to define a validity period. This
|
||||
| is only used for the 'uploads' config when using a supported cloud disk
|
||||
*/
|
||||
|
||||
'storage' => [
|
||||
|
|
@ -260,6 +265,7 @@ return [
|
|||
'disk' => 'local',
|
||||
'folder' => 'uploads',
|
||||
'path' => '/storage/app/uploads',
|
||||
'temporaryUrlTTL' => 3600,
|
||||
],
|
||||
|
||||
'media' => [
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use View;
|
||||
use Cache;
|
||||
use Config;
|
||||
use Backend;
|
||||
use Response;
|
||||
use System\Models\File as FileModel;
|
||||
|
|
@ -65,18 +66,18 @@ class Files extends Controller
|
|||
$url = null;
|
||||
$disk = $file->getDisk();
|
||||
$adapter = $disk->getAdapter();
|
||||
if (is_a($adapter, 'League\Flysystem\Cached\CachedAdapter')) {
|
||||
if ($adapter instanceof \League\Flysystem\Cached\CachedAdapter) {
|
||||
$adapter = $adapter->getAdapter();
|
||||
}
|
||||
|
||||
if (is_a($adapter, 'League\Flysystem\AwsS3v3\AwsS3Adapter') ||
|
||||
is_a($adapter, 'League\Flysystem\Rackspace\RackspaceAdapter') ||
|
||||
if (($adapter instanceof \League\Flysystem\AwsS3v3\AwsS3Adapter) ||
|
||||
($adapter instanceof \League\Flysystem\Rackspace\RackspaceAdapter) ||
|
||||
method_exists($adapter, 'getTemporaryUrl')
|
||||
) {
|
||||
if (empty($path)) {
|
||||
$path = $file->getDiskPath();
|
||||
}
|
||||
$expires = now()->addMinutes(60);
|
||||
$expires = now()->addSeconds(Config::get('cms.storage.uploads.temporaryUrlTTL', 3600));
|
||||
|
||||
$url = Cache::remember('backend.file:' . $path, $expires, function () use ($disk, $path, $expires) {
|
||||
return $disk->temporaryUrl($path, $expires);
|
||||
|
|
|
|||
Loading…
Reference in New Issue