Skip to content

Commit 31f9c22

Browse files
Support download from CDN
1 parent ae8d3ff commit 31f9c22

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

src/Eloquent/Media.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,9 @@ public function thumbnail(int $width = null, int $height = null, bool $fit = fal
3232
->forMedia($this)
3333
->make($width, $height, $fit);
3434
}
35+
36+
public function download(): ?string
37+
{
38+
return \Storage::disk($this->disk)->url($this->file_name);
39+
}
3540
}

src/Support/Thumbnails/CdnThumbnail.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,17 @@ public function make(?int $width, ?int $height = null, bool $fit = false): ?stri
1919
}
2020

2121
abstract protected function generateUrlParameters(?int $width, ?int $height, bool $fit): string;
22+
23+
public function download(): ?string
24+
{
25+
if($cdnUrl = str(config('ozu-client.cdn_url'))->rtrim('/')) {
26+
return sprintf(
27+
'%s/storage/%s',
28+
$cdnUrl,
29+
$this->mediaModel->file_name,
30+
);
31+
}
32+
33+
return null;
34+
}
2235
}

src/Support/Thumbnails/LocalThumbnail.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,9 @@ private function generateThumbnail(string $sourceDisk, string $sourceRelPath, st
8585
return $thumbnailDisk->url($thumbnailPath)
8686
.($this->appendTimestamp ? '?'.$thumbnailDisk->lastModified($thumbnailPath) : '');
8787
}
88+
89+
public function download(): ?string
90+
{
91+
return $this->mediaModel->download();
92+
}
8893
}

src/Support/Thumbnails/Thumbnail.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ public function forMedia(Media $model): self
1616
}
1717

1818
abstract public function make(?int $width, ?int $height = null, bool $fit = false): ?string;
19+
20+
abstract public function download(): ?string;
1921
}

0 commit comments

Comments
 (0)