feat(cms): sync site assets, revalidate webhook, and document download naming
This commit is contained in:
48
app/Services/SiteRevalidationService.php
Normal file
48
app/Services/SiteRevalidationService.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class SiteRevalidationService
|
||||
{
|
||||
/**
|
||||
* Revalidate article cache on the Next.js frontend.
|
||||
*/
|
||||
public static function revalidateArticle(?string $slug = null): void
|
||||
{
|
||||
static::revalidate('article', $slug);
|
||||
}
|
||||
|
||||
/**
|
||||
* Revalidate page cache on the Next.js frontend.
|
||||
*/
|
||||
public static function revalidatePage(?string $slug = null): void
|
||||
{
|
||||
static::revalidate('page', $slug);
|
||||
}
|
||||
|
||||
private static function revalidate(string $type, ?string $slug = null): void
|
||||
{
|
||||
$url = config('services.nextjs.revalidate_url');
|
||||
$token = config('services.nextjs.revalidate_token');
|
||||
|
||||
if (! $url || ! $token) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$payload = ['type' => $type];
|
||||
if ($slug) {
|
||||
$payload['slug'] = $slug;
|
||||
}
|
||||
|
||||
Http::timeout(5)
|
||||
->withHeaders(['x-revalidate-token' => $token])
|
||||
->post($url, $payload);
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning("Site revalidation failed for {$type}/{$slug}: {$e->getMessage()}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user