mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-31 10:18:55 +00:00
Fix views inconsistencies
This commit is contained in:
@@ -6,6 +6,7 @@ namespace App\Models;
|
||||
|
||||
use App\Enums\UserRole;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
@@ -201,4 +202,56 @@ class Content extends Model
|
||||
{
|
||||
return $this->contenttype === self::TYPE_INDEX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the content URL: external URLs are used as-is (domains without
|
||||
* protocol get https://), internal paths are prefixed with the site URL.
|
||||
*
|
||||
* @return Attribute<string|null, never>
|
||||
*/
|
||||
protected function resolvedUrl(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: function (): ?string {
|
||||
$url = $this->url;
|
||||
|
||||
if (empty($url)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (str_starts_with($url, 'http://') || str_starts_with($url, 'https://')) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
// Domain pattern without protocol (e.g. google.com, chatgpt.ai)
|
||||
if (! str_starts_with($url, '/') && preg_match('/^[a-zA-Z0-9][a-zA-Z0-9-]*\.[a-zA-Z]{2,}/', $url)) {
|
||||
return 'https://'.$url;
|
||||
}
|
||||
|
||||
return url($url);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the content URL points to an external site.
|
||||
*
|
||||
* @return Attribute<bool, never>
|
||||
*/
|
||||
protected function isExternalUrl(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: function (): bool {
|
||||
$url = $this->url;
|
||||
|
||||
if (empty($url)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return str_starts_with($url, 'http://')
|
||||
|| str_starts_with($url, 'https://')
|
||||
|| (! str_starts_with($url, '/') && preg_match('/^[a-zA-Z0-9][a-zA-Z0-9-]*\.[a-zA-Z]{2,}/', $url));
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user