lthn.io/app/Mod/Names/Controllers/OgImageController.php
Claude 8f9c1f282e
feat: email notifications on claim approval + OG images for names
ClaimApproved mailable sent when admin approves a claim — dark
themed HTML email with name, next steps, and CTA links. Wrapped
in try/catch so email failure doesn't block approval.

Dynamic SVG OpenGraph images at /names/{name}/og.svg — shows name,
type badge (Registered/Reserved/Gateway/Available), and branding.
og:image meta tag added to name detail pages via @push('head').

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 12:20:43 +01:00

64 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
namespace Mod\Names\Controllers;
use Illuminate\Routing\Controller;
use Mod\Chain\Services\DaemonRpc;
/**
* Dynamic OpenGraph image for .lthn names.
*
* GET /names/{name}/og.svg
*
* Returns an SVG that social platforms can render as preview image.
*/
class OgImageController extends Controller
{
public function __invoke(string $name, DaemonRpc $rpc): \Illuminate\Http\Response
{
$alias = $rpc->getAliasByName(strtolower(trim($name)));
$type = 'Available';
$typeColour = '#34d399';
if ($alias) {
$comment = $alias['comment'] ?? '';
if (str_contains($comment, 'type=reserved')) {
$type = 'Reserved';
$typeColour = '#fbbf24';
} elseif (str_contains($comment, 'type=gateway')) {
$type = 'Gateway';
$typeColour = '#34d399';
} else {
$type = 'Registered';
$typeColour = '#818cf8';
}
}
$escapedName = htmlspecialchars($name, ENT_XML1);
$svg = <<<SVG
<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="630" viewBox="0 0 1200 630">
<rect width="1200" height="630" fill="#0a0e17"/>
<rect x="0" y="0" width="1200" height="4" fill="{$typeColour}"/>
<text x="80" y="200" font-family="Inter, -apple-system, sans-serif" font-size="72" font-weight="700" fill="#e5e7eb">
<tspan fill="#818cf8">{$escapedName}</tspan><tspan fill="#6b7280">.lthn</tspan>
</text>
<rect x="80" y="240" width="120" height="36" rx="18" fill="{$typeColour}" opacity="0.15"/>
<text x="140" y="265" font-family="Inter, sans-serif" font-size="16" font-weight="600" fill="{$typeColour}" text-anchor="middle">{$type}</text>
<text x="80" y="340" font-family="Inter, sans-serif" font-size="24" fill="#6b7280">Blockchain domain name on the Lethean network</text>
<text x="80" y="540" font-family="Inter, sans-serif" font-size="20" fill="#374151">lthn.io</text>
<text x="1120" y="540" font-family="Inter, sans-serif" font-size="18" fill="#374151" text-anchor="end">Lethean CIC</text>
</svg>
SVG;
return response($svg, 200)->header('Content-Type', 'image/svg+xml')
->header('Cache-Control', 'public, max-age=3600');
}
}