Files
moonwell-web/app/Services/GameClientDownloadService.php
2026-10-03 14:33:08 +04:00

42 lines
1.0 KiB
PHP

<?php
namespace App\Services;
use Illuminate\Support\Facades\Storage;
use RuntimeException;
use Throwable;
class GameClientDownloadService
{
public function filename(): string
{
return basename($this->objectKey());
}
public function temporaryUrl(): string
{
$disk = Storage::disk(config('moonwell.client.disk'));
$objectKey = $this->objectKey();
$filename = $this->filename();
if (! $disk->exists($objectKey)) {
throw new RuntimeException('Game client archive is not available.');
}
try {
return $disk->temporaryUrl(
$objectKey,
now()->addMinutes(config('moonwell.client.temporary_url_minutes')),
['ResponseContentDisposition' => sprintf('attachment; filename="%s"', $filename)],
);
} catch (Throwable) {
return $disk->url($objectKey);
}
}
private function objectKey(): string
{
return (string) config('moonwell.client.object_key');
}
}