ActivityPubResolverはNoteだけ処理するように
This commit is contained in:
parent
3420e053fc
commit
67ae0e159f
@ -37,6 +37,10 @@ class ActivityPubResolver implements Resolver, Parser
|
|||||||
$activityOrObject = json_decode($json, true);
|
$activityOrObject = json_decode($json, true);
|
||||||
$object = $activityOrObject['object'] ?? $activityOrObject;
|
$object = $activityOrObject['object'] ?? $activityOrObject;
|
||||||
|
|
||||||
|
if ($object['type'] !== 'Note') {
|
||||||
|
throw new UnsupportedContentException('Unsupported object type: ' . $object['type']);
|
||||||
|
}
|
||||||
|
|
||||||
$metadata = new Metadata();
|
$metadata = new Metadata();
|
||||||
|
|
||||||
$metadata->title = isset($object['attributedTo']) ? $this->getTitleFromActor($object['attributedTo']) : '';
|
$metadata->title = isset($object['attributedTo']) ? $this->getTitleFromActor($object['attributedTo']) : '';
|
||||||
|
@ -48,16 +48,19 @@ class MetadataResolver implements Resolver
|
|||||||
{
|
{
|
||||||
foreach ($this->rules as $pattern => $class) {
|
foreach ($this->rules as $pattern => $class) {
|
||||||
if (preg_match($pattern, $url) === 1) {
|
if (preg_match($pattern, $url) === 1) {
|
||||||
/** @var Resolver $resolver */
|
try {
|
||||||
$resolver = app($class);
|
/** @var Resolver $resolver */
|
||||||
|
$resolver = app($class);
|
||||||
|
|
||||||
return $resolver->resolve($url);
|
return $resolver->resolve($url);
|
||||||
|
} catch (UnsupportedContentException $e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->resolveWithAcceptHeader($url);
|
try {
|
||||||
if ($result !== null) {
|
return $this->resolveWithAcceptHeader($url);
|
||||||
return $result;
|
} catch (UnsupportedContentException $e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($this->defaultResolver)) {
|
if (isset($this->defaultResolver)) {
|
||||||
@ -70,7 +73,7 @@ class MetadataResolver implements Resolver
|
|||||||
throw new \UnexpectedValueException('URL not matched.');
|
throw new \UnexpectedValueException('URL not matched.');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function resolveWithAcceptHeader(string $url): ?Metadata
|
public function resolveWithAcceptHeader(string $url): Metadata
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// Rails等はAcceptに */* が入っていると、ブラウザの適当なAcceptヘッダだと判断して全部無視してしまう。
|
// Rails等はAcceptに */* が入っていると、ブラウザの適当なAcceptヘッダだと判断して全部無視してしまう。
|
||||||
@ -115,6 +118,6 @@ class MetadataResolver implements Resolver
|
|||||||
// 5xx は変なAcceptが原因かもしれない(?)ので無視してフォールバック
|
// 5xx は変なAcceptが原因かもしれない(?)ので無視してフォールバック
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
throw new UnsupportedContentException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
app/MetadataResolver/UnsupportedContentException.php
Normal file
12
app/MetadataResolver/UnsupportedContentException.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\MetadataResolver;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* このResolverやParserが対応していないサイトであったことを表わします。
|
||||||
|
*/
|
||||||
|
class UnsupportedContentException extends Exception
|
||||||
|
{
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user