mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-14 02:24:31 +00:00
Update ApiV1Controller, allow description (alt text) updates after status is published
This commit is contained in:
parent
ddbabddd83
commit
869c3ed1fa
1 changed files with 27 additions and 6 deletions
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue