Skip to content

Commit

Permalink
Merge 47fa15c into 37605ed
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxpiper committed Apr 8, 2020
2 parents 37605ed + 47fa15c commit 7dea0e4
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/App/Formatter/Media.php
Expand Up @@ -14,9 +14,13 @@
use Ushahidi\Core\Entity;
use Ushahidi\Core\Traits\FormatterAuthorizerMetadata;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Cache;

class Media extends API
{
// This is rather long, because what we cache here rarely (if ever) changes
const CACHE_LIFETIME = 24 * 3600 ; # in seconds

use FormatterAuthorizerMetadata;

protected function addMetadata(array $data, Entity $media)
Expand Down Expand Up @@ -60,6 +64,17 @@ protected function formatOFilename($value)
array_push($url_path, $filename);
$path = implode("/", $url_path);

return Cache::remember(
'Ushahidi\App\Formatter\Media.publicUrl[' . $path . ']',
self::CACHE_LIFETIME,
function () use ($path) {
return $this->getStorageObjectPublicUrl($path);
}
);
}

protected function getStorageObjectPublicUrl(string $path) : string
{
$adapter = Storage::getAdapter();
// Special handling for RS to get SSL URLs
if ($adapter instanceof \League\Flysystem\Rackspace\RackspaceAdapter) {
Expand Down

0 comments on commit 7dea0e4

Please sign in to comment.