39 lines
1.2 KiB
PHP
39 lines
1.2 KiB
PHP
<?php
|
|
/**
|
|
* admin/api/profile.php — Single-profile lookup from the profiles cache.
|
|
* Returns cached kind-0 metadata for a given pubkey.
|
|
*
|
|
* Usage: profile.php?pubkey=<64-char-hex>
|
|
* Returns: { "pubkey": "...", "name": "...", "display_name": "...",
|
|
* "best_name": "...", "picture": "...", "nip05": "...",
|
|
* "about": "...", "website": "...", "lud16": "..." }
|
|
* or { "error": "not found" } with HTTP 404 if no profile is cached.
|
|
*/
|
|
require_once __DIR__ . '/../lib/helpers.php';
|
|
|
|
$pubkey = trim($_GET['pubkey'] ?? '');
|
|
if (!preg_match('/^[0-9a-fA-F]{64}$/', $pubkey)) {
|
|
http_response_code(400);
|
|
json_response(['error' => 'Invalid pubkey']);
|
|
}
|
|
|
|
$pdo = db();
|
|
try {
|
|
$stmt = $pdo->prepare(
|
|
"SELECT pubkey, name, display_name, about, picture, banner,
|
|
nip05, website, lud16, lud06
|
|
FROM profiles WHERE pubkey = ?"
|
|
);
|
|
$stmt->execute([$pubkey]);
|
|
$row = $stmt->fetch();
|
|
if (!$row) {
|
|
http_response_code(404);
|
|
json_response(['error' => 'not found']);
|
|
}
|
|
$row['best_name'] = profile_display_name($row);
|
|
json_response($row);
|
|
} catch (PDOException $e) {
|
|
http_response_code(500);
|
|
json_response(['error' => 'Database error']);
|
|
}
|