30a6b080eb
Replace the server-rendered release upload form with a Livewire component, introducing an interactive admin release form that supports dynamic episode management, real‑time CDN path validation, and direct download file checks. Key changes: - New `AdminReleaseForm` Livewire component with dynamic episode fields, Tagify integration, and upload handling via Livewire's file uploads. - Added `CdnPathValidator` service to verify download and stream paths across all configured mirrors, caching results and capturing file sizes. - Extended `EpisodeService` and `GalleryService` to support array‑based data and temporary uploaded files from Livewire. - Persist validated download sizes and store the validation timestamp on the `downloads` table via a new migration; also add a unique constraint on `hentais.slug` to prevent duplicates. - Remove the old POST `/admin/release/upload` route and controller logic, along with the legacy `upload.js` script. - Add comprehensive feature and unit tests covering the new component and the CDN validation service.
55 lines
1.0 KiB
PHP
55 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Downloads extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var string[]
|
|
*/
|
|
protected $fillable = [
|
|
'episode_id',
|
|
'type',
|
|
'url',
|
|
'size',
|
|
'validated_at',
|
|
];
|
|
|
|
/**
|
|
* Belongs to an episode
|
|
*/
|
|
public function episode()
|
|
{
|
|
return $this->belongsTo(Episode::class);
|
|
}
|
|
|
|
/**
|
|
* Convert bytes to human readable format
|
|
*/
|
|
private static function bytesToHuman($bytes)
|
|
{
|
|
$units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'];
|
|
|
|
for ($i = 0; $bytes > 1024; $i++) {
|
|
$bytes /= 1024;
|
|
}
|
|
|
|
return round($bytes, 2).' '.$units[$i];
|
|
}
|
|
|
|
/**
|
|
* Returns the human readable form of the file size
|
|
*/
|
|
public function getFileSize(): ?string
|
|
{
|
|
return $this->size === null ? null : self::bytesToHuman($this->size);
|
|
}
|
|
}
|