diff --git a/app/Http/Controllers/Api/VideoAnnotationController.php b/app/Http/Controllers/Api/VideoAnnotationController.php index 619bd8aaa..f1ab24bcd 100644 --- a/app/Http/Controllers/Api/VideoAnnotationController.php +++ b/app/Http/Controllers/Api/VideoAnnotationController.php @@ -211,13 +211,8 @@ public function store(StoreVideoAnnotation $request) } } - // from a JSON request, the array may already be decoded $points = $request->input('points', []); - if (is_string($points)) { - $points = json_decode($points); - } - $annotation = new VideoAnnotation([ 'video_id' => $request->video->id, 'shape_id' => $request->input('shape_id'), diff --git a/app/Http/Requests/StoreVideoAnnotation.php b/app/Http/Requests/StoreVideoAnnotation.php index 1a9d18ff1..b42d2dd33 100644 --- a/app/Http/Requests/StoreVideoAnnotation.php +++ b/app/Http/Requests/StoreVideoAnnotation.php @@ -41,6 +41,8 @@ public function rules() 'required_unless:shape_id,'.Shape::wholeFrameId(), 'array', ], + 'points.*' => 'array', + 'points.*.*' => 'numeric', 'frames' => 'required|array', 'frames.*' => 'required|numeric|min:0|max:'.$this->video->duration, 'track' => 'filled|boolean', @@ -67,18 +69,13 @@ public function withValidator($validator) $validator->errors()->add('frames', 'A new whole frame annotation must not have more than two frames.'); } - $points = $this->input('points', []); - $allArrays = array_reduce($points, fn ($c, $i) => $c && is_array($i), true); - - if (!$allArrays) { - $validator->errors()->add('points', 'The points must be an array of arrays.'); - } if ($this->shouldTrack()) { if ($frameCount !== 1) { $validator->errors()->add('id', 'Only single frame annotations can be tracked.'); } + $points = $this->input('points', []); if (count($points) !== 1) { $validator->errors()->add('id', 'Only single frame annotations can be tracked.'); } diff --git a/tests/php/Http/Controllers/Api/VideoAnnotationControllerTest.php b/tests/php/Http/Controllers/Api/VideoAnnotationControllerTest.php index c23d1e1be..43e67851c 100644 --- a/tests/php/Http/Controllers/Api/VideoAnnotationControllerTest.php +++ b/tests/php/Http/Controllers/Api/VideoAnnotationControllerTest.php @@ -356,6 +356,19 @@ public function testStoreValidatePointsArray() ->assertStatus(422); } + public function testStoreValidatePointsArray2() + { + $this->beEditor(); + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + 'shape_id' => Shape::pointId(), + 'label_id' => $this->labelRoot()->id, + 'points' => [[[10, 11]]], + 'frames' => [0.0], + ]) + ->assertStatus(422); + } + public function testStoreValidateFrames() { $this->beEditor();