Forum: - TipTap WYSIWYG editor with full toolbar - @emoji-mart/react emoji picker (consistent with tweets) - @mention autocomplete with user search API - Fix PHP 8.4 parse errors in Blade templates - Fix thread data display (paginator items) - Align forum page widths to max-w-5xl Discover: - Extract shared _nav.blade.php partial - Add missing nav links to for-you page - Add Following link for authenticated users Feed/Posts: - Post model, controllers, policies, migrations - Feed page components (PostComposer, FeedCard, etc) - Post reactions, comments, saves, reports, sharing - Scheduled publishing support - Link preview controller Profile: - Profile page components (ProfileHero, ProfileTabs) - Profile API controller Uploads: - Upload wizard enhancements - Scheduled publish picker - Studio status bar and readiness checklist
59 lines
1.9 KiB
PHP
59 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\Posts;
|
|
|
|
use App\Events\Posts\ArtworkShared;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Posts\ShareArtworkRequest;
|
|
use App\Models\Artwork;
|
|
use App\Services\Posts\PostFeedService;
|
|
use App\Services\Posts\PostShareService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Support\Facades\RateLimiter;
|
|
|
|
class PostShareController extends Controller
|
|
{
|
|
public function __construct(
|
|
private PostShareService $shareService,
|
|
private PostFeedService $feedService,
|
|
) {}
|
|
|
|
/**
|
|
* POST /api/posts/share/artwork/{artwork_id}
|
|
* payload: { body?, visibility }
|
|
*/
|
|
public function shareArtwork(ShareArtworkRequest $request, int $artworkId): JsonResponse
|
|
{
|
|
$user = $request->user();
|
|
$artwork = Artwork::findOrFail($artworkId);
|
|
|
|
// Rate limit: 10 artwork shares per hour
|
|
$key = 'share_artwork:' . $user->id;
|
|
if (RateLimiter::tooManyAttempts($key, 10)) {
|
|
$seconds = RateLimiter::availableIn($key);
|
|
return response()->json([
|
|
'message' => "You're sharing too quickly. Please wait {$seconds} seconds.",
|
|
], 429);
|
|
}
|
|
RateLimiter::hit($key, 3600);
|
|
|
|
$post = $this->shareService->shareArtwork(
|
|
user: $user,
|
|
artwork: $artwork,
|
|
body: $request->input('body'),
|
|
visibility: $request->input('visibility', 'public'),
|
|
);
|
|
|
|
$post->load(['user', 'user.profile', 'targets', 'targets.artwork', 'targets.artwork.user', 'targets.artwork.user.profile', 'reactions']);
|
|
|
|
// Notify original artwork owner (unless self-share)
|
|
if ($artwork->user_id !== $user->id) {
|
|
event(new ArtworkShared($post, $artwork, $user));
|
|
}
|
|
|
|
return response()->json([
|
|
'post' => $this->feedService->formatPost($post, $user->id),
|
|
], 201);
|
|
}
|
|
}
|