Added `temporaryUrlTTL` configuration option, switched is_a() to instanceof

This commit is contained in:
Luke Towers 2019-05-31 00:53:27 -06:00
parent aea4857eba
commit ef4f1e49ee
2 changed files with 14 additions and 7 deletions

View File

@ -252,14 +252,20 @@ 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' => [
'uploads' => [
'disk' => 'local',
'folder' => 'uploads',
'path' => '/storage/app/uploads',
'disk' => 'local',
'folder' => 'uploads',
'path' => '/storage/app/uploads',
'temporaryUrlTTL' => 3600,
],
'media' => [

View File

@ -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);