Files
speech2text/app/Services/StorageService.php
2026-06-02 17:35:45 +08:00

46 lines
1.1 KiB
PHP

<?php
namespace App\Services;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
class StorageService
{
private const DISK = 'private';
public function storeAudio(UploadedFile $file, string $uuid): string
{
$ext = $file->getClientOriginalExtension();
$filename = Str::random(40) . '.' . strtolower($ext);
$dir = "transcriptions/{$uuid}/audio";
Storage::disk(self::DISK)->putFileAs($dir, $file, $filename);
return "{$dir}/{$filename}";
}
public function delete(string $path): void
{
if (Storage::disk(self::DISK)->exists($path)) {
Storage::disk(self::DISK)->delete($path);
}
}
public function exists(string $path): bool
{
return Storage::disk(self::DISK)->exists($path);
}
public function size(string $path): int
{
return Storage::disk(self::DISK)->size($path);
}
public function readStream(string $path)
{
return Storage::disk(self::DISK)->readStream($path);
}
}