Skip to content

Commit

Permalink
FeedGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
kawax committed Nov 22, 2024
1 parent e8f96b9 commit d276157
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 15 deletions.
5 changes: 4 additions & 1 deletion config/bluesky.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@
'prefix' => env('BLUESKY_OAUTH_PREFIX', '/bluesky/oauth/'),
],

// Feed Generator
/**
* Feed Generator.
* Optional, as if not set, `did:web:example.com` will be used from the current URL.
*/
'generator' => [
// did:web:example.com
'service' => env('BLUESKY_GENERATOR_SERVICE'),
Expand Down
9 changes: 6 additions & 3 deletions src/FeedGenerator/FeedGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Revolution\Bluesky\FeedGenerator;

use Illuminate\Http\Request;
use Revolution\Bluesky\Support\DID;

final class FeedGenerator
{
Expand Down Expand Up @@ -43,15 +44,17 @@ public static function getFeedSkeleton(string $name, ?int $limit, ?string $curso
return call_user_func(self::$algos[$name], $limit, $cursor, $request);
}

public static function describeFeedGenerator(?string $publisher, ?string $service): array
public static function describeFeedGenerator(): array
{
$pub = config('bluesky.generator.publisher') ?? DID::web();

$feeds = collect(self::$algos)
->keys()
->map(fn ($algo) => 'at://'.$publisher.'/app.bsky.feed.generator/'.$algo)
->map(fn ($algo) => 'at://'.$pub.'/app.bsky.feed.generator/'.$algo)
->toArray();

return [
'did' => $service,
'did' => config('bluesky.generator.service') ?? DID::web(),
'feeds' => $feeds,
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
use Illuminate\Http\Request;
use Revolution\Bluesky\FeedGenerator\FeedGenerator;

class DescribeController
class DescribeFeedController
{
public function __invoke(Request $request): array
{
return FeedGenerator::describeFeedGenerator(
publisher: config('bluesky.generator.publisher'),
service: config('bluesky.generator.service'),
);
return FeedGenerator::describeFeedGenerator();
}
}
6 changes: 3 additions & 3 deletions src/FeedGenerator/Http/WellKnownDidController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

namespace Revolution\Bluesky\FeedGenerator\Http;

use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Revolution\Bluesky\Support\DID;

class WellKnownDidController
{
public function __invoke(Request $request): array
public function __invoke(): array
{
return [
'@context' => ['https://www.w3.org/ns/did/v1'],
'id' => config('bluesky.generator.service') ?? 'did:web:'.Str::of(url('/'))->rtrim('/')->chopStart(['http://', 'https://'])->toString(),
'id' => config('bluesky.generator.service') ?? DID::web(),
'service' => [
[
'id' => '#bsky_fg',
Expand Down
4 changes: 2 additions & 2 deletions src/Providers/BlueskyServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Revolution\Bluesky\Console\NewPrivateKeyCommand;
use Revolution\Bluesky\Contracts\Factory;
use Revolution\Bluesky\Contracts\XrpcClient;
use Revolution\Bluesky\FeedGenerator\Http\DescribeController;
use Revolution\Bluesky\FeedGenerator\Http\DescribeFeedController;
use Revolution\Bluesky\FeedGenerator\Http\FeedSkeletonController;
use Revolution\Bluesky\FeedGenerator\Http\WellKnownDidController;
use Revolution\Bluesky\Socalite\BlueskyProvider;
Expand Down Expand Up @@ -101,7 +101,7 @@ protected function generator(): void
->group(function () {
Route::get(Feed::getFeedSkeleton, FeedSkeletonController::class)
->name('bluesky.feed.skeleton');
Route::get(Feed::describeFeedGenerator, DescribeController::class)
Route::get(Feed::describeFeedGenerator, DescribeFeedController::class)
->name('bluesky.feed.describe');
});

Expand Down
9 changes: 8 additions & 1 deletion tests/Feature/FeedGenerator/FeedGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ public function test_feed_describe(): void
$response = $this->get(route('bluesky.feed.describe'));

$response->assertSuccessful();
$response->assertJson(['did' => null, 'feeds' => ['at:///app.bsky.feed.generator/test']]);
$response->assertJson(['did' => 'did:web:localhost', 'feeds' => ['at://did:web:localhost/app.bsky.feed.generator/test']]);
}

public function test_feed_did(): void
{
$response = $this->get('.well-known/did.json');

$response->assertSuccessful();
}
}
8 changes: 8 additions & 0 deletions tests/Feature/Support/SupportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Support\Facades\Http;
use Revolution\Bluesky\Facades\Bluesky;
use Revolution\Bluesky\Support\AtUri;
use Revolution\Bluesky\Support\DID;
use Revolution\Bluesky\Support\DidDocument;
use Tests\TestCase;

Expand Down Expand Up @@ -89,4 +90,11 @@ public function test_at_uri()
$this->assertSame('app.bsky.feed.post', $at->collection());
$this->assertSame('abcde', $at->rkey());
}

public function test_did_web()
{
$web = DID::web();

$this->assertSame('did:web:localhost', $web);
}
}

0 comments on commit d276157

Please sign in to comment.