Scaffolded from the Ladill mini/events extraction pattern: multi-file transfers, retention controls, public landing pages, analytics, and Gitea deploy workflow. Co-authored-by: Cursor <cursoragent@cursor.com>
58 lines
1.3 KiB
PHP
58 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class TransferFile extends Model
|
|
{
|
|
protected $fillable = [
|
|
'transfer_id',
|
|
'original_name',
|
|
'disk',
|
|
'path',
|
|
'mime_type',
|
|
'size_bytes',
|
|
'downloads_total',
|
|
];
|
|
|
|
protected $casts = [
|
|
'size_bytes' => 'integer',
|
|
'downloads_total' => 'integer',
|
|
];
|
|
|
|
public function transfer(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Transfer::class);
|
|
}
|
|
|
|
public function downloadEvents(): HasMany
|
|
{
|
|
return $this->hasMany(TransferDownloadEvent::class);
|
|
}
|
|
|
|
public function humanSize(): string
|
|
{
|
|
$bytes = $this->size_bytes;
|
|
if ($bytes >= 1073741824) {
|
|
return number_format($bytes / 1073741824, 1).' GB';
|
|
}
|
|
if ($bytes >= 1048576) {
|
|
return number_format($bytes / 1048576, 1).' MB';
|
|
}
|
|
if ($bytes >= 1024) {
|
|
return number_format($bytes / 1024, 0).' KB';
|
|
}
|
|
|
|
return $bytes.' B';
|
|
}
|
|
|
|
public function existsOnDisk(): bool
|
|
{
|
|
return Storage::disk($this->disk)->exists($this->path);
|
|
}
|
|
}
|