Allow heading tags (h1-h6) in ContentSanitizer so news editor headings render
This commit is contained in:
@@ -85,6 +85,13 @@ final class AcademyCourseController extends Controller
|
||||
'featuredCourses' => $featuredCourses->all(),
|
||||
'filters' => $filters,
|
||||
'pricingUrl' => route('academy.pricing'),
|
||||
'lessonsUrl' => route('academy.lessons.index'),
|
||||
'promptLibraryUrl' => route('academy.prompts.index'),
|
||||
'academyAccess' => array_merge($this->access->accessSummary($request->user()), [
|
||||
'billingUrl' => $request->user() && (bool) config('academy_billing.enabled', false)
|
||||
? route('academy.billing.account')
|
||||
: route('academy.pricing'),
|
||||
]),
|
||||
'analytics' => [
|
||||
'enabled' => true,
|
||||
'contentType' => null,
|
||||
|
||||
@@ -60,10 +60,16 @@ final class AcademyHomeController extends Controller
|
||||
return Inertia::render('Academy/Index', [
|
||||
'seo' => $seo,
|
||||
'pricingUrl' => route('academy.pricing'),
|
||||
'academyAccess' => array_merge($this->access->accessSummary($request->user()), [
|
||||
'billingUrl' => $request->user() && (bool) config('academy_billing.enabled', false)
|
||||
? route('academy.billing.account')
|
||||
: route('academy.pricing'),
|
||||
]),
|
||||
'links' => [
|
||||
'lessons' => route('academy.lessons.index'),
|
||||
'courses' => route('academy.courses.index'),
|
||||
'prompts' => route('academy.prompts.index'),
|
||||
'promptPopular' => route('academy.prompts.popular'),
|
||||
'packs' => route('academy.packs.index'),
|
||||
'challenges' => route('academy.challenges.index'),
|
||||
],
|
||||
|
||||
@@ -13,6 +13,7 @@ use App\Services\Academy\AcademyCacheService;
|
||||
use App\Services\Academy\AcademyInteractionService;
|
||||
use App\Support\AcademyAnalytics\AcademyAnalyticsContentType;
|
||||
use App\Support\Seo\SeoFactory;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Inertia;
|
||||
@@ -27,7 +28,7 @@ final class AcademyLessonController extends Controller
|
||||
private readonly AcademyInteractionService $interactions,
|
||||
) {}
|
||||
|
||||
public function index(Request $request): Response
|
||||
public function index(Request $request): Response|JsonResponse
|
||||
{
|
||||
abort_unless((bool) config('academy.enabled', true), 404);
|
||||
|
||||
@@ -65,6 +66,10 @@ final class AcademyLessonController extends Controller
|
||||
$this->analytics->trackSearch((string) $filters['q'], (int) $lessons->total(), array_filter($filters), $request);
|
||||
}
|
||||
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json($lessons);
|
||||
}
|
||||
|
||||
$seo = app(SeoFactory::class)
|
||||
->collectionListing(
|
||||
'Academy Lessons — Skinbase',
|
||||
@@ -78,10 +83,21 @@ final class AcademyLessonController extends Controller
|
||||
'title' => 'Academy lessons',
|
||||
'description' => 'Step-by-step tutorials and workflow guides for AI-assisted creative work on Skinbase.',
|
||||
'seo' => $seo,
|
||||
'breadcrumbs' => [
|
||||
['label' => 'Academy', 'href' => route('academy.index')],
|
||||
['label' => 'Lessons', 'href' => route('academy.lessons.index')],
|
||||
],
|
||||
'items' => $lessons,
|
||||
'filters' => $filters,
|
||||
'categories' => $this->cache->categoriesByType('lesson'),
|
||||
'pricingUrl' => route('academy.pricing'),
|
||||
'coursesUrl' => route('academy.courses.index'),
|
||||
'promptLibraryUrl' => route('academy.prompts.index'),
|
||||
'academyAccess' => array_merge($this->access->accessSummary($request->user()), [
|
||||
'billingUrl' => $request->user() && (bool) config('academy_billing.enabled', false)
|
||||
? route('academy.billing.account')
|
||||
: route('academy.pricing'),
|
||||
]),
|
||||
'analytics' => [
|
||||
'enabled' => true,
|
||||
'contentType' => filled($filters['q'] ?? null) ? AcademyAnalyticsContentType::SEARCH : null,
|
||||
|
||||
@@ -10,11 +10,13 @@ use App\Services\Academy\AcademyAccessService;
|
||||
use App\Services\Academy\AcademyAnalyticsService;
|
||||
use App\Services\Academy\AcademyCacheService;
|
||||
use App\Services\Academy\AcademyInteractionService;
|
||||
use App\Services\Academy\AcademyPopularityService;
|
||||
use App\Support\AcademyAnalytics\AcademyAnalyticsContentType;
|
||||
use App\Support\Seo\SeoFactory;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
@@ -25,6 +27,7 @@ final class AcademyPromptController extends Controller
|
||||
private readonly AcademyCacheService $cache,
|
||||
private readonly AcademyAnalyticsService $analytics,
|
||||
private readonly AcademyInteractionService $interactions,
|
||||
private readonly AcademyPopularityService $popularity,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -86,16 +89,32 @@ final class AcademyPromptController extends Controller
|
||||
|
||||
return Inertia::render('Academy/List', [
|
||||
'pageType' => 'prompts',
|
||||
'promptView' => 'library',
|
||||
'title' => 'Prompt library',
|
||||
'description' => 'Reusable prompt templates for wallpapers, worlds, mascots, covers, and digital art workflows.',
|
||||
'seo' => $seo,
|
||||
'breadcrumbs' => [
|
||||
['label' => 'Academy', 'href' => route('academy.index')],
|
||||
['label' => 'Prompt Library', 'href' => route('academy.prompts.index')],
|
||||
],
|
||||
'items' => $prompts,
|
||||
'filters' => $filters,
|
||||
'categories' => $this->cache->categoriesByType('prompt'),
|
||||
'pricingUrl' => route('academy.pricing'),
|
||||
'coursesUrl' => route('academy.courses.index'),
|
||||
'packsUrl' => route('academy.packs.index'),
|
||||
'promptPopularUrl' => route('academy.prompts.popular'),
|
||||
'promptLibraryUrl' => route('academy.prompts.index'),
|
||||
'academyAccess' => array_merge($this->access->accessSummary($request->user()), [
|
||||
'billingUrl' => $request->user() && (bool) config('academy_billing.enabled', false)
|
||||
? route('academy.billing.account')
|
||||
: route('academy.pricing'),
|
||||
]),
|
||||
'featuredPrompts' => $this->featuredPromptPayloads($request->user()),
|
||||
'popularPrompts' => $this->popularPromptPayloads($request->user()),
|
||||
'analytics' => [
|
||||
'enabled' => true,
|
||||
'contentType' => filled($filters['q'] ?? null) ? AcademyAnalyticsContentType::SEARCH : null,
|
||||
'contentType' => AcademyAnalyticsContentType::PROMPT_LIBRARY,
|
||||
'contentId' => null,
|
||||
'eventUrl' => route('academy.analytics.events.store'),
|
||||
'pageName' => 'academy_prompts_index',
|
||||
@@ -110,6 +129,186 @@ final class AcademyPromptController extends Controller
|
||||
])->rootView('collections');
|
||||
}
|
||||
|
||||
public function popular(Request $request): Response
|
||||
{
|
||||
abort_unless((bool) config('academy.enabled', true), 404);
|
||||
|
||||
$validated = $request->validate([
|
||||
'period' => ['nullable', 'string', 'in:7d,30d,90d'],
|
||||
]);
|
||||
|
||||
$selectedPeriod = $this->selectedPopularPromptPeriod($validated['period'] ?? null);
|
||||
$from = now()->subDays($selectedPeriod['days'] - 1)->startOfDay();
|
||||
$to = now()->endOfDay();
|
||||
|
||||
$rows = DB::query()
|
||||
->fromSub(
|
||||
$this->popularity->queryBetween($from, $to)
|
||||
->where('content_type', AcademyAnalyticsContentType::PROMPT)
|
||||
->whereNotNull('content_id')
|
||||
->selectRaw('content_id, sum(views) as views, sum(prompt_copies) as prompt_copies, sum(popularity_score) as popularity_score')
|
||||
->groupBy('content_id'),
|
||||
'prompt_rankings'
|
||||
)
|
||||
->orderByDesc('popularity_score')
|
||||
->orderByDesc('prompt_copies')
|
||||
->orderByDesc('views')
|
||||
->paginate(12)
|
||||
->withQueryString();
|
||||
|
||||
$prompts = AcademyPromptTemplate::query()
|
||||
->with('category')
|
||||
->active()
|
||||
->published()
|
||||
->whereIn('id', $rows->pluck('content_id')->map(static fn ($value): int => (int) $value)->all())
|
||||
->get()
|
||||
->keyBy('id');
|
||||
|
||||
$baseRank = (($rows->currentPage() - 1) * $rows->perPage());
|
||||
|
||||
$rows->setCollection(
|
||||
$rows->getCollection()
|
||||
->values()
|
||||
->map(function (object $row, int $index) use ($prompts, $request, $baseRank, $selectedPeriod): ?array {
|
||||
$prompt = $prompts->get((int) $row->content_id);
|
||||
|
||||
if (! $prompt instanceof AcademyPromptTemplate) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$payload = $this->access->promptPayload($prompt, $request->user());
|
||||
$payload['ranking'] = [
|
||||
'rank' => $baseRank + $index + 1,
|
||||
'views' => max(0, (int) ($row->views ?? 0)),
|
||||
'prompt_copies' => max(0, (int) ($row->prompt_copies ?? 0)),
|
||||
'popularity_score' => round((float) ($row->popularity_score ?? 0), 2),
|
||||
];
|
||||
$payload['spotlight'] = [
|
||||
'eyebrow' => max(0, (int) ($row->prompt_copies ?? 0)) > 0
|
||||
? sprintf('%d copies %s', (int) $row->prompt_copies, $selectedPeriod['eyebrow_suffix'])
|
||||
: sprintf('%d views %s', (int) $row->views, $selectedPeriod['eyebrow_suffix']),
|
||||
];
|
||||
|
||||
return $payload;
|
||||
})
|
||||
->filter()
|
||||
->values()
|
||||
);
|
||||
|
||||
$seo = app(SeoFactory::class)
|
||||
->collectionListing(
|
||||
sprintf('%s Prompts — Skinbase Academy', $selectedPeriod['title_prefix']),
|
||||
sprintf('See which Skinbase Academy prompt templates are driving the most views and copies %s.', $selectedPeriod['description_suffix']),
|
||||
route('academy.prompts.popular', $request->query()),
|
||||
)
|
||||
->toArray();
|
||||
|
||||
return Inertia::render('Academy/List', [
|
||||
'pageType' => 'prompts',
|
||||
'promptView' => 'popular',
|
||||
'title' => sprintf('%s prompts', $selectedPeriod['title_prefix']),
|
||||
'description' => sprintf('The prompt templates getting the most momentum from views and copies across the Academy %s.', $selectedPeriod['description_suffix']),
|
||||
'seo' => $seo,
|
||||
'breadcrumbs' => [
|
||||
['label' => 'Academy', 'href' => route('academy.index')],
|
||||
['label' => 'Prompt Library', 'href' => route('academy.prompts.index')],
|
||||
['label' => 'Popular Prompts', 'href' => route('academy.prompts.popular')],
|
||||
],
|
||||
'items' => $rows,
|
||||
'filters' => [],
|
||||
'categories' => [],
|
||||
'pricingUrl' => route('academy.pricing'),
|
||||
'coursesUrl' => route('academy.courses.index'),
|
||||
'packsUrl' => route('academy.packs.index'),
|
||||
'promptPopularUrl' => route('academy.prompts.popular'),
|
||||
'promptLibraryUrl' => route('academy.prompts.index'),
|
||||
'academyAccess' => array_merge($this->access->accessSummary($request->user()), [
|
||||
'billingUrl' => $request->user() && (bool) config('academy_billing.enabled', false)
|
||||
? route('academy.billing.account')
|
||||
: route('academy.pricing'),
|
||||
]),
|
||||
'popularPeriod' => [
|
||||
'value' => $selectedPeriod['value'],
|
||||
'label' => $selectedPeriod['label'],
|
||||
'description' => $selectedPeriod['description'],
|
||||
],
|
||||
'popularPeriods' => collect($this->popularPromptPeriods())
|
||||
->map(fn (array $period): array => [
|
||||
'value' => $period['value'],
|
||||
'label' => $period['label'],
|
||||
'description' => $period['description'],
|
||||
'href' => route('academy.prompts.popular', ['period' => $period['value']]),
|
||||
'active' => $period['value'] === $selectedPeriod['value'],
|
||||
])
|
||||
->values()
|
||||
->all(),
|
||||
'featuredPrompts' => $this->featuredPromptPayloads($request->user()),
|
||||
'popularPrompts' => [],
|
||||
'analytics' => [
|
||||
'enabled' => true,
|
||||
'contentType' => AcademyAnalyticsContentType::PROMPT_POPULAR,
|
||||
'contentId' => null,
|
||||
'eventUrl' => route('academy.analytics.events.store'),
|
||||
'pageName' => 'academy_prompts_popular',
|
||||
'trackingKey' => sprintf('period:%s', $selectedPeriod['value']),
|
||||
'metadata' => [
|
||||
'period' => $selectedPeriod['value'],
|
||||
'period_days' => $selectedPeriod['days'],
|
||||
],
|
||||
'search' => null,
|
||||
'isPremium' => false,
|
||||
'isGuest' => $request->user() === null,
|
||||
'isSubscriber' => $request->user()?->hasAcademyCreatorAccess() || $request->user()?->hasAcademyProAccess(),
|
||||
],
|
||||
])->rootView('collections');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
private function popularPromptPeriods(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'value' => '7d',
|
||||
'days' => 7,
|
||||
'label' => '7 days',
|
||||
'description' => 'Fresh momentum from the last 7 days.',
|
||||
'title_prefix' => 'Top 7-day',
|
||||
'description_suffix' => 'in the last 7 days',
|
||||
'eyebrow_suffix' => 'in the last 7 days',
|
||||
],
|
||||
[
|
||||
'value' => '30d',
|
||||
'days' => 30,
|
||||
'label' => '30 days',
|
||||
'description' => 'The default monthly view of prompt momentum.',
|
||||
'title_prefix' => 'Popular',
|
||||
'description_suffix' => 'this month',
|
||||
'eyebrow_suffix' => 'this month',
|
||||
],
|
||||
[
|
||||
'value' => '90d',
|
||||
'days' => 90,
|
||||
'label' => '90 days',
|
||||
'description' => 'Longer-running prompt momentum across the quarter.',
|
||||
'title_prefix' => 'Top 90-day',
|
||||
'description_suffix' => 'in the last 90 days',
|
||||
'eyebrow_suffix' => 'in the last 90 days',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function selectedPopularPromptPeriod(?string $value): array
|
||||
{
|
||||
return collect($this->popularPromptPeriods())
|
||||
->first(fn (array $period): bool => $period['value'] === $value)
|
||||
?? $this->popularPromptPeriods()[1];
|
||||
}
|
||||
|
||||
public function show(Request $request, string $slug): Response
|
||||
{
|
||||
abort_unless((bool) config('academy.enabled', true), 404);
|
||||
@@ -201,4 +400,70 @@ final class AcademyPromptController extends Controller
|
||||
],
|
||||
], fn (mixed $value): bool => $value !== null && $value !== '' && $value !== []);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
private function featuredPromptPayloads(mixed $viewer, int $limit = 4): array
|
||||
{
|
||||
return collect($this->cache->featuredPrompts())
|
||||
->take($limit)
|
||||
->map(function (AcademyPromptTemplate $prompt) use ($viewer): array {
|
||||
$payload = $this->access->promptPayload($prompt, $viewer);
|
||||
$payload['spotlight'] = [
|
||||
'eyebrow' => $prompt->prompt_of_week ? 'Prompt of the week' : 'Featured pick',
|
||||
];
|
||||
|
||||
return $payload;
|
||||
})
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
private function popularPromptPayloads(mixed $viewer, int $limit = 4): array
|
||||
{
|
||||
$rows = $this->popularity->queryBetween(now()->subDays(29)->startOfDay(), now()->endOfDay())
|
||||
->where('content_type', AcademyAnalyticsContentType::PROMPT)
|
||||
->whereNotNull('content_id')
|
||||
->selectRaw('content_id, sum(views) as views, sum(prompt_copies) as prompt_copies, sum(popularity_score) as popularity_score')
|
||||
->groupBy('content_id')
|
||||
->orderByDesc('popularity_score')
|
||||
->limit($limit)
|
||||
->get();
|
||||
|
||||
if ($rows->isEmpty()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$prompts = AcademyPromptTemplate::query()
|
||||
->with('category')
|
||||
->active()
|
||||
->published()
|
||||
->whereIn('id', $rows->pluck('content_id')->all())
|
||||
->get()
|
||||
->keyBy('id');
|
||||
|
||||
return $rows->map(function ($row) use ($prompts, $viewer): ?array {
|
||||
$prompt = $prompts->get((int) $row->content_id);
|
||||
|
||||
if (! $prompt instanceof AcademyPromptTemplate) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$payload = $this->access->promptPayload($prompt, $viewer);
|
||||
$copies = max(0, (int) ($row->prompt_copies ?? 0));
|
||||
$views = max(0, (int) ($row->views ?? 0));
|
||||
$payload['spotlight'] = [
|
||||
'eyebrow' => $copies > 0 ? sprintf('%d copies this month', $copies) : sprintf('%d views this month', $views),
|
||||
];
|
||||
|
||||
return $payload;
|
||||
})
|
||||
->filter()
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,6 @@ final class AcademyPromptPackController extends Controller
|
||||
abort_unless((bool) config('academy.enabled', true), 404);
|
||||
|
||||
$packs = AcademyPromptPack::query()
|
||||
->with('prompts')
|
||||
->active()
|
||||
->published()
|
||||
->latest('published_at')
|
||||
@@ -57,7 +56,7 @@ final class AcademyPromptPackController extends Controller
|
||||
'pricingUrl' => route('academy.pricing'),
|
||||
'analytics' => [
|
||||
'enabled' => true,
|
||||
'contentType' => null,
|
||||
'contentType' => AcademyAnalyticsContentType::PROMPT_PACK_LIBRARY,
|
||||
'contentId' => null,
|
||||
'eventUrl' => route('academy.analytics.events.store'),
|
||||
'pageName' => 'academy_packs_index',
|
||||
|
||||
@@ -53,7 +53,12 @@ class LinkPreviewController extends Controller
|
||||
return response()->json(['error' => 'Invalid URL.'], 422);
|
||||
}
|
||||
|
||||
// Resolve hostname and block private/loopback IPs (SSRF protection)
|
||||
// Resolve hostname and block private/loopback IPs (SSRF protection).
|
||||
// NOTE: This check is not atomic with Guzzle's own DNS resolution — a
|
||||
// DNS rebinding attack could theoretically pass this check and then
|
||||
// resolve to an internal IP when Guzzle makes the actual request.
|
||||
// Risk is low (requires attacker-controlled DNS with very short TTL),
|
||||
// but this is a known limitation of the current approach.
|
||||
$resolved = gethostbyname($host);
|
||||
if ($this->isBlockedIp($resolved)) {
|
||||
return response()->json(['error' => 'URL not allowed.'], 422);
|
||||
|
||||
@@ -47,7 +47,9 @@ use App\Uploads\Exceptions\DraftQuotaException;
|
||||
use App\Models\Artwork;
|
||||
use App\Models\Group;
|
||||
use App\Services\GroupArtworkReviewService;
|
||||
use App\Support\ArtworkDescriptionContentValidator;
|
||||
use App\Services\Worlds\WorldSubmissionService;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
final class UploadController extends Controller
|
||||
@@ -534,6 +536,8 @@ final class UploadController extends Controller
|
||||
'nsfw' => ['nullable', 'boolean'],
|
||||
]);
|
||||
|
||||
$this->ensureValidArtworkDescription($validated);
|
||||
|
||||
$updates = [];
|
||||
foreach (['title', 'category_id', 'description', 'tags', 'license', 'nsfw'] as $field) {
|
||||
if (array_key_exists($field, $validated)) {
|
||||
@@ -635,6 +639,8 @@ final class UploadController extends Controller
|
||||
'world_submissions.*.source_surface' => ['nullable', 'string', 'max:80'],
|
||||
]);
|
||||
|
||||
$this->ensureValidArtworkDescription($validated);
|
||||
|
||||
$mode = $validated['mode'] ?? 'now';
|
||||
$visibility = $validated['visibility'] ?? 'public';
|
||||
|
||||
@@ -814,6 +820,8 @@ final class UploadController extends Controller
|
||||
'world_submissions.*.source_surface' => ['nullable', 'string', 'max:80'],
|
||||
]);
|
||||
|
||||
$this->ensureValidArtworkDescription($validated);
|
||||
|
||||
if (! ctype_digit($id)) {
|
||||
return response()->json(['message' => 'Artwork review submission requires an artwork draft id.'], Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
@@ -842,4 +850,13 @@ final class UploadController extends Controller
|
||||
'group_review_status' => (string) $artwork->group_review_status,
|
||||
], Response::HTTP_OK);
|
||||
}
|
||||
|
||||
private function ensureValidArtworkDescription(array $validated): void
|
||||
{
|
||||
foreach (ArtworkDescriptionContentValidator::errors($validated['description'] ?? null) as $message) {
|
||||
throw ValidationException::withMessages([
|
||||
'description' => [$message],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
52
app/Http/Controllers/ArtworkEnhanceController.php
Normal file
52
app/Http/Controllers/ArtworkEnhanceController.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Artwork;
|
||||
use App\Services\Enhance\EnhanceService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
use RuntimeException;
|
||||
|
||||
final class ArtworkEnhanceController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EnhanceService $enhanceService,
|
||||
) {
|
||||
}
|
||||
|
||||
public function store(Request $request, int $artwork): RedirectResponse
|
||||
{
|
||||
$artwork = Artwork::query()->findOrFail($artwork);
|
||||
|
||||
$actor = $request->user();
|
||||
abort_unless($actor !== null, 403);
|
||||
|
||||
$isOwner = (int) $artwork->user_id === (int) $actor->id;
|
||||
$isStaff = $actor->isAdmin() || $actor->isModerator();
|
||||
|
||||
abort_unless($isOwner || $isStaff, 403);
|
||||
|
||||
$validated = $request->validate([
|
||||
'scale' => ['required', 'integer', Rule::in((array) config('enhance.allowed_scales', [2, 4]))],
|
||||
'mode' => ['required', 'string', Rule::in((array) config('enhance.allowed_modes', ['standard', 'artwork', 'photo', 'illustration']))],
|
||||
]);
|
||||
|
||||
try {
|
||||
$job = $this->enhanceService->createFromArtwork($actor, $artwork, $validated);
|
||||
} catch (RuntimeException $exception) {
|
||||
return redirect()
|
||||
->route('enhance.create', ['artwork' => $artwork->id])
|
||||
->withErrors([
|
||||
'source' => $exception->getMessage(),
|
||||
]);
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->route('enhance.show', ['enhanceJob' => $job])
|
||||
->with('success', 'Artwork enhance job created.');
|
||||
}
|
||||
}
|
||||
208
app/Http/Controllers/EnhanceController.php
Normal file
208
app/Http/Controllers/EnhanceController.php
Normal file
@@ -0,0 +1,208 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Artwork;
|
||||
use App\Models\EnhanceJob;
|
||||
use App\Services\Enhance\EnhanceService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
final class EnhanceController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EnhanceService $enhanceService,
|
||||
) {
|
||||
}
|
||||
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$this->authorize('viewAny', EnhanceJob::class);
|
||||
|
||||
$jobs = EnhanceJob::query()
|
||||
->where('user_id', (int) $request->user()->id)
|
||||
->with('artwork:id,title,slug')
|
||||
->latest('id')
|
||||
->paginate(12)
|
||||
->withQueryString()
|
||||
->through(fn (EnhanceJob $job): array => $this->serializeJobListItem($job));
|
||||
|
||||
$latestCompleted = EnhanceJob::query()
|
||||
->where('user_id', (int) $request->user()->id)
|
||||
->where('status', EnhanceJob::STATUS_COMPLETED)
|
||||
->latest('finished_at')
|
||||
->limit(4)
|
||||
->get()
|
||||
->map(fn (EnhanceJob $job): array => $this->serializeJobListItem($job))
|
||||
->all();
|
||||
|
||||
return Inertia::render('Enhance/Index', [
|
||||
'title' => 'Skinbase Enhance',
|
||||
'jobs' => $jobs,
|
||||
'latestCompleted' => $latestCompleted,
|
||||
'createUrl' => route('enhance.create'),
|
||||
'indexUrl' => route('enhance.index'),
|
||||
'dailyLimit' => (int) config('enhance.daily_limit', 10),
|
||||
'enhanceConfig' => $this->enhanceService->frontendConfig(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(Request $request): Response
|
||||
{
|
||||
$this->authorize('create', EnhanceJob::class);
|
||||
|
||||
$selectedArtwork = null;
|
||||
|
||||
if (($artworkId = (int) $request->integer('artwork')) > 0) {
|
||||
$artwork = Artwork::query()
|
||||
->select(['id', 'user_id', 'title', 'slug'])
|
||||
->findOrFail($artworkId);
|
||||
|
||||
$actor = $request->user();
|
||||
abort_unless($actor !== null, 403);
|
||||
|
||||
$isOwner = (int) $artwork->user_id === (int) $actor->id;
|
||||
$isStaff = $actor->isAdmin() || $actor->isModerator();
|
||||
|
||||
abort_unless($isOwner || $isStaff, 403);
|
||||
|
||||
$selectedArtwork = [
|
||||
'id' => $artwork->id,
|
||||
'title' => $artwork->title,
|
||||
'show_url' => route('art.show', ['id' => $artwork->id, 'slug' => $artwork->slug]),
|
||||
'store_url' => route('artworks.enhance.store', ['artwork' => $artwork->id]),
|
||||
];
|
||||
}
|
||||
|
||||
return Inertia::render('Enhance/Create', [
|
||||
'title' => 'Skinbase Enhance',
|
||||
'options' => $this->optionsPayload(),
|
||||
'storeUrl' => route('enhance.store'),
|
||||
'indexUrl' => route('enhance.index'),
|
||||
'maxUploadMb' => (int) config('enhance.max_upload_mb', 20),
|
||||
'selectedArtwork' => $selectedArtwork,
|
||||
'enhanceConfig' => $this->enhanceService->frontendConfig(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$this->authorize('create', EnhanceJob::class);
|
||||
|
||||
$validated = $request->validate([
|
||||
'image' => ['required', 'file', 'mimetypes:image/jpeg,image/png,image/webp', 'max:' . ((int) config('enhance.max_upload_mb', 20) * 1024)],
|
||||
'scale' => ['required', 'integer', Rule::in((array) config('enhance.allowed_scales', [2, 4]))],
|
||||
'mode' => ['required', 'string', Rule::in((array) config('enhance.allowed_modes', ['standard', 'artwork', 'photo', 'illustration']))],
|
||||
]);
|
||||
|
||||
$job = $this->enhanceService->createFromUpload($request->user(), $request->file('image'), $validated);
|
||||
|
||||
return redirect()
|
||||
->route('enhance.show', ['enhanceJob' => $job])
|
||||
->with('success', 'Enhance job created.');
|
||||
}
|
||||
|
||||
public function show(EnhanceJob $enhanceJob): Response
|
||||
{
|
||||
$this->authorize('view', $enhanceJob);
|
||||
$enhanceJob->loadMissing('artwork:id,title,slug');
|
||||
|
||||
return Inertia::render('Enhance/Show', [
|
||||
'title' => 'Enhance Job',
|
||||
'job' => $this->serializeJobDetail($enhanceJob),
|
||||
'indexUrl' => route('enhance.index'),
|
||||
'createUrl' => route('enhance.create'),
|
||||
'enhanceConfig' => $this->enhanceService->frontendConfig(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function retry(EnhanceJob $enhanceJob): RedirectResponse
|
||||
{
|
||||
$this->authorize('retry', $enhanceJob);
|
||||
|
||||
$job = $this->enhanceService->retry($enhanceJob);
|
||||
|
||||
return redirect()
|
||||
->route('enhance.show', ['enhanceJob' => $job])
|
||||
->with('success', 'Enhance job queued again.');
|
||||
}
|
||||
|
||||
public function destroy(EnhanceJob $enhanceJob): RedirectResponse
|
||||
{
|
||||
$this->authorize('delete', $enhanceJob);
|
||||
|
||||
$this->enhanceService->delete($enhanceJob);
|
||||
|
||||
return redirect()
|
||||
->route('enhance.index')
|
||||
->with('success', 'Enhance job deleted.');
|
||||
}
|
||||
|
||||
private function optionsPayload(): array
|
||||
{
|
||||
return [
|
||||
'modes' => array_map(fn (string $mode): array => [
|
||||
'value' => $mode,
|
||||
'label' => ucfirst($mode),
|
||||
], (array) config('enhance.allowed_modes', [])),
|
||||
'scales' => array_map(fn (int $scale): array => [
|
||||
'value' => $scale,
|
||||
'label' => $scale . 'x',
|
||||
], array_map('intval', (array) config('enhance.allowed_scales', []))),
|
||||
];
|
||||
}
|
||||
|
||||
private function serializeJobListItem(EnhanceJob $job): array
|
||||
{
|
||||
return [
|
||||
'id' => $job->id,
|
||||
'status' => (string) $job->status,
|
||||
'engine' => (string) $job->engine,
|
||||
'mode' => (string) $job->mode,
|
||||
'scale' => (int) $job->scale,
|
||||
'source_url' => $job->sourceUrl(),
|
||||
'output_url' => $job->outputUrl(),
|
||||
'preview_url' => $job->previewUrl(),
|
||||
'input_width' => (int) ($job->input_width ?? 0),
|
||||
'input_height' => (int) ($job->input_height ?? 0),
|
||||
'output_width' => (int) ($job->output_width ?? 0),
|
||||
'output_height' => (int) ($job->output_height ?? 0),
|
||||
'error_message' => $job->error_message,
|
||||
'processing_seconds' => $job->processing_seconds,
|
||||
'created_at' => optional($job->created_at)?->toIso8601String(),
|
||||
'finished_at' => optional($job->finished_at)?->toIso8601String(),
|
||||
'show_url' => route('enhance.show', ['enhanceJob' => $job]),
|
||||
'artwork' => $job->artwork ? [
|
||||
'id' => $job->artwork->id,
|
||||
'title' => $job->artwork->title,
|
||||
'slug' => $job->artwork->slug,
|
||||
'url' => route('art.show', ['id' => $job->artwork->id, 'slug' => $job->artwork->slug]),
|
||||
] : null,
|
||||
];
|
||||
}
|
||||
|
||||
private function serializeJobDetail(EnhanceJob $job): array
|
||||
{
|
||||
return $this->serializeJobListItem($job) + [
|
||||
'input_filesize' => (int) ($job->input_filesize ?? 0),
|
||||
'input_mime' => $job->input_mime,
|
||||
'output_filesize' => (int) ($job->output_filesize ?? 0),
|
||||
'output_mime' => $job->output_mime,
|
||||
'metadata' => $job->metadata ?? [],
|
||||
'queued_at' => optional($job->queued_at)?->toIso8601String(),
|
||||
'started_at' => optional($job->started_at)?->toIso8601String(),
|
||||
'deleted_at' => optional($job->deleted_at)?->toIso8601String(),
|
||||
'expires_at' => optional($job->expires_at)?->toIso8601String(),
|
||||
'retry_url' => route('enhance.retry', ['enhanceJob' => $job]),
|
||||
'delete_url' => route('enhance.destroy', ['enhanceJob' => $job]),
|
||||
'download_url' => $job->outputUrl(),
|
||||
'can_retry' => auth()->user()?->can('retry', $job) ?? false,
|
||||
'can_delete' => auth()->user()?->can('delete', $job) ?? false,
|
||||
];
|
||||
}
|
||||
}
|
||||
39
app/Http/Controllers/Internal/EnhanceSourceController.php
Normal file
39
app/Http/Controllers/Internal/EnhanceSourceController.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Internal;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\EnhanceJob;
|
||||
use App\Services\Enhance\EnhanceStorageService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Throwable;
|
||||
|
||||
final class EnhanceSourceController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EnhanceStorageService $storage,
|
||||
) {
|
||||
}
|
||||
|
||||
public function show(Request $request, EnhanceJob $enhanceJob): Response
|
||||
{
|
||||
abort_unless($request->hasValidSignature(), 403);
|
||||
abort_unless($this->storage->isEnhancePath($enhanceJob->source_path), 404);
|
||||
|
||||
try {
|
||||
$binary = $this->storage->fetchSourceBinary($enhanceJob);
|
||||
} catch (Throwable) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
return response($binary, 200, [
|
||||
'Content-Type' => trim((string) ($enhanceJob->input_mime ?: 'application/octet-stream')),
|
||||
'Content-Length' => (string) strlen($binary),
|
||||
'Cache-Control' => 'private, max-age=60',
|
||||
'Content-Disposition' => 'inline; filename="enhance-source-' . $enhanceJob->id . '"',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -79,19 +79,27 @@ class UserController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$allowedLegacyMimes = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'];
|
||||
|
||||
if ($request->hasFile('personal_picture')) {
|
||||
$f = $request->file('personal_picture');
|
||||
$name = $user->id . '.' . $f->getClientOriginalExtension();
|
||||
$f->move(public_path('user-picture'), $name);
|
||||
$profileUpdates['cover_image'] = $name;
|
||||
$user->picture = $name;
|
||||
if (in_array($f->getMimeType(), $allowedLegacyMimes, true)) {
|
||||
$ext = $f->guessExtension() ?: 'jpg';
|
||||
$name = $user->id . '.' . $ext;
|
||||
$f->move(public_path('user-picture'), $name);
|
||||
$profileUpdates['cover_image'] = $name;
|
||||
$user->picture = $name;
|
||||
}
|
||||
}
|
||||
|
||||
if ($request->hasFile('emotion_icon')) {
|
||||
$f = $request->file('emotion_icon');
|
||||
$name = $user->id . '.' . $f->getClientOriginalExtension();
|
||||
$f->move(public_path('emotion'), $name);
|
||||
$user->eicon = $name;
|
||||
if (in_array($f->getMimeType(), $allowedLegacyMimes, true)) {
|
||||
$ext = $f->guessExtension() ?: 'jpg';
|
||||
$name = $user->id . '.' . $ext;
|
||||
$f->move(public_path('emotion'), $name);
|
||||
$user->eicon = $name;
|
||||
}
|
||||
}
|
||||
|
||||
// Save core user fields
|
||||
|
||||
162
app/Http/Controllers/Moderation/ModerationEnhanceController.php
Normal file
162
app/Http/Controllers/Moderation/ModerationEnhanceController.php
Normal file
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Moderation;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\EnhanceJob;
|
||||
use App\Services\Enhance\EnhanceService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
final class ModerationEnhanceController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EnhanceService $enhanceService,
|
||||
) {
|
||||
}
|
||||
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$filters = [
|
||||
'status' => trim((string) $request->query('status', 'all')),
|
||||
'engine' => trim((string) $request->query('engine', 'all')),
|
||||
'mode' => trim((string) $request->query('mode', 'all')),
|
||||
'scale' => trim((string) $request->query('scale', 'all')),
|
||||
'user' => trim((string) $request->query('user', '')),
|
||||
'date_from' => trim((string) $request->query('date_from', '')),
|
||||
'date_to' => trim((string) $request->query('date_to', '')),
|
||||
];
|
||||
|
||||
$jobs = EnhanceJob::query()
|
||||
->with(['user:id,name,username', 'artwork:id,title,slug'])
|
||||
->when($filters['status'] !== '' && $filters['status'] !== 'all', fn ($query) => $query->where('status', $filters['status']))
|
||||
->when($filters['engine'] !== '' && $filters['engine'] !== 'all', fn ($query) => $query->where('engine', $filters['engine']))
|
||||
->when($filters['mode'] !== '' && $filters['mode'] !== 'all', fn ($query) => $query->where('mode', $filters['mode']))
|
||||
->when($filters['scale'] !== '' && $filters['scale'] !== 'all', fn ($query) => $query->where('scale', (int) $filters['scale']))
|
||||
->when($filters['user'] !== '', function ($query) use ($filters): void {
|
||||
$query->whereHas('user', function ($userQuery) use ($filters): void {
|
||||
$userQuery
|
||||
->where('name', 'like', '%' . $filters['user'] . '%')
|
||||
->orWhere('username', 'like', '%' . $filters['user'] . '%');
|
||||
});
|
||||
})
|
||||
->when($filters['date_from'] !== '', fn ($query) => $query->whereDate('created_at', '>=', $filters['date_from']))
|
||||
->when($filters['date_to'] !== '', fn ($query) => $query->whereDate('created_at', '<=', $filters['date_to']))
|
||||
->latest('id')
|
||||
->paginate(20)
|
||||
->withQueryString()
|
||||
->through(fn (EnhanceJob $job): array => $this->serializeJob($job));
|
||||
|
||||
return Inertia::render('Moderation/Enhance/Index', [
|
||||
'title' => 'Enhance Jobs',
|
||||
'jobs' => $jobs,
|
||||
'filters' => $filters,
|
||||
'options' => [
|
||||
'statuses' => ['all', 'pending', 'queued', 'processing', 'completed', 'failed', 'cancelled', 'expired'],
|
||||
'engines' => ['all', 'stub', 'external_worker'],
|
||||
'modes' => array_merge(['all'], (array) config('enhance.allowed_modes', [])),
|
||||
'scales' => array_merge(['all'], array_map('intval', (array) config('enhance.allowed_scales', []))),
|
||||
],
|
||||
'indexUrl' => route('admin.enhance.index'),
|
||||
'enhanceConfig' => $this->enhanceService->frontendConfig(),
|
||||
])->rootView('moderation');
|
||||
}
|
||||
|
||||
public function show(EnhanceJob $enhanceJob): Response
|
||||
{
|
||||
$enhanceJob->loadMissing(['user:id,name,username', 'artwork:id,title,slug']);
|
||||
|
||||
return Inertia::render('Moderation/Enhance/Show', [
|
||||
'title' => 'Enhance Job #' . $enhanceJob->id,
|
||||
'job' => $this->serializeJob($enhanceJob, true),
|
||||
'indexUrl' => route('admin.enhance.index'),
|
||||
'enhanceConfig' => $this->enhanceService->frontendConfig(),
|
||||
])->rootView('moderation');
|
||||
}
|
||||
|
||||
public function retry(EnhanceJob $enhanceJob): RedirectResponse
|
||||
{
|
||||
$this->authorize('retry', $enhanceJob);
|
||||
|
||||
$job = $this->enhanceService->retry($enhanceJob);
|
||||
|
||||
return redirect()
|
||||
->route('admin.enhance.show', ['enhanceJob' => $job])
|
||||
->with('success', 'Enhance job queued again.');
|
||||
}
|
||||
|
||||
public function markFailed(Request $request, EnhanceJob $enhanceJob): RedirectResponse
|
||||
{
|
||||
$this->authorize('markFailed', $enhanceJob);
|
||||
|
||||
$job = $this->enhanceService->markFailedByModerator($enhanceJob, $request->user());
|
||||
|
||||
return redirect()
|
||||
->route('admin.enhance.show', ['enhanceJob' => $job])
|
||||
->with('success', 'Enhance job marked as failed.');
|
||||
}
|
||||
|
||||
public function destroy(EnhanceJob $enhanceJob): RedirectResponse
|
||||
{
|
||||
$this->authorize('delete', $enhanceJob);
|
||||
|
||||
$this->enhanceService->delete($enhanceJob);
|
||||
|
||||
return redirect()
|
||||
->route('admin.enhance.index')
|
||||
->with('success', 'Enhance job deleted.');
|
||||
}
|
||||
|
||||
private function serializeJob(EnhanceJob $job, bool $detailed = false): array
|
||||
{
|
||||
return [
|
||||
'id' => $job->id,
|
||||
'status' => (string) $job->status,
|
||||
'engine' => (string) $job->engine,
|
||||
'mode' => (string) $job->mode,
|
||||
'scale' => (int) $job->scale,
|
||||
'source_url' => $job->sourceUrl(),
|
||||
'output_url' => $job->outputUrl(),
|
||||
'preview_url' => $job->previewUrl(),
|
||||
'input_width' => (int) ($job->input_width ?? 0),
|
||||
'input_height' => (int) ($job->input_height ?? 0),
|
||||
'input_filesize' => (int) ($job->input_filesize ?? 0),
|
||||
'input_mime' => $job->input_mime,
|
||||
'output_width' => (int) ($job->output_width ?? 0),
|
||||
'output_height' => (int) ($job->output_height ?? 0),
|
||||
'output_filesize' => (int) ($job->output_filesize ?? 0),
|
||||
'output_mime' => $job->output_mime,
|
||||
'processing_seconds' => $job->processing_seconds,
|
||||
'error_message' => $job->error_message,
|
||||
'metadata' => $job->metadata ?? [],
|
||||
'created_at' => optional($job->created_at)?->toIso8601String(),
|
||||
'queued_at' => optional($job->queued_at)?->toIso8601String(),
|
||||
'started_at' => optional($job->started_at)?->toIso8601String(),
|
||||
'finished_at' => optional($job->finished_at)?->toIso8601String(),
|
||||
'expires_at' => optional($job->expires_at)?->toIso8601String(),
|
||||
'user' => $job->user ? [
|
||||
'id' => $job->user->id,
|
||||
'name' => $job->user->name,
|
||||
'username' => $job->user->username,
|
||||
] : null,
|
||||
'artwork' => $job->artwork ? [
|
||||
'id' => $job->artwork->id,
|
||||
'title' => $job->artwork->title,
|
||||
'slug' => $job->artwork->slug,
|
||||
'url' => route('art.show', ['id' => $job->artwork->id, 'slug' => $job->artwork->slug]),
|
||||
] : null,
|
||||
'show_url' => route('admin.enhance.show', ['enhanceJob' => $job]),
|
||||
'download_url' => $job->outputUrl(),
|
||||
'retry_url' => route('admin.enhance.retry', ['enhanceJob' => $job]),
|
||||
'mark_failed_url' => route('admin.enhance.mark-failed', ['enhanceJob' => $job]),
|
||||
'delete_url' => route('admin.enhance.destroy', ['enhanceJob' => $job]),
|
||||
'can_retry' => $job->status === EnhanceJob::STATUS_FAILED,
|
||||
'can_mark_failed' => in_array($job->status, [EnhanceJob::STATUS_PENDING, EnhanceJob::STATUS_QUEUED, EnhanceJob::STATUS_PROCESSING], true),
|
||||
'detailed' => $detailed,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -132,6 +132,32 @@ class NewsController extends Controller
|
||||
] + $this->sidebarData());
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Type page — /news/type/{type}
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
public function type(Request $request, string $type): View
|
||||
{
|
||||
$typeLabels = \cPad\Plugins\News\Models\NewsArticle::TYPE_LABELS;
|
||||
|
||||
abort_unless(array_key_exists($type, $typeLabels), 404);
|
||||
|
||||
$label = $typeLabels[$type];
|
||||
$perPage = config('news.articles_per_page', 12);
|
||||
|
||||
$articles = NewsArticle::with('author', 'category')
|
||||
->published()
|
||||
->where('type', $type)
|
||||
->editorialOrder()
|
||||
->paginate($perPage);
|
||||
|
||||
return view('news.type', [
|
||||
'type' => $type,
|
||||
'typeLabel' => $label,
|
||||
'articles' => $articles,
|
||||
] + $this->sidebarData());
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Article page — /news/{slug}
|
||||
// -----------------------------------------------------------------------
|
||||
@@ -173,14 +199,21 @@ class NewsController extends Controller
|
||||
return;
|
||||
}
|
||||
|
||||
NewsView::create([
|
||||
'article_id' => $article->id,
|
||||
'user_id' => $userId,
|
||||
'ip' => $ip,
|
||||
'created_at' => now(),
|
||||
]);
|
||||
try {
|
||||
NewsView::create([
|
||||
'article_id' => $article->id,
|
||||
'user_id' => $userId,
|
||||
'ip' => $ip,
|
||||
'created_at' => now(),
|
||||
]);
|
||||
|
||||
$article->incrementViews();
|
||||
$article->incrementViews();
|
||||
} catch (\Illuminate\Database\QueryException $e) {
|
||||
// Unique constraint violation — duplicate view, skip silently.
|
||||
if (($e->errorInfo[1] ?? 0) !== 1062) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
if ($canReadSession) {
|
||||
$request->session()->put($session, true);
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\News;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use cPad\Plugins\News\Models\NewsArticle;
|
||||
|
||||
class NewsRssController extends Controller
|
||||
@@ -14,13 +15,17 @@ class NewsRssController extends Controller
|
||||
*/
|
||||
public function feed(): Response
|
||||
{
|
||||
$articles = NewsArticle::with('author', 'category')
|
||||
->published()
|
||||
->orderByDesc('published_at')
|
||||
->limit(config('news.rss_limit', 25))
|
||||
->get();
|
||||
$ttl = max(60, (int) config('news.rss_cache_ttl', 300));
|
||||
|
||||
$xml = $this->buildRss($articles);
|
||||
$xml = Cache::remember('news.rss.feed', $ttl, function (): string {
|
||||
$articles = NewsArticle::with('author', 'category')
|
||||
->published()
|
||||
->orderByDesc('published_at')
|
||||
->limit(config('news.rss_limit', 25))
|
||||
->get();
|
||||
|
||||
return $this->buildRss($articles);
|
||||
});
|
||||
|
||||
return response($xml, 200, [
|
||||
'Content-Type' => 'application/rss+xml; charset=UTF-8',
|
||||
|
||||
@@ -6,11 +6,13 @@ namespace App\Http\Controllers\Settings;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\AcademyContentMetricDaily;
|
||||
use App\Models\AcademyEvent;
|
||||
use App\Models\AcademySearchLog;
|
||||
use App\Services\Academy\AcademyAnalyticsContentResolver;
|
||||
use App\Services\Academy\AcademyContentIntelligenceService;
|
||||
use App\Services\Academy\AcademyPopularityService;
|
||||
use App\Support\AcademyAnalytics\AcademyAnalyticsContentType;
|
||||
use App\Support\AcademyAnalytics\AcademyAnalyticsEventType;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -29,6 +31,9 @@ final class AcademyAdminAnalyticsController extends Controller
|
||||
public function overview(Request $request): Response
|
||||
{
|
||||
[$from, $to, $range] = $this->resolveDateRange($request);
|
||||
$promptLibraryCurrent = $this->contentSummary(AcademyAnalyticsContentType::PROMPT_LIBRARY, $from, $to);
|
||||
[$previousFrom, $previousTo] = $this->previousRange($from, $to);
|
||||
$promptLibraryPrevious = $this->contentSummary(AcademyAnalyticsContentType::PROMPT_LIBRARY, $previousFrom, $previousTo);
|
||||
|
||||
$summary = $this->metricsQuery($from, $to)
|
||||
->selectRaw('sum(views) as views, sum(unique_visitors) as unique_visitors, sum(user_views) as user_views, sum(guest_views) as guest_views, sum(subscriber_views) as subscriber_views, sum(prompt_copies) as prompt_copies, sum(likes) as likes, sum(saves) as saves, sum(completions) as completions, sum(starts) as starts, sum(upgrade_clicks) as upgrade_clicks')
|
||||
@@ -50,6 +55,21 @@ final class AcademyAdminAnalyticsController extends Controller
|
||||
'courseStarts' => (int) ($summary?->starts ?? 0),
|
||||
'upgradeClicks' => (int) ($summary?->upgrade_clicks ?? 0),
|
||||
],
|
||||
'promptLibraryTrend' => [
|
||||
'current' => $promptLibraryCurrent,
|
||||
'previous' => $promptLibraryPrevious,
|
||||
'deltas' => [
|
||||
'views' => $this->percentDelta((int) $promptLibraryCurrent['views'], (int) $promptLibraryPrevious['views']),
|
||||
'uniqueVisitors' => $this->percentDelta((int) $promptLibraryCurrent['uniqueVisitors'], (int) $promptLibraryPrevious['uniqueVisitors']),
|
||||
'engagedViews' => $this->percentDelta((int) $promptLibraryCurrent['engagedViews'], (int) $promptLibraryPrevious['engagedViews']),
|
||||
'engagementRate' => $this->percentDelta((float) $promptLibraryCurrent['engagementRate'], (float) $promptLibraryPrevious['engagementRate']),
|
||||
],
|
||||
'range' => [
|
||||
'current' => ['from' => $from->toDateString(), 'to' => $to->toDateString()],
|
||||
'previous' => ['from' => $previousFrom->toDateString(), 'to' => $previousTo->toDateString()],
|
||||
],
|
||||
],
|
||||
'popularPromptPeriodUsage' => $this->popularPromptPeriodUsage($from, $to),
|
||||
'topContent' => $this->serializeContentRows($this->popularity->topContent($from, $to, 8)),
|
||||
'topWeek' => $this->serializeContentRows($this->popularity->topContent(now()->subDays(6)->startOfDay(), now()->endOfDay(), 8)),
|
||||
]);
|
||||
@@ -65,6 +85,11 @@ final class AcademyAdminAnalyticsController extends Controller
|
||||
return $this->renderContentPage($request, AcademyAnalyticsContentType::PROMPT, 'Prompt analytics', 'Copy-heavy prompt performance, save rates, and upgrade interest.');
|
||||
}
|
||||
|
||||
public function promptLibrary(Request $request): Response
|
||||
{
|
||||
return $this->renderContentPage($request, AcademyAnalyticsContentType::PROMPT_LIBRARY, 'Prompt library analytics', 'Discovery and engagement on the public /academy/prompts library page.');
|
||||
}
|
||||
|
||||
public function lessons(Request $request): Response
|
||||
{
|
||||
return $this->renderContentPage($request, AcademyAnalyticsContentType::LESSON, 'Lesson analytics', 'Lesson engagement, starts, completions, and drop-off signals.');
|
||||
@@ -333,9 +358,14 @@ final class AcademyAdminAnalyticsController extends Controller
|
||||
'access' => $access,
|
||||
'content_type' => $contentType,
|
||||
],
|
||||
'summary' => $contentType === AcademyAnalyticsContentType::PROMPT_LIBRARY
|
||||
? $this->contentSummary(AcademyAnalyticsContentType::PROMPT_LIBRARY, $from, $to)
|
||||
: null,
|
||||
'rows' => $serializedRows,
|
||||
'contentTypeOptions' => [
|
||||
['value' => '', 'label' => 'All content'],
|
||||
['value' => AcademyAnalyticsContentType::PROMPT_LIBRARY, 'label' => 'Prompt library'],
|
||||
['value' => AcademyAnalyticsContentType::PROMPT_PACK_LIBRARY, 'label' => 'Prompt pack library'],
|
||||
['value' => AcademyAnalyticsContentType::PROMPT, 'label' => 'Prompts'],
|
||||
['value' => AcademyAnalyticsContentType::LESSON, 'label' => 'Lessons'],
|
||||
['value' => AcademyAnalyticsContentType::COURSE, 'label' => 'Courses'],
|
||||
@@ -359,7 +389,134 @@ final class AcademyAdminAnalyticsController extends Controller
|
||||
private function metricsQuery(Carbon $from, Carbon $to)
|
||||
{
|
||||
return AcademyContentMetricDaily::query()
|
||||
->whereBetween('date', [$from->toDateString(), $to->toDateString()]);
|
||||
->whereBetween('date', [$from->copy()->startOfDay(), $to->copy()->endOfDay()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, int|float>
|
||||
*/
|
||||
private function contentSummary(string $contentType, Carbon $from, Carbon $to): array
|
||||
{
|
||||
$query = $this->metricsQuery($from, $to)
|
||||
->where('content_type', $contentType);
|
||||
|
||||
if (! AcademyAnalyticsContentType::requiresContentId($contentType)) {
|
||||
$query->whereNull('content_id');
|
||||
}
|
||||
|
||||
$summary = $query
|
||||
->selectRaw('sum(views) as views, sum(unique_visitors) as unique_visitors, sum(engaged_views) as engaged_views, sum(scroll_50) as scroll_50, sum(scroll_75) as scroll_75, sum(scroll_100) as scroll_100, avg(avg_engaged_seconds) as avg_engaged_seconds, sum(popularity_score) as popularity_score')
|
||||
->first();
|
||||
|
||||
$uniqueVisitors = max(0, (int) ($summary?->unique_visitors ?? 0));
|
||||
$engagedViews = max(0, (int) ($summary?->engaged_views ?? 0));
|
||||
$scroll100 = max(0, (int) ($summary?->scroll_100 ?? 0));
|
||||
|
||||
return [
|
||||
'views' => max(0, (int) ($summary?->views ?? 0)),
|
||||
'uniqueVisitors' => $uniqueVisitors,
|
||||
'engagedViews' => $engagedViews,
|
||||
'scroll50' => max(0, (int) ($summary?->scroll_50 ?? 0)),
|
||||
'scroll75' => max(0, (int) ($summary?->scroll_75 ?? 0)),
|
||||
'scroll100' => $scroll100,
|
||||
'avgEngagedSeconds' => round((float) ($summary?->avg_engaged_seconds ?? 0), 1),
|
||||
'popularityScore' => round((float) ($summary?->popularity_score ?? 0), 2),
|
||||
'engagementRate' => $uniqueVisitors > 0 ? round(($engagedViews / $uniqueVisitors) * 100, 1) : 0.0,
|
||||
'deepScrollRate' => $uniqueVisitors > 0 ? round(($scroll100 / $uniqueVisitors) * 100, 1) : 0.0,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{0: Carbon, 1: Carbon}
|
||||
*/
|
||||
private function previousRange(Carbon $from, Carbon $to): array
|
||||
{
|
||||
$days = $from->copy()->startOfDay()->diffInDays($to->copy()->startOfDay()) + 1;
|
||||
|
||||
return [
|
||||
$from->copy()->subDays($days)->startOfDay(),
|
||||
$from->copy()->subDay()->endOfDay(),
|
||||
];
|
||||
}
|
||||
|
||||
private function percentDelta(int|float $current, int|float $previous): ?float
|
||||
{
|
||||
if ((float) $previous === 0.0) {
|
||||
return (float) $current === 0.0 ? 0.0 : null;
|
||||
}
|
||||
|
||||
return round((((float) $current - (float) $previous) / (float) $previous) * 100, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{totalViews:int,totalVisitors:int,periods:list<array<string,int|float|string>>}
|
||||
*/
|
||||
private function popularPromptPeriodUsage(Carbon $from, Carbon $to): array
|
||||
{
|
||||
$events = AcademyEvent::query()
|
||||
->whereBetween('occurred_at', [$from, $to])
|
||||
->where('event_type', AcademyAnalyticsEventType::PAGE_VIEW)
|
||||
->where('content_type', AcademyAnalyticsContentType::PROMPT_POPULAR)
|
||||
->get(['visitor_id', 'metadata']);
|
||||
|
||||
$summary = [];
|
||||
$totalViews = 0;
|
||||
$visitorBuckets = [];
|
||||
|
||||
foreach ($events as $event) {
|
||||
$metadata = is_array($event->metadata) ? $event->metadata : [];
|
||||
$period = trim((string) ($metadata['period'] ?? ''));
|
||||
|
||||
if ($period === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$days = max(0, (int) ($metadata['period_days'] ?? 0));
|
||||
|
||||
if (! isset($summary[$period])) {
|
||||
$summary[$period] = [
|
||||
'period' => $period,
|
||||
'label' => sprintf('%s days', $days > 0 ? $days : (int) preg_replace('/\D+/', '', $period)),
|
||||
'views' => 0,
|
||||
'uniqueVisitors' => 0,
|
||||
'share' => 0.0,
|
||||
'days' => $days,
|
||||
];
|
||||
$visitorBuckets[$period] = [];
|
||||
}
|
||||
|
||||
$summary[$period]['views']++;
|
||||
$totalViews++;
|
||||
|
||||
$visitorId = trim((string) ($event->visitor_id ?? ''));
|
||||
if ($visitorId !== '') {
|
||||
$visitorBuckets[$period][$visitorId] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$totalVisitors = 0;
|
||||
|
||||
foreach ($summary as $period => &$row) {
|
||||
$uniqueVisitors = count($visitorBuckets[$period] ?? []);
|
||||
$row['uniqueVisitors'] = $uniqueVisitors;
|
||||
$row['share'] = $totalViews > 0 ? round((((int) $row['views']) / $totalViews) * 100, 1) : 0.0;
|
||||
$totalVisitors += $uniqueVisitors;
|
||||
}
|
||||
unset($row);
|
||||
|
||||
usort($summary, static function (array $left, array $right): int {
|
||||
if ((int) $right['views'] === (int) $left['views']) {
|
||||
return ((int) $left['days']) <=> ((int) $right['days']);
|
||||
}
|
||||
|
||||
return ((int) $right['views']) <=> ((int) $left['views']);
|
||||
});
|
||||
|
||||
return [
|
||||
'totalViews' => $totalViews,
|
||||
'totalVisitors' => $totalVisitors,
|
||||
'periods' => array_values($summary),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -440,6 +597,7 @@ final class AcademyAdminAnalyticsController extends Controller
|
||||
['label' => 'Overview', 'href' => route('admin.academy.analytics.overview')],
|
||||
['label' => 'Intelligence', 'href' => route('admin.academy.analytics.intelligence')],
|
||||
['label' => 'Content', 'href' => route('admin.academy.analytics.content')],
|
||||
['label' => 'Prompt Library', 'href' => route('admin.academy.analytics.prompt-library')],
|
||||
['label' => 'Prompts', 'href' => route('admin.academy.analytics.prompts')],
|
||||
['label' => 'Lessons', 'href' => route('admin.academy.analytics.lessons')],
|
||||
['label' => 'Courses', 'href' => route('admin.academy.analytics.courses')],
|
||||
|
||||
@@ -18,6 +18,7 @@ use App\Services\TagService;
|
||||
use App\Services\ArtworkVersioningService;
|
||||
use App\Services\Studio\StudioArtworkQueryService;
|
||||
use App\Services\Studio\StudioBulkActionService;
|
||||
use App\Support\ArtworkDescriptionContentValidator;
|
||||
use App\Services\Tags\TagDiscoveryService;
|
||||
use App\Services\Worlds\WorldSubmissionService;
|
||||
use Carbon\Carbon;
|
||||
@@ -164,6 +165,8 @@ final class StudioArtworksApiController extends Controller
|
||||
'evolution_note' => 'sometimes|nullable|string|max:1200',
|
||||
]);
|
||||
|
||||
$this->ensureValidArtworkDescription($validated);
|
||||
|
||||
$hasAttributionUpdates = array_key_exists('group', $validated)
|
||||
|| array_key_exists('primary_author_user_id', $validated)
|
||||
|| array_key_exists('contributor_user_ids', $validated)
|
||||
@@ -326,6 +329,15 @@ final class StudioArtworksApiController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
private function ensureValidArtworkDescription(array $validated): void
|
||||
{
|
||||
foreach (ArtworkDescriptionContentValidator::errors($validated['description'] ?? null) as $message) {
|
||||
throw ValidationException::withMessages([
|
||||
'description' => [$message],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function evolutionOptions(Request $request, int $id): JsonResponse
|
||||
{
|
||||
$artwork = $request->user()->artworks()->findOrFail($id);
|
||||
|
||||
@@ -95,7 +95,13 @@ final class StudioController extends Controller
|
||||
{
|
||||
$provider = $this->content->provider('artworks');
|
||||
$prefs = $this->preferences->forUser($request->user());
|
||||
$listing = $this->content->list($request->user(), $request->only(['q', 'sort', 'bucket', 'page', 'per_page', 'content_type', 'category', 'tag']), null, 'artworks');
|
||||
$filters = $request->only(['q', 'sort', 'bucket', 'page', 'per_page', 'content_type', 'category', 'tag']);
|
||||
|
||||
if (! $request->filled('sort')) {
|
||||
$filters['sort'] = 'published_desc';
|
||||
}
|
||||
|
||||
$listing = $this->content->list($request->user(), $filters, null, 'artworks');
|
||||
$listing['default_view'] = $prefs['default_content_view'];
|
||||
|
||||
return Inertia::render('Studio/StudioArtworks', [
|
||||
|
||||
@@ -377,10 +377,41 @@ final class StudioNewsController extends Controller
|
||||
'og_image' => ['nullable', 'string', 'max:2048'],
|
||||
'relations' => ['nullable', 'array', 'max:12'],
|
||||
'relations.*.entity_type' => ['required_with:relations', Rule::in(array_column($this->news->relationTypeOptions(), 'value'))],
|
||||
'relations.*.entity_id' => ['required_with:relations', 'integer', 'min:1'],
|
||||
'relations.*.entity_id' => ['nullable', 'integer', 'min:1'],
|
||||
'relations.*.external_url' => ['nullable', 'string', 'max:2048'],
|
||||
'relations.*.context_label' => ['nullable', 'string', 'max:120'],
|
||||
]);
|
||||
|
||||
$relationErrors = [];
|
||||
|
||||
foreach ((array) ($validated['relations'] ?? []) as $index => $relation) {
|
||||
$entityType = trim(Str::lower((string) ($relation['entity_type'] ?? '')));
|
||||
|
||||
if ($entityType === NewsService::RELATION_SOURCE) {
|
||||
$externalUrl = $this->normalizeExternalRelationUrl($relation['external_url'] ?? null);
|
||||
|
||||
if ($externalUrl === null) {
|
||||
$relationErrors["relations.{$index}.external_url"] = 'Source relations need a valid URL.';
|
||||
continue;
|
||||
}
|
||||
|
||||
$validated['relations'][$index]['entity_id'] = null;
|
||||
$validated['relations'][$index]['external_url'] = $externalUrl;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((int) ($relation['entity_id'] ?? 0) < 1) {
|
||||
$relationErrors["relations.{$index}.entity_id"] = 'Select a related entity.';
|
||||
}
|
||||
|
||||
$validated['relations'][$index]['external_url'] = null;
|
||||
}
|
||||
|
||||
if ($relationErrors !== []) {
|
||||
throw ValidationException::withMessages($relationErrors);
|
||||
}
|
||||
|
||||
if (($validated['editorial_status'] ?? null) === NewsArticle::EDITORIAL_STATUS_SCHEDULED && empty($validated['published_at'])) {
|
||||
throw ValidationException::withMessages([
|
||||
'published_at' => 'Scheduled articles need a publish date and time.',
|
||||
@@ -390,6 +421,25 @@ final class StudioNewsController extends Controller
|
||||
return $validated;
|
||||
}
|
||||
|
||||
private function normalizeExternalRelationUrl(mixed $value): ?string
|
||||
{
|
||||
$url = trim((string) ($value ?? ''));
|
||||
|
||||
if ($url === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (preg_match('/^\[[^\]]+\]\((https?:\/\/[^)]+)\)$/i', $url, $matches) === 1) {
|
||||
$url = trim((string) ($matches[1] ?? ''));
|
||||
}
|
||||
|
||||
if ($url === '' || filter_var($url, FILTER_VALIDATE_URL) === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Str::limit($url, 2048, '');
|
||||
}
|
||||
|
||||
private function tagPayload(): array
|
||||
{
|
||||
return NewsTag::query()
|
||||
|
||||
@@ -46,6 +46,7 @@ final class StudioNewsMediaApiController extends Controller
|
||||
'size_bytes' => $stored['size_bytes'],
|
||||
'mobile_url' => $stored['mobile_url'],
|
||||
'desktop_url' => $stored['desktop_url'],
|
||||
'large_url' => $stored['large_url'],
|
||||
'srcset' => $stored['srcset'],
|
||||
]);
|
||||
} catch (RuntimeException $e) {
|
||||
|
||||
@@ -855,25 +855,33 @@ class ProfileController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$allowedImageMimes = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'];
|
||||
|
||||
if ($request->hasFile('emoticon')) {
|
||||
$file = $request->file('emoticon');
|
||||
$fname = $file->getClientOriginalName();
|
||||
$path = \Illuminate\Support\Facades\Storage::disk('public')->putFileAs('user-emoticons/'.$user->id, $file, $fname);
|
||||
try {
|
||||
\Illuminate\Support\Facades\DB::table('users')->where('id', $user->id)->update(['eicon' => $fname]);
|
||||
} catch (\Exception $e) {}
|
||||
if (in_array($file->getMimeType(), $allowedImageMimes, true)) {
|
||||
$ext = $file->guessExtension() ?: 'jpg';
|
||||
$fname = $user->id . '_emoticon_' . time() . '.' . $ext;
|
||||
\Illuminate\Support\Facades\Storage::disk('public')->putFileAs('user-emoticons/'.$user->id, $file, $fname);
|
||||
try {
|
||||
\Illuminate\Support\Facades\DB::table('users')->where('id', $user->id)->update(['eicon' => $fname]);
|
||||
} catch (\Exception $e) {}
|
||||
}
|
||||
}
|
||||
|
||||
if ($request->hasFile('photo')) {
|
||||
$file = $request->file('photo');
|
||||
$fname = $file->getClientOriginalName();
|
||||
$path = \Illuminate\Support\Facades\Storage::disk('public')->putFileAs('user-picture/'.$user->id, $file, $fname);
|
||||
if (\Illuminate\Support\Facades\Schema::hasTable('user_profiles')) {
|
||||
$profileUpdates['cover_image'] = $fname;
|
||||
} else {
|
||||
try {
|
||||
\Illuminate\Support\Facades\DB::table('users')->where('id', $user->id)->update(['picture' => $fname]);
|
||||
} catch (\Exception $e) {}
|
||||
if (in_array($file->getMimeType(), $allowedImageMimes, true)) {
|
||||
$ext = $file->guessExtension() ?: 'jpg';
|
||||
$fname = $user->id . '_photo_' . time() . '.' . $ext;
|
||||
\Illuminate\Support\Facades\Storage::disk('public')->putFileAs('user-picture/'.$user->id, $file, $fname);
|
||||
if (\Illuminate\Support\Facades\Schema::hasTable('user_profiles')) {
|
||||
$profileUpdates['cover_image'] = $fname;
|
||||
} else {
|
||||
try {
|
||||
\Illuminate\Support\Facades\DB::table('users')->where('id', $user->id)->update(['picture' => $fname]);
|
||||
} catch (\Exception $e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
22
app/Http/Middleware/SecurityHeaders.php
Normal file
22
app/Http/Middleware/SecurityHeaders.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class SecurityHeaders
|
||||
{
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
$response = $next($request);
|
||||
|
||||
$response->headers->set('X-Frame-Options', 'SAMEORIGIN');
|
||||
$response->headers->set('X-Content-Type-Options', 'nosniff');
|
||||
$response->headers->set('Referrer-Policy', 'strict-origin-when-cross-origin');
|
||||
$response->headers->set('Permissions-Policy', 'camera=(), microphone=(), geolocation=()');
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@@ -111,7 +111,7 @@ class UpsertAcademyLessonRequest extends FormRequest
|
||||
'cover_image' => ['nullable', 'string', 'max:2048'],
|
||||
'article_cover_image' => ['nullable', 'string', 'max:2048'],
|
||||
'tags' => ['nullable', 'array'],
|
||||
'tags.*' => ['string', 'max:100'],
|
||||
'tags.*' => ['string', 'max:200'],
|
||||
'video_url' => ['nullable', 'string', 'max:2048'],
|
||||
'reading_minutes' => ['required', 'integer', 'min:1', 'max:999'],
|
||||
'featured' => ['required', 'boolean'],
|
||||
|
||||
@@ -4,7 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\Artworks;
|
||||
|
||||
use App\Support\ArtworkDescriptionContentValidator;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Validator;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
final class ArtworkCreateRequest extends FormRequest
|
||||
@@ -32,6 +34,15 @@ final class ArtworkCreateRequest extends FormRequest
|
||||
];
|
||||
}
|
||||
|
||||
public function withValidator(Validator $validator): void
|
||||
{
|
||||
$validator->after(function (Validator $validator): void {
|
||||
foreach (ArtworkDescriptionContentValidator::errors($this->input('description')) as $message) {
|
||||
$validator->errors()->add('description', $message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private function denyAsNotFound(): void
|
||||
{
|
||||
throw new NotFoundHttpException();
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
namespace App\Http\Requests\Dashboard;
|
||||
|
||||
use App\Models\Artwork;
|
||||
use App\Support\ArtworkDescriptionContentValidator;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Validator;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class UpdateArtworkRequest extends FormRequest
|
||||
@@ -45,6 +47,15 @@ class UpdateArtworkRequest extends FormRequest
|
||||
];
|
||||
}
|
||||
|
||||
public function withValidator(Validator $validator): void
|
||||
{
|
||||
$validator->after(function (Validator $validator): void {
|
||||
foreach (ArtworkDescriptionContentValidator::errors($this->input('description')) as $message) {
|
||||
$validator->errors()->add('description', $message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function artwork(): Artwork
|
||||
{
|
||||
if (! $this->artwork) {
|
||||
|
||||
@@ -4,8 +4,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\Manage;
|
||||
|
||||
use App\Support\ArtworkDescriptionContentValidator;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Validation\Validator;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
final class ManageArtworkUpdateRequest extends FormRequest
|
||||
@@ -48,6 +50,15 @@ final class ManageArtworkUpdateRequest extends FormRequest
|
||||
];
|
||||
}
|
||||
|
||||
public function withValidator(Validator $validator): void
|
||||
{
|
||||
$validator->after(function (Validator $validator): void {
|
||||
foreach (ArtworkDescriptionContentValidator::errors($this->input('description')) as $message) {
|
||||
$validator->errors()->add('description', $message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function artwork(): object
|
||||
{
|
||||
if (! $this->artwork) {
|
||||
|
||||
@@ -4,8 +4,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\Studio;
|
||||
|
||||
use App\Support\ArtworkDescriptionContentValidator;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
final class ApplyArtworkAiAssistRequest extends FormRequest
|
||||
{
|
||||
@@ -31,4 +33,13 @@ final class ApplyArtworkAiAssistRequest extends FormRequest
|
||||
'similar_actions.*.state' => ['required_with:similar_actions', Rule::in(['ignored', 'reviewed'])],
|
||||
];
|
||||
}
|
||||
|
||||
public function withValidator(Validator $validator): void
|
||||
{
|
||||
$validator->after(function (Validator $validator): void {
|
||||
foreach (ArtworkDescriptionContentValidator::errors($this->input('description')) as $message) {
|
||||
$validator->errors()->add('description', $message);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user