Bluesky does not hydrate link cards server-side, so build the app.bsky.embed.external embed at publish time: detect the first URL, scrape its OpenGraph metadata, and re-upload the og:image as the card thumb. Works for web, API and MCP. Adds a posts/link-preview endpoint so the editor renders the card live. The thumb download is SSRF-guarded and does not follow redirects.
25 lines
641 B
PHP
25 lines
641 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\App;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\App\Post\LinkPreviewRequest;
|
|
use App\Services\Social\LinkCard\LinkCardFetcher;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Response;
|
|
|
|
class LinkPreviewController extends Controller
|
|
{
|
|
public function __invoke(LinkPreviewRequest $request, LinkCardFetcher $fetcher): JsonResponse|Response
|
|
{
|
|
$card = $fetcher->fetch($request->validated('url'));
|
|
|
|
if ($card === null) {
|
|
return response()->noContent();
|
|
}
|
|
|
|
return response()->json($card->toArray());
|
|
}
|
|
}
|