minor
This commit is contained in:
parent
fb472f29c5
commit
3835897a88
@ -59,7 +59,7 @@ public function viewUrl(): string
|
|||||||
|
|
||||||
public function saveContent(string $content): void
|
public function saveContent(string $content): void
|
||||||
{
|
{
|
||||||
$this->file_path = ReportStorage::reportFilepath($this->study);
|
$this->file_path = ReportStorage::randomFilepath($this->study);
|
||||||
Storage::disk('public')->put($this->file_path, $content);
|
Storage::disk('public')->put($this->file_path, $content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,22 +3,45 @@
|
|||||||
namespace App\Services;
|
namespace App\Services;
|
||||||
|
|
||||||
use App\Models\Study;
|
use App\Models\Study;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
final readonly class ReportStorage
|
final readonly class ReportStorage
|
||||||
{
|
{
|
||||||
public static function studyFolder(Study|int $study): string
|
final public const REPORTS_DISK = 'public';
|
||||||
|
final public const REPORTS_DIRECTORY = 'reports';
|
||||||
|
|
||||||
|
public static function folder(Study|int $study): string
|
||||||
{
|
{
|
||||||
$hash = md5($study instanceof Study ? $study->id : $study);
|
$hash = md5($study instanceof Study ? $study->id : $study);
|
||||||
|
|
||||||
return 'reports/' . substr($hash, 0, 2) . '/' . substr($hash, 2, 2) . '/' . substr($hash, 4, 2);
|
return implode('/', [
|
||||||
|
self::REPORTS_DIRECTORY,
|
||||||
|
substr($hash, 0, 2),
|
||||||
|
substr($hash, 2, 2),
|
||||||
|
substr($hash, 4, 2),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function reportFilepath(Study|int $study, string $ext = '.html'): string
|
public static function randomFilepath(Study|int $study, string $ext = '.html'): string
|
||||||
{
|
{
|
||||||
$directory = self::studyFolder($study);
|
|
||||||
$filename = Str::random(16) . $ext;
|
$filename = Str::random(16) . $ext;
|
||||||
|
|
||||||
return $directory . '/' . $filename;
|
return self::customFilepath($study, $filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function customFilepath(Study|int $study, string $filename): string
|
||||||
|
{
|
||||||
|
return self::folder($study) . '/' . $filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function abspath(string $path): string
|
||||||
|
{
|
||||||
|
return Storage::disk(self::REPORTS_DISK)->path($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function exists(Study|int $study, string $filename): bool
|
||||||
|
{
|
||||||
|
return Storage::disk(self::REPORTS_DISK)->exists(self::customFilepath($study, $filename));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user