mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-11 01:24:46 +02:00
41 lines
889 B
PHP
41 lines
889 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Actions\Http;
|
|
|
|
use App\Contracts\Storage\InteractsWithDisk;
|
|
use App\Models\BaseModel;
|
|
use Illuminate\Filesystem\FilesystemAdapter;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
|
|
|
/**
|
|
* Class DownloadAction.
|
|
*
|
|
* @template TModel of \App\Models\BaseModel
|
|
*/
|
|
abstract class DownloadAction implements InteractsWithDisk
|
|
{
|
|
/**
|
|
* @param TModel $model
|
|
*/
|
|
public function __construct(protected readonly BaseModel $model) {}
|
|
|
|
/**
|
|
* Download the resource.
|
|
*/
|
|
public function download(): StreamedResponse
|
|
{
|
|
/** @var FilesystemAdapter $fs */
|
|
$fs = Storage::disk($this->disk());
|
|
|
|
return $fs->download($this->path());
|
|
}
|
|
|
|
/**
|
|
* Get the path of the resource in storage.
|
|
*/
|
|
abstract protected function path(): string;
|
|
}
|