Aggregate ladl.link slugs from all platform apps in the link list.
Deploy Ladill Link / deploy (push) Successful in 29s
Deploy Ladill Link / deploy (push) Successful in 29s
Sync QR and storefront short codes from sibling apps via a platform catalog API so My Links shows every ladl.link URL in one place. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Link;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
/**
|
||||
* Fetches ladl.link slugs created in other Ladill apps from the platform catalog API.
|
||||
*/
|
||||
class PlatformLinkCatalogClient
|
||||
{
|
||||
private function base(): string
|
||||
{
|
||||
$platform = rtrim((string) config('app.platform_url', 'https://ladill.com'), '/');
|
||||
|
||||
return $platform.'/api/link-catalog';
|
||||
}
|
||||
|
||||
private function token(): string
|
||||
{
|
||||
return (string) (config('billing.api_key') ?? '');
|
||||
}
|
||||
|
||||
/** @return list<array<string, mixed>> */
|
||||
public function linksForUser(string $publicId): array
|
||||
{
|
||||
if ($this->token() === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
try {
|
||||
$response = Http::withToken($this->token())
|
||||
->acceptJson()
|
||||
->timeout(12)
|
||||
->get($this->base().'/links', ['user' => $publicId]);
|
||||
|
||||
if (! $response->successful()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return array_values(array_filter(
|
||||
(array) ($response->json('links') ?? []),
|
||||
fn ($row) => is_array($row) && filled($row['slug'] ?? null),
|
||||
));
|
||||
} catch (\Throwable) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user