This commit is contained in:
2026-04-18 14:18:52 +02:00
parent 5b4d3d435e
commit f3e5100d5d
126 changed files with 743 additions and 795 deletions

View File

@@ -4,19 +4,18 @@ namespace App\Models;
use App\Models\Presenters\CommentPresenter;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Maize\Markable\Markable;
use Maize\Markable\Models\Like;
class Comment extends Model
{
use HasFactory, SoftDeletes, Markable;
use HasFactory, Markable, SoftDeletes;
protected static $marks = [
Like::class
Like::class,
];
/**
@@ -25,7 +24,7 @@ class Comment extends Model
* @var string[]
*/
protected $fillable = [
'body'
'body',
];
public function presenter()
@@ -71,6 +70,6 @@ class Comment extends Model
*/
public function likeCount(): int
{
return cache()->remember('commentLikes' . $this->id, 300, fn() => $this->likes->count());
return cache()->remember('commentLikes'.$this->id, 300, fn () => $this->likes->count());
}
}

View File

@@ -39,7 +39,7 @@ class Downloads extends Model
$bytes /= 1024;
}
return round($bytes, 2) . ' ' . $units[$i];
return round($bytes, 2).' '.$units[$i];
}
/**

View File

@@ -2,35 +2,28 @@
namespace App\Models;
use App\Models\Downloads;
use App\Models\PopularMonthly;
use App\Models\PopularWeekly;
use App\Models\PopularDaily;
use Conner\Tagging\Taggable;
use Laravel\Scout\Searchable;
use Maize\Markable\Markable;
use Maize\Markable\Models\Like;
use Spatie\Sitemap\Contracts\Sitemapable;
use Spatie\Sitemap\Tags\Url;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Laravel\Scout\Searchable;
use Maize\Markable\Markable;
use Maize\Markable\Models\Like;
use Spatie\Sitemap\Contracts\Sitemapable;
use Spatie\Sitemap\Tags\Url;
class Episode extends Model implements Sitemapable
{
use Markable, Taggable;
use HasFactory;
use Markable, Taggable;
use Searchable;
protected static $marks = [
Like::class
Like::class,
];
/**
@@ -49,14 +42,14 @@ class Episode extends Model implements Sitemapable
public function toSearchableArray()
{
return [
'title' => $this->title,
'title_search' => $this->title_search,
'title_jpn' => $this->title_jpn,
'slug' => $this->slug,
'description' => $this->description,
'tags' => $this->tagNames(),
'release_date' => $this->release_date,
'created_at' => $this->created_at,
'title' => $this->title,
'title_search' => $this->title_search,
'title_jpn' => $this->title_jpn,
'slug' => $this->slug,
'description' => $this->description,
'tags' => $this->tagNames(),
'release_date' => $this->release_date,
'created_at' => $this->created_at,
];
}
@@ -125,7 +118,7 @@ class Episode extends Model implements Sitemapable
*/
public function viewCount(): int
{
return cache()->remember('episodeViews' . $this->id, 300, fn() => $this->view_count);
return cache()->remember('episodeViews'.$this->id, 300, fn () => $this->view_count);
}
/**
@@ -141,7 +134,7 @@ class Episode extends Model implements Sitemapable
$index = floor(log($this->viewCount(), 1000));
$shortNumber = $this->viewCount() / pow(1000, $index);
return round($shortNumber, 0) . $units[$index - 1];
return round($shortNumber, 0).$units[$index - 1];
}
/**
@@ -149,7 +142,7 @@ class Episode extends Model implements Sitemapable
*/
public function likeCount(): int
{
return cache()->remember('episodeLikes' . $this->id, 300, fn() => $this->likes->count());
return cache()->remember('episodeLikes'.$this->id, 300, fn () => $this->likes->count());
}
/**
@@ -157,7 +150,7 @@ class Episode extends Model implements Sitemapable
*/
public function commentCount(): int
{
return cache()->remember('episodeComments' . $this->id, 300, fn() => $this->comments->count());
return cache()->remember('episodeComments'.$this->id, 300, fn () => $this->comments->count());
}
public function comments()
@@ -180,6 +173,7 @@ class Episode extends Model implements Sitemapable
$problematicResults .= $pTag;
}
return $problematicResults;
}
@@ -202,17 +196,17 @@ class Episode extends Model implements Sitemapable
*/
public function hasAutoTrans(): bool
{
return cache()->remember('mt' . $this->id, 900, fn() => $this->subtitles()->exists());
return cache()->remember('mt'.$this->id, 900, fn () => $this->subtitles()->exists());
}
public function is48Fps(): bool
{
return cache()->remember('48fps' . $this->id, 900, fn() => $this->interpolated);
return cache()->remember('48fps'.$this->id, 900, fn () => $this->interpolated);
}
public function isUHD48Fps(): bool
{
return cache()->remember('48fpsUHD' . $this->id, 900, fn() => $this->interpolated_uhd);
return cache()->remember('48fpsUHD'.$this->id, 900, fn () => $this->interpolated_uhd);
}
public function getResolution(): string
@@ -226,7 +220,7 @@ class Episode extends Model implements Sitemapable
public function userWatched(int $user_id): bool
{
return cache()->remember('user' . $user_id . 'watched' . $this->id, 300, fn() => Watched::where('user_id', $user_id)->where('episode_id', $this->id)->exists());
return cache()->remember('user'.$user_id.'watched'.$this->id, 300, fn () => Watched::where('user_id', $user_id)->where('episode_id', $this->id)->exists());
}
public function watched(): HasMany
@@ -234,15 +228,16 @@ class Episode extends Model implements Sitemapable
return $this->hasMany(Watched::class);
}
public function getDownloadByType(string $type): Downloads | null
public function getDownloadByType(string $type): ?Downloads
{
$cacheKey = "episode_{$this->id}_download_{$type}";
return Cache::remember($cacheKey, now()->addMinutes(10), function () use ($type) {
return $this->downloads()->where('type', $type)->first();
});
}
public function toSitemapTag(): Url | string | array
public function toSitemapTag(): Url|string|array
{
return Url::create(route('hentai.index', $this->slug))
->setLastModificationDate(Carbon::create($this->created_at));

View File

@@ -2,19 +2,18 @@
namespace App\Models;
use Conner\Tagging\Taggable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Cache;
use Spatie\Sitemap\Contracts\Sitemapable;
use Spatie\Sitemap\Tags\Url;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Conner\Tagging\Taggable;
class Hentai extends Model implements Sitemapable
{
use Taggable;
use HasFactory;
use Taggable;
/**
* The attributes that are mass assignable.
@@ -31,7 +30,7 @@ class Hentai extends Model implements Sitemapable
return $this->hasMany(Episode::class, 'hentai_id');
}
public function title(): String
public function title(): string
{
return $this->episodes->first()->title;
}
@@ -63,7 +62,7 @@ class Hentai extends Model implements Sitemapable
);
}
public function toSitemapTag(): Url | string | array
public function toSitemapTag(): Url|string|array
{
return Url::create(route('hentai.index', $this->slug))
->setLastModificationDate(Carbon::create($this->created_at));

View File

@@ -2,8 +2,8 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Playlist extends Model
{

View File

@@ -2,8 +2,8 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class PlaylistEpisode extends Model
{

View File

@@ -13,7 +13,7 @@ class PopularDaily extends Model
*
* @var string[]
*/
protected $fillable = [ 'episode_id' ];
protected $fillable = ['episode_id'];
/**
* Get the Episode.

View File

@@ -13,7 +13,7 @@ class PopularMonthly extends Model
*
* @var string[]
*/
protected $fillable = [ 'episode_id' ];
protected $fillable = ['episode_id'];
/**
* Get the Episode.

View File

@@ -13,7 +13,7 @@ class PopularWeekly extends Model
*
* @var string[]
*/
protected $fillable = [ 'episode_id' ];
protected $fillable = ['episode_id'];
/**
* Get the Episode.

View File

@@ -25,4 +25,4 @@ class CommentPresenter
{
return $this->comment->created_at->diffForHumans();
}
}
}

View File

@@ -4,7 +4,6 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
class SiteBackground extends Model
{
@@ -16,19 +15,19 @@ class SiteBackground extends Model
protected $fillable = [
'date_start',
'date_end',
'default'
'default',
];
/**
* Returns the current IDs of active wallpaper
*/
public function getImages(): ? \Illuminate\Support\Collection
public function getImages(): ?\Illuminate\Support\Collection
{
$now = Carbon::now();
$byDates = $this->whereDate('date_start', '<=', $now)->whereDate('date_end', '>=', $now)->get()->pluck('id');
$default = $this->where('default', true)->get()->pluck('id');
return $byDates->isEmpty() ? $default : $byDates;
}
}

View File

@@ -3,13 +3,13 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Studios extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*

View File

@@ -2,16 +2,15 @@
namespace App\Models;
//use Illuminate\Contracts\Auth\MustVerifyEmail;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use App\Enums\UserRole;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
class User extends Authenticatable
{
@@ -62,7 +61,6 @@ class User extends Authenticatable
'discord_avatar' => 'string',
];
/**
* Has Many Playlists.
*/
@@ -100,7 +98,7 @@ class User extends Authenticatable
*/
public function commentCount(): int
{
return cache()->remember('userComments' . $this->id, 300, fn() => $this->comments->count());
return cache()->remember('userComments'.$this->id, 300, fn () => $this->comments->count());
}
/**
@@ -108,13 +106,11 @@ class User extends Authenticatable
*/
public function getAvatar(): string
{
if ($this->discord_id && $this->discord_avatar && !$this->avatar)
{
if ($this->discord_id && $this->discord_avatar && ! $this->avatar) {
return "https://external-content.duckduckgo.com/iu/?u={$this->discord_avatar}";
}
if ($this->avatar)
{
if ($this->avatar) {
return Storage::url($this->avatar);
}
@@ -153,7 +149,7 @@ class User extends Authenticatable
*/
public function removeRole(UserRole $role): void
{
if (!$this->hasRole($role)) {
if (! $this->hasRole($role)) {
return;
}

View File

@@ -2,8 +2,8 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class UserDownload extends Model
{

View File

@@ -2,8 +2,8 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Watched extends Model
{