1
0
Fork 0
forked from mirror/pixelfed

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,
NetworkTimelineService,
NotificationService,
MediaService,
MediaPathService,
ProfileStatusService,
PublicTimelineService,
@ -90,6 +91,8 @@ use App\Services\MarkerService;
use App\Models\Conversation;
use App\Jobs\FollowPipeline\FollowAcceptPipeline;
use App\Jobs\FollowPipeline\FollowRejectPipeline;
use Illuminate\Support\Facades\RateLimiter;
use Purify;
class ApiV1Controller extends Controller
{
@ -1582,15 +1585,33 @@ class ApiV1Controller extends Controller
$user = $request->user();
$media = Media::whereUserId($user->id)
->whereNull('status_id')
->whereProfileId($user->profile_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();
$resource = new Fractal\Resource\Item($media, new MediaTransformer());
$res = $this->fractal->createData($resource)->toArray();
return $this->json($res);
if($media->status_id) {
MediaService::del($media->status_id);
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));
}
/**