Add some routing, start working on actually searching webmentions

This commit is contained in:
Lewis Dale committed 2023-03-09 21:50:59 +00:00
1 parent 15d03799bf
commit 45024faa5f
13 files changed
+308 -12

No files matched your search

+25 -5
View File
@@ -2,7 +2,11 @@
namespace Lewisdale\Webmentions;
use Lewisdale\Webmentions\Exceptions\InvalidTargetException;
use Lewisdale\Webmentions\Exceptions\InvalidUrlException;
use Lewisdale\Webmentions\Gateways\WebmentionGatewayInterface;
use Lewisdale\Webmentions\Models\Webmention;
use Symfony\Component\HttpClient\HttpClient;
class Endpoint {
private readonly WebmentionGatewayInterface $gateway;
@@ -16,19 +20,35 @@ class Endpoint {
// Validate that both source and target are actual domains
if (!$this->validateUrl($source) || !$this->validateUrl($target))
{
return;
throw new InvalidUrlException();
}
// Validate that the webmention target is a domain I care about
if (!str_contains($target, "https://lewisdale.dev")) {
// Should throw a Bad Request error
return;
throw new InvalidTargetException();
}
// Parse content from the source
$client = HttpClient::create();
$response = $client->request('GET', $source);
// Store the webmention
if ($response->getStatusCode() === 200)
{
$content = $this->parseContent($response->getContent());
$author = $this->parseAuthor($response->getContent());
// Send the appropriate response
$webmention = new Webmention(null, $target, $source, $content, $author);
$this->gateway->save($webmention);
}
}
private function parseContent(string $content) : ?string
{
return null;
}
private function parseAuthor(string $author) : ?string
{
return null;
}
}