Update ApiV1Controller, allow description (alt text) updates after status is published

This commit is contained in:
Daniel Supernault 2023-01-29 00:27:23 -07:00
parent ddbabddd83
commit 869c3ed1fa
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -68,6 +68,7 @@ use App\Services\{
LikeService, LikeService,
NetworkTimelineService, NetworkTimelineService,
NotificationService, NotificationService,
MediaService,
MediaPathService, MediaPathService,
ProfileStatusService, ProfileStatusService,
PublicTimelineService, PublicTimelineService,
@ -90,6 +91,8 @@ use App\Services\MarkerService;
use App\Models\Conversation; use App\Models\Conversation;
use App\Jobs\FollowPipeline\FollowAcceptPipeline; use App\Jobs\FollowPipeline\FollowAcceptPipeline;
use App\Jobs\FollowPipeline\FollowRejectPipeline; use App\Jobs\FollowPipeline\FollowRejectPipeline;
use Illuminate\Support\Facades\RateLimiter;
use Purify;
class ApiV1Controller extends Controller class ApiV1Controller extends Controller
{ {
@ -1582,15 +1585,33 @@ class ApiV1Controller extends Controller
$user = $request->user(); $user = $request->user();
$media = Media::whereUserId($user->id) $media = Media::whereUserId($user->id)
->whereNull('status_id') ->whereProfileId($user->profile_id)
->findOrFail($id); ->findOrFail($id);
$media->caption = $request->input('description'); $executed = RateLimiter::attempt(
'media:update:'.$user->id,
10,
function() use($media, $request) {
$caption = Purify::clean($request->input('description'));
if($caption != $media->caption) {
$media->caption = $caption;
$media->save(); $media->save();
$resource = new Fractal\Resource\Item($media, new MediaTransformer()); if($media->status_id) {
$res = $this->fractal->createData($resource)->toArray(); MediaService::del($media->status_id);
return $this->json($res); StatusService::del($media->status_id);
}
}
});
if(!$executed) {
return response()->json([
'error' => 'Too many attempts. Try again in a few minutes.'
], 429);
};
return $this->json(MediaService::get($media->status_id));
} }
/** /**