25 - Fix code style issues across codebase with Pint
This commit is contained in:
parent
0b2fc5004b
commit
56db303b15
50 changed files with 125 additions and 134 deletions
|
|
@ -15,7 +15,7 @@ public function execute(string $name, string $provider, int $languageId, ?string
|
||||||
|
|
||||||
$url = config("feed.providers.{$provider}.languages.{$langCode}.url");
|
$url = config("feed.providers.{$provider}.languages.{$langCode}.url");
|
||||||
|
|
||||||
if (!$url) {
|
if (! $url) {
|
||||||
throw new InvalidArgumentException("Invalid provider and language combination: {$provider}/{$langCode}");
|
throw new InvalidArgumentException("Invalid provider and language combination: {$provider}/{$langCode}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ public function __construct(
|
||||||
*/
|
*/
|
||||||
public function execute(string $instanceDomain, string $username, string $password, string $platform = 'lemmy'): PlatformAccount
|
public function execute(string $instanceDomain, string $username, string $password, string $platform = 'lemmy'): PlatformAccount
|
||||||
{
|
{
|
||||||
$fullInstanceUrl = 'https://' . $instanceDomain;
|
$fullInstanceUrl = 'https://'.$instanceDomain;
|
||||||
|
|
||||||
// Authenticate first — if this fails, no records are created
|
// Authenticate first — if this fails, no records are created
|
||||||
$authResponse = $this->lemmyAuthService->authenticate($fullInstanceUrl, $username, $password);
|
$authResponse = $this->lemmyAuthService->authenticate($fullInstanceUrl, $username, $password);
|
||||||
|
|
|
||||||
|
|
@ -15,13 +15,13 @@ class FetchNewArticlesCommand extends Command
|
||||||
|
|
||||||
public function handle(): int
|
public function handle(): int
|
||||||
{
|
{
|
||||||
if (!Setting::isArticleProcessingEnabled()) {
|
if (! Setting::isArticleProcessingEnabled()) {
|
||||||
$this->info('Article processing is disabled. Article discovery skipped.');
|
$this->info('Article processing is disabled. Article discovery skipped.');
|
||||||
|
|
||||||
return self::SUCCESS;
|
return self::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Feed::where('is_active', true)->exists()) {
|
if (! Feed::where('is_active', true)->exists()) {
|
||||||
$this->info('No active feeds found. Article discovery skipped.');
|
$this->info('No active feeds found. Article discovery skipped.');
|
||||||
|
|
||||||
return self::SUCCESS;
|
return self::SUCCESS;
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ public function canParse(string $url): bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract article data from HTML
|
* Extract article data from HTML
|
||||||
|
*
|
||||||
* @return array<string, mixed>
|
* @return array<string, mixed>
|
||||||
*/
|
*/
|
||||||
public function extractData(string $html): array;
|
public function extractData(string $html): array;
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ public function canParse(string $url): bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract article URLs from homepage HTML
|
* Extract article URLs from homepage HTML
|
||||||
|
*
|
||||||
* @return array<int, string>
|
* @return array<int, string>
|
||||||
*/
|
*/
|
||||||
public function extractArticleUrls(string $html): array;
|
public function extractArticleUrls(string $html): array;
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,5 @@ class ExceptionLogged
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public Log $log
|
public Log $log
|
||||||
) {
|
) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,5 @@ public function __construct(
|
||||||
public string $message,
|
public string $message,
|
||||||
/** @var array<string, mixed> */
|
/** @var array<string, mixed> */
|
||||||
public array $context = []
|
public array $context = []
|
||||||
) {
|
) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,5 @@ class NewArticleFetched
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||||
|
|
||||||
public function __construct(public Article $article)
|
public function __construct(public Article $article) {}
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,4 @@
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
class ChannelException extends Exception
|
class ChannelException extends Exception {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ class PublishException extends Exception
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly Article $article,
|
private readonly Article $article,
|
||||||
private readonly PlatformEnum|null $platform,
|
private readonly ?PlatformEnum $platform,
|
||||||
?Throwable $previous = null
|
?Throwable $previous = null
|
||||||
) {
|
) {
|
||||||
$message = "Failed to publish article #$article->id";
|
$message = "Failed to publish article #$article->id";
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,4 @@
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
class RoutingException extends Exception
|
class RoutingException extends Exception {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,12 @@
|
||||||
namespace App\Http\Controllers\Api\V1;
|
namespace App\Http\Controllers\Api\V1;
|
||||||
|
|
||||||
use App\Http\Resources\ArticleResource;
|
use App\Http\Resources\ArticleResource;
|
||||||
|
use App\Jobs\ArticleDiscoveryJob;
|
||||||
use App\Models\Article;
|
use App\Models\Article;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use App\Jobs\ArticleDiscoveryJob;
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Artisan;
|
|
||||||
|
|
||||||
class ArticlesController extends BaseController
|
class ArticlesController extends BaseController
|
||||||
{
|
{
|
||||||
|
|
@ -54,7 +53,7 @@ public function approve(Article $article): JsonResponse
|
||||||
'Article approved and queued for publishing.'
|
'Article approved and queued for publishing.'
|
||||||
);
|
);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $this->sendError('Failed to approve article: ' . $e->getMessage(), [], 500);
|
return $this->sendError('Failed to approve article: '.$e->getMessage(), [], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -71,7 +70,7 @@ public function reject(Article $article): JsonResponse
|
||||||
'Article rejected.'
|
'Article rejected.'
|
||||||
);
|
);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $this->sendError('Failed to reject article: ' . $e->getMessage(), [], 500);
|
return $this->sendError('Failed to reject article: '.$e->getMessage(), [], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,7 +87,7 @@ public function refresh(): JsonResponse
|
||||||
'Article refresh started. New articles will appear shortly.'
|
'Article refresh started. New articles will appear shortly.'
|
||||||
);
|
);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $this->sendError('Failed to start article refresh: ' . $e->getMessage(), [], 500);
|
return $this->sendError('Failed to start article refresh: '.$e->getMessage(), [], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
|
|
@ -24,7 +23,7 @@ public function login(Request $request): JsonResponse
|
||||||
|
|
||||||
$user = User::where('email', $request->email)->first();
|
$user = User::where('email', $request->email)->first();
|
||||||
|
|
||||||
if (!$user || !Hash::check($request->password, $user->password)) {
|
if (! $user || ! Hash::check($request->password, $user->password)) {
|
||||||
return $this->sendError('Invalid credentials', [], 401);
|
return $this->sendError('Invalid credentials', [], 401);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,7 +41,7 @@ public function login(Request $request): JsonResponse
|
||||||
} catch (ValidationException $e) {
|
} catch (ValidationException $e) {
|
||||||
return $this->sendValidationError($e->errors());
|
return $this->sendValidationError($e->errors());
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return $this->sendError('Login failed: ' . $e->getMessage(), [], 500);
|
return $this->sendError('Login failed: '.$e->getMessage(), [], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -78,7 +77,7 @@ public function register(Request $request): JsonResponse
|
||||||
} catch (ValidationException $e) {
|
} catch (ValidationException $e) {
|
||||||
return $this->sendValidationError($e->errors());
|
return $this->sendValidationError($e->errors());
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return $this->sendError('Registration failed: ' . $e->getMessage(), [], 500);
|
return $this->sendError('Registration failed: '.$e->getMessage(), [], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,7 +91,7 @@ public function logout(Request $request): JsonResponse
|
||||||
|
|
||||||
return $this->sendResponse(null, 'Logged out successfully');
|
return $this->sendResponse(null, 'Logged out successfully');
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return $this->sendError('Logout failed: ' . $e->getMessage(), [], 500);
|
return $this->sendError('Logout failed: '.$e->getMessage(), [], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use InvalidArgumentException;
|
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
class FeedsController extends BaseController
|
class FeedsController extends BaseController
|
||||||
{
|
{
|
||||||
|
|
@ -37,7 +37,7 @@ public function index(Request $request): JsonResponse
|
||||||
'total' => $feeds->total(),
|
'total' => $feeds->total(),
|
||||||
'from' => $feeds->firstItem(),
|
'from' => $feeds->firstItem(),
|
||||||
'to' => $feeds->lastItem(),
|
'to' => $feeds->lastItem(),
|
||||||
]
|
],
|
||||||
], 'Feeds retrieved successfully.');
|
], 'Feeds retrieved successfully.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,7 +64,7 @@ public function store(StoreFeedRequest $request, CreateFeedAction $createFeedAct
|
||||||
} catch (InvalidArgumentException $e) {
|
} catch (InvalidArgumentException $e) {
|
||||||
return $this->sendError($e->getMessage(), [], 422);
|
return $this->sendError($e->getMessage(), [], 422);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $this->sendError('Failed to create feed: ' . $e->getMessage(), [], 500);
|
return $this->sendError('Failed to create feed: '.$e->getMessage(), [], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -97,7 +97,7 @@ public function update(UpdateFeedRequest $request, Feed $feed): JsonResponse
|
||||||
} catch (ValidationException $e) {
|
} catch (ValidationException $e) {
|
||||||
return $this->sendValidationError($e->errors());
|
return $this->sendValidationError($e->errors());
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $this->sendError('Failed to update feed: ' . $e->getMessage(), [], 500);
|
return $this->sendError('Failed to update feed: '.$e->getMessage(), [], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,7 +114,7 @@ public function destroy(Feed $feed): JsonResponse
|
||||||
'Feed deleted successfully!'
|
'Feed deleted successfully!'
|
||||||
);
|
);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $this->sendError('Failed to delete feed: ' . $e->getMessage(), [], 500);
|
return $this->sendError('Failed to delete feed: '.$e->getMessage(), [], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -124,7 +124,7 @@ public function destroy(Feed $feed): JsonResponse
|
||||||
public function toggle(Feed $feed): JsonResponse
|
public function toggle(Feed $feed): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$newStatus = !$feed->is_active;
|
$newStatus = ! $feed->is_active;
|
||||||
$feed->update(['is_active' => $newStatus]);
|
$feed->update(['is_active' => $newStatus]);
|
||||||
|
|
||||||
$status = $newStatus ? 'activated' : 'deactivated';
|
$status = $newStatus ? 'activated' : 'deactivated';
|
||||||
|
|
@ -134,7 +134,7 @@ public function toggle(Feed $feed): JsonResponse
|
||||||
"Feed {$status} successfully!"
|
"Feed {$status} successfully!"
|
||||||
);
|
);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $this->sendError('Failed to toggle feed status: ' . $e->getMessage(), [], 500);
|
return $this->sendError('Failed to toggle feed status: '.$e->getMessage(), [], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -62,7 +62,7 @@ public function store(Request $request, Feed $feed, PlatformChannel $channel): J
|
||||||
} catch (ValidationException $e) {
|
} catch (ValidationException $e) {
|
||||||
return $this->sendValidationError($e->errors());
|
return $this->sendValidationError($e->errors());
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return $this->sendError('Failed to create keyword: ' . $e->getMessage(), [], 500);
|
return $this->sendError('Failed to create keyword: '.$e->getMessage(), [], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -90,7 +90,7 @@ public function update(Request $request, Feed $feed, PlatformChannel $channel, K
|
||||||
} catch (ValidationException $e) {
|
} catch (ValidationException $e) {
|
||||||
return $this->sendValidationError($e->errors());
|
return $this->sendValidationError($e->errors());
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return $this->sendError('Failed to update keyword: ' . $e->getMessage(), [], 500);
|
return $this->sendError('Failed to update keyword: '.$e->getMessage(), [], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -112,7 +112,7 @@ public function destroy(Feed $feed, PlatformChannel $channel, Keyword $keyword):
|
||||||
'Keyword deleted successfully!'
|
'Keyword deleted successfully!'
|
||||||
);
|
);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return $this->sendError('Failed to delete keyword: ' . $e->getMessage(), [], 500);
|
return $this->sendError('Failed to delete keyword: '.$e->getMessage(), [], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,7 +127,7 @@ public function toggle(Feed $feed, PlatformChannel $channel, Keyword $keyword):
|
||||||
return $this->sendNotFound('Keyword not found for this route.');
|
return $this->sendNotFound('Keyword not found for this route.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$newStatus = !$keyword->is_active;
|
$newStatus = ! $keyword->is_active;
|
||||||
$keyword->update(['is_active' => $newStatus]);
|
$keyword->update(['is_active' => $newStatus]);
|
||||||
|
|
||||||
$status = $newStatus ? 'activated' : 'deactivated';
|
$status = $newStatus ? 'activated' : 'deactivated';
|
||||||
|
|
@ -137,7 +137,7 @@ public function toggle(Feed $feed, PlatformChannel $channel, Keyword $keyword):
|
||||||
"Keyword {$status} successfully!"
|
"Keyword {$status} successfully!"
|
||||||
);
|
);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return $this->sendError('Failed to toggle keyword status: ' . $e->getMessage(), [], 500);
|
return $this->sendError('Failed to toggle keyword status: '.$e->getMessage(), [], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -49,7 +49,7 @@ public function index(Request $request): JsonResponse
|
||||||
],
|
],
|
||||||
], 'Logs retrieved successfully.');
|
], 'Logs retrieved successfully.');
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return $this->sendError('Failed to retrieve logs: ' . $e->getMessage(), [], 500);
|
return $this->sendError('Failed to retrieve logs: '.$e->getMessage(), [], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ public function store(StorePlatformAccountRequest $request, CreatePlatformAccoun
|
||||||
if (str_contains($e->getMessage(), 'Rate limited by')) {
|
if (str_contains($e->getMessage(), 'Rate limited by')) {
|
||||||
return $this->sendError($e->getMessage(), [], 429);
|
return $this->sendError($e->getMessage(), [], 429);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->sendError('Invalid username or password. Please check your credentials and try again.', [], 422);
|
return $this->sendError('Invalid username or password. Please check your credentials and try again.', [], 422);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $this->sendError('Unable to connect to the Lemmy instance. Please check the URL and try again.', [], 422);
|
return $this->sendError('Unable to connect to the Lemmy instance. Please check the URL and try again.', [], 422);
|
||||||
|
|
@ -97,7 +98,7 @@ public function update(Request $request, PlatformAccount $platformAccount): Json
|
||||||
} catch (ValidationException $e) {
|
} catch (ValidationException $e) {
|
||||||
return $this->sendValidationError($e->errors());
|
return $this->sendValidationError($e->errors());
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $this->sendError('Failed to update platform account: ' . $e->getMessage(), [], 500);
|
return $this->sendError('Failed to update platform account: '.$e->getMessage(), [], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,7 +115,7 @@ public function destroy(PlatformAccount $platformAccount): JsonResponse
|
||||||
'Platform account deleted successfully!'
|
'Platform account deleted successfully!'
|
||||||
);
|
);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $this->sendError('Failed to delete platform account: ' . $e->getMessage(), [], 500);
|
return $this->sendError('Failed to delete platform account: '.$e->getMessage(), [], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -131,7 +132,7 @@ public function setActive(PlatformAccount $platformAccount): JsonResponse
|
||||||
"Set {$platformAccount->username}@{$platformAccount->instance_url} as active for {$platformAccount->platform->value}!"
|
"Set {$platformAccount->username}@{$platformAccount->instance_url} as active for {$platformAccount->platform->value}!"
|
||||||
);
|
);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $this->sendError('Failed to set platform account as active: ' . $e->getMessage(), [], 500);
|
return $this->sendError('Failed to set platform account as active: '.$e->getMessage(), [], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -52,7 +52,7 @@ public function store(StoreRouteRequest $request, CreateRouteAction $createRoute
|
||||||
201
|
201
|
||||||
);
|
);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $this->sendError('Failed to create routing configuration: ' . $e->getMessage(), [], 500);
|
return $this->sendError('Failed to create routing configuration: '.$e->getMessage(), [], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,7 +63,7 @@ public function show(Feed $feed, PlatformChannel $channel): JsonResponse
|
||||||
{
|
{
|
||||||
$route = $this->findRoute($feed, $channel);
|
$route = $this->findRoute($feed, $channel);
|
||||||
|
|
||||||
if (!$route) {
|
if (! $route) {
|
||||||
return $this->sendNotFound('Routing configuration not found.');
|
return $this->sendNotFound('Routing configuration not found.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,7 +83,7 @@ public function update(Request $request, Feed $feed, PlatformChannel $channel):
|
||||||
try {
|
try {
|
||||||
$route = $this->findRoute($feed, $channel);
|
$route = $this->findRoute($feed, $channel);
|
||||||
|
|
||||||
if (!$route) {
|
if (! $route) {
|
||||||
return $this->sendNotFound('Routing configuration not found.');
|
return $this->sendNotFound('Routing configuration not found.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -103,7 +103,7 @@ public function update(Request $request, Feed $feed, PlatformChannel $channel):
|
||||||
} catch (ValidationException $e) {
|
} catch (ValidationException $e) {
|
||||||
return $this->sendValidationError($e->errors());
|
return $this->sendValidationError($e->errors());
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $this->sendError('Failed to update routing configuration: ' . $e->getMessage(), [], 500);
|
return $this->sendError('Failed to update routing configuration: '.$e->getMessage(), [], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -115,7 +115,7 @@ public function destroy(Feed $feed, PlatformChannel $channel): JsonResponse
|
||||||
try {
|
try {
|
||||||
$route = $this->findRoute($feed, $channel);
|
$route = $this->findRoute($feed, $channel);
|
||||||
|
|
||||||
if (!$route) {
|
if (! $route) {
|
||||||
return $this->sendNotFound('Routing configuration not found.');
|
return $this->sendNotFound('Routing configuration not found.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -128,7 +128,7 @@ public function destroy(Feed $feed, PlatformChannel $channel): JsonResponse
|
||||||
'Routing configuration deleted successfully!'
|
'Routing configuration deleted successfully!'
|
||||||
);
|
);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $this->sendError('Failed to delete routing configuration: ' . $e->getMessage(), [], 500);
|
return $this->sendError('Failed to delete routing configuration: '.$e->getMessage(), [], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -140,11 +140,11 @@ public function toggle(Feed $feed, PlatformChannel $channel): JsonResponse
|
||||||
try {
|
try {
|
||||||
$route = $this->findRoute($feed, $channel);
|
$route = $this->findRoute($feed, $channel);
|
||||||
|
|
||||||
if (!$route) {
|
if (! $route) {
|
||||||
return $this->sendNotFound('Routing configuration not found.');
|
return $this->sendNotFound('Routing configuration not found.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$newStatus = !$route->is_active;
|
$newStatus = ! $route->is_active;
|
||||||
Route::where('feed_id', $feed->id)
|
Route::where('feed_id', $feed->id)
|
||||||
->where('platform_channel_id', $channel->id)
|
->where('platform_channel_id', $channel->id)
|
||||||
->update(['is_active' => $newStatus]);
|
->update(['is_active' => $newStatus]);
|
||||||
|
|
@ -156,7 +156,7 @@ public function toggle(Feed $feed, PlatformChannel $channel): JsonResponse
|
||||||
"Routing configuration {$status} successfully!"
|
"Routing configuration {$status} successfully!"
|
||||||
);
|
);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $this->sendError('Failed to toggle routing configuration status: ' . $e->getMessage(), [], 500);
|
return $this->sendError('Failed to toggle routing configuration status: '.$e->getMessage(), [], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ public function index(): JsonResponse
|
||||||
|
|
||||||
return $this->sendResponse($settings, 'Settings retrieved successfully.');
|
return $this->sendResponse($settings, 'Settings retrieved successfully.');
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return $this->sendError('Failed to retrieve settings: ' . $e->getMessage(), [], 500);
|
return $this->sendError('Failed to retrieve settings: '.$e->getMessage(), [], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,7 +64,7 @@ public function update(Request $request): JsonResponse
|
||||||
} catch (ValidationException $e) {
|
} catch (ValidationException $e) {
|
||||||
return $this->sendValidationError($e->errors());
|
return $this->sendValidationError($e->errors());
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return $this->sendError('Failed to update settings: ' . $e->getMessage(), [], 500);
|
return $this->sendError('Failed to update settings: '.$e->getMessage(), [], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ public function __construct(
|
||||||
*/
|
*/
|
||||||
public function handle(Request $request, Closure $next): Response
|
public function handle(Request $request, Closure $next): Response
|
||||||
{
|
{
|
||||||
if (!$this->onboardingService->needsOnboarding()) {
|
if (! $this->onboardingService->needsOnboarding()) {
|
||||||
return redirect()->route('dashboard');
|
return redirect()->route('dashboard');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ public function rules(): array
|
||||||
'provider' => "required|in:{$providers}",
|
'provider' => "required|in:{$providers}",
|
||||||
'language_id' => 'required|exists:languages,id',
|
'language_id' => 'required|exists:languages,id',
|
||||||
'description' => 'nullable|string',
|
'description' => 'nullable|string',
|
||||||
'is_active' => 'boolean'
|
'is_active' => 'boolean',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -19,11 +19,11 @@ public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'name' => 'required|string|max:255',
|
'name' => 'required|string|max:255',
|
||||||
'url' => 'required|url|unique:feeds,url,' . ($this->route('feed') instanceof Feed ? (string)$this->route('feed')->id : (string)$this->route('feed')),
|
'url' => 'required|url|unique:feeds,url,'.($this->route('feed') instanceof Feed ? (string) $this->route('feed')->id : (string) $this->route('feed')),
|
||||||
'type' => 'required|in:website,rss',
|
'type' => 'required|in:website,rss',
|
||||||
'language_id' => 'required|exists:languages,id',
|
'language_id' => 'required|exists:languages,id',
|
||||||
'description' => 'nullable|string',
|
'description' => 'nullable|string',
|
||||||
'is_active' => 'boolean'
|
'is_active' => 'boolean',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -25,7 +25,7 @@ public function handle(LogSaver $logSaver, ArticleFetcher $articleFetcher): void
|
||||||
$logSaver->info('Starting feed article fetch', null, [
|
$logSaver->info('Starting feed article fetch', null, [
|
||||||
'feed_id' => $this->feed->id,
|
'feed_id' => $this->feed->id,
|
||||||
'feed_name' => $this->feed->name,
|
'feed_name' => $this->feed->name,
|
||||||
'feed_url' => $this->feed->url
|
'feed_url' => $this->feed->url,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$articles = $articleFetcher->getArticlesFromFeed($this->feed);
|
$articles = $articleFetcher->getArticlesFromFeed($this->feed);
|
||||||
|
|
@ -33,7 +33,7 @@ public function handle(LogSaver $logSaver, ArticleFetcher $articleFetcher): void
|
||||||
$logSaver->info('Feed article fetch completed', null, [
|
$logSaver->info('Feed article fetch completed', null, [
|
||||||
'feed_id' => $this->feed->id,
|
'feed_id' => $this->feed->id,
|
||||||
'feed_name' => $this->feed->name,
|
'feed_name' => $this->feed->name,
|
||||||
'articles_count' => $articles->count()
|
'articles_count' => $articles->count(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->feed->update(['last_fetched_at' => now()]);
|
$this->feed->update(['last_fetched_at' => now()]);
|
||||||
|
|
@ -56,7 +56,7 @@ public static function dispatchForAllActiveFeeds(): void
|
||||||
$logSaver->info('Dispatched feed discovery job', null, [
|
$logSaver->info('Dispatched feed discovery job', null, [
|
||||||
'feed_id' => $feed->id,
|
'feed_id' => $feed->id,
|
||||||
'feed_name' => $feed->name,
|
'feed_name' => $feed->name,
|
||||||
'delay_minutes' => $delayMinutes
|
'delay_minutes' => $delayMinutes,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ public function __construct()
|
||||||
|
|
||||||
public function handle(LogSaver $logSaver): void
|
public function handle(LogSaver $logSaver): void
|
||||||
{
|
{
|
||||||
if (!Setting::isArticleProcessingEnabled()) {
|
if (! Setting::isArticleProcessingEnabled()) {
|
||||||
$logSaver->info('Article processing is disabled. Article discovery skipped.');
|
$logSaver->info('Article processing is disabled. Article discovery skipped.');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Foundation\Queue\Queueable;
|
use Illuminate\Foundation\Queue\Queueable;
|
||||||
|
|
||||||
class PublishNextArticleJob implements ShouldQueue, ShouldBeUnique
|
class PublishNextArticleJob implements ShouldBeUnique, ShouldQueue
|
||||||
{
|
{
|
||||||
use Queueable;
|
use Queueable;
|
||||||
|
|
||||||
|
|
@ -28,6 +28,7 @@ public function __construct()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the job.
|
* Execute the job.
|
||||||
|
*
|
||||||
* @throws PublishException
|
* @throws PublishException
|
||||||
*/
|
*/
|
||||||
public function handle(ArticleFetcher $articleFetcher, ArticlePublishingService $publishingService): void
|
public function handle(ArticleFetcher $articleFetcher, ArticlePublishingService $publishingService): void
|
||||||
|
|
@ -56,7 +57,7 @@ public function handle(ArticleFetcher $articleFetcher, ArticlePublishingService
|
||||||
'article_id' => $article->id,
|
'article_id' => $article->id,
|
||||||
'title' => $article->title,
|
'title' => $article->title,
|
||||||
'url' => $article->url,
|
'url' => $article->url,
|
||||||
'created_at' => $article->created_at
|
'created_at' => $article->created_at,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Fetch article data
|
// Fetch article data
|
||||||
|
|
@ -67,12 +68,12 @@ public function handle(ArticleFetcher $articleFetcher, ArticlePublishingService
|
||||||
|
|
||||||
logger()->info('Successfully published article', [
|
logger()->info('Successfully published article', [
|
||||||
'article_id' => $article->id,
|
'article_id' => $article->id,
|
||||||
'title' => $article->title
|
'title' => $article->title,
|
||||||
]);
|
]);
|
||||||
} catch (PublishException $e) {
|
} catch (PublishException $e) {
|
||||||
logger()->error('Failed to publish article', [
|
logger()->error('Failed to publish article', [
|
||||||
'article_id' => $article->id,
|
'article_id' => $article->id,
|
||||||
'error' => $e->getMessage()
|
'error' => $e->getMessage(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
throw $e;
|
throw $e;
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
use Illuminate\Foundation\Queue\Queueable;
|
use Illuminate\Foundation\Queue\Queueable;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
|
||||||
class SyncChannelPostsJob implements ShouldQueue, ShouldBeUnique
|
class SyncChannelPostsJob implements ShouldBeUnique, ShouldQueue
|
||||||
{
|
{
|
||||||
use Queueable;
|
use Queueable;
|
||||||
|
|
||||||
|
|
@ -78,7 +78,7 @@ private function syncLemmyChannelPosts(LogSaver $logSaver): void
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$logSaver->error('Failed to sync channel posts', $this->channel, [
|
$logSaver->error('Failed to sync channel posts', $this->channel, [
|
||||||
'error' => $e->getMessage()
|
'error' => $e->getMessage(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
throw $e;
|
throw $e;
|
||||||
|
|
@ -97,13 +97,13 @@ private function getAuthToken(LemmyApiService $api, PlatformAccount $account): s
|
||||||
return $cachedToken;
|
return $cachedToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$account->username || !$account->password) {
|
if (! $account->username || ! $account->password) {
|
||||||
throw new PlatformAuthException(PlatformEnum::LEMMY, 'Missing credentials for account');
|
throw new PlatformAuthException(PlatformEnum::LEMMY, 'Missing credentials for account');
|
||||||
}
|
}
|
||||||
|
|
||||||
$token = $api->login($account->username, $account->password);
|
$token = $api->login($account->username, $account->password);
|
||||||
|
|
||||||
if (!$token) {
|
if (! $token) {
|
||||||
throw new PlatformAuthException(PlatformEnum::LEMMY, 'Login failed for account');
|
throw new PlatformAuthException(PlatformEnum::LEMMY, 'Login failed for account');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,14 @@
|
||||||
use App\Events\ExceptionLogged;
|
use App\Events\ExceptionLogged;
|
||||||
use App\Events\ExceptionOccurred;
|
use App\Events\ExceptionOccurred;
|
||||||
use App\Models\Log;
|
use App\Models\Log;
|
||||||
|
|
||||||
class LogExceptionToDatabase
|
class LogExceptionToDatabase
|
||||||
{
|
{
|
||||||
|
|
||||||
public function handle(ExceptionOccurred $event): void
|
public function handle(ExceptionOccurred $event): void
|
||||||
{
|
{
|
||||||
// Truncate the message to prevent database errors
|
// Truncate the message to prevent database errors
|
||||||
$message = strlen($event->message) > 255
|
$message = strlen($event->message) > 255
|
||||||
? substr($event->message, 0, 252) . '...'
|
? substr($event->message, 0, 252).'...'
|
||||||
: $event->message;
|
: $event->message;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -24,15 +24,15 @@ public function handle(ExceptionOccurred $event): void
|
||||||
'file' => $event->exception->getFile(),
|
'file' => $event->exception->getFile(),
|
||||||
'line' => $event->exception->getLine(),
|
'line' => $event->exception->getLine(),
|
||||||
'trace' => $event->exception->getTraceAsString(),
|
'trace' => $event->exception->getTraceAsString(),
|
||||||
...$event->context
|
...$event->context,
|
||||||
]
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
ExceptionLogged::dispatch($log);
|
ExceptionLogged::dispatch($log);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
// Prevent infinite recursion by not logging this exception
|
// Prevent infinite recursion by not logging this exception
|
||||||
// Optionally log to file or other non-database destination
|
// Optionally log to file or other non-database destination
|
||||||
error_log("Failed to log exception to database: " . $e->getMessage());
|
error_log('Failed to log exception to database: '.$e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ public function handle(NewArticleFetched $event): void
|
||||||
'article_id' => $article->id,
|
'article_id' => $article->id,
|
||||||
'error' => $e->getMessage(),
|
'error' => $e->getMessage(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,7 @@
|
||||||
|
|
||||||
class AppServiceProvider extends ServiceProvider
|
class AppServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
public function register(): void
|
public function register(): void {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public function boot(): void
|
public function boot(): void
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
namespace Database\Factories;
|
namespace Database\Factories;
|
||||||
|
|
||||||
use App\Models\ArticlePublication;
|
|
||||||
use App\Models\Article;
|
use App\Models\Article;
|
||||||
|
use App\Models\ArticlePublication;
|
||||||
use App\Models\PlatformChannel;
|
use App\Models\PlatformChannel;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ public function definition(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'platform' => PlatformEnum::LEMMY,
|
'platform' => PlatformEnum::LEMMY,
|
||||||
'instance_url' => 'https://lemmy.' . $this->faker->domainName(),
|
'instance_url' => 'https://lemmy.'.$this->faker->domainName(),
|
||||||
'username' => $this->faker->userName(),
|
'username' => $this->faker->userName(),
|
||||||
'password' => 'test-password',
|
'password' => 'test-password',
|
||||||
'settings' => [],
|
'settings' => [],
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ public function inactive(): static
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function community(string $name = null): static
|
public function community(?string $name = null): static
|
||||||
{
|
{
|
||||||
$communityName = $name ?: $this->faker->word();
|
$communityName = $name ?: $this->faker->word();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,8 @@ public function lemmy(): static
|
||||||
{
|
{
|
||||||
return $this->state(fn (array $attributes) => [
|
return $this->state(fn (array $attributes) => [
|
||||||
'platform' => 'lemmy',
|
'platform' => 'lemmy',
|
||||||
'name' => 'Lemmy ' . $this->faker->word(),
|
'name' => 'Lemmy '.$this->faker->word(),
|
||||||
'url' => 'https://lemmy.' . $this->faker->domainName(),
|
'url' => 'https://lemmy.'.$this->faker->domainName(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
namespace Database\Factories;
|
namespace Database\Factories;
|
||||||
|
|
||||||
use App\Models\Route;
|
|
||||||
use App\Models\Feed;
|
use App\Models\Feed;
|
||||||
use App\Models\PlatformChannel;
|
use App\Models\PlatformChannel;
|
||||||
|
use App\Models\Route;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
class RouteFactory extends Factory
|
class RouteFactory extends Factory
|
||||||
|
|
|
||||||
|
|
@ -17,14 +17,13 @@ public function run(): void
|
||||||
'name' => 'Belgae Social',
|
'name' => 'Belgae Social',
|
||||||
'description' => 'A Belgian Lemmy instance on the fediverse',
|
'description' => 'A Belgian Lemmy instance on the fediverse',
|
||||||
],
|
],
|
||||||
])->each (fn ($instanceData) =>
|
])->each(fn ($instanceData) => PlatformInstance::updateOrCreate(
|
||||||
PlatformInstance::updateOrCreate(
|
[
|
||||||
[
|
'platform' => $instanceData['platform'],
|
||||||
'platform' => $instanceData['platform'],
|
'url' => $instanceData['url'],
|
||||||
'url' => $instanceData['url'],
|
],
|
||||||
],
|
$instanceData
|
||||||
$instanceData
|
)
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
namespace Database\Seeders;
|
namespace Database\Seeders;
|
||||||
|
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
class SettingsSeeder extends Seeder
|
class SettingsSeeder extends Seeder
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,12 @@
|
||||||
use App\Http\Controllers\Api\V1\AuthController;
|
use App\Http\Controllers\Api\V1\AuthController;
|
||||||
use App\Http\Controllers\Api\V1\DashboardController;
|
use App\Http\Controllers\Api\V1\DashboardController;
|
||||||
use App\Http\Controllers\Api\V1\FeedsController;
|
use App\Http\Controllers\Api\V1\FeedsController;
|
||||||
|
use App\Http\Controllers\Api\V1\KeywordsController;
|
||||||
use App\Http\Controllers\Api\V1\LogsController;
|
use App\Http\Controllers\Api\V1\LogsController;
|
||||||
use App\Http\Controllers\Api\V1\OnboardingController;
|
use App\Http\Controllers\Api\V1\OnboardingController;
|
||||||
use App\Http\Controllers\Api\V1\PlatformAccountsController;
|
use App\Http\Controllers\Api\V1\PlatformAccountsController;
|
||||||
use App\Http\Controllers\Api\V1\PlatformChannelsController;
|
use App\Http\Controllers\Api\V1\PlatformChannelsController;
|
||||||
use App\Http\Controllers\Api\V1\RoutingController;
|
use App\Http\Controllers\Api\V1\RoutingController;
|
||||||
use App\Http\Controllers\Api\V1\KeywordsController;
|
|
||||||
use App\Http\Controllers\Api\V1\SettingsController;
|
use App\Http\Controllers\Api\V1\SettingsController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue