From cb0ab3c823ad67830aed5459eee0f5c972b606b0 Mon Sep 17 00:00:00 2001 From: shimon Date: Thu, 14 Jul 2022 18:26:56 +0300 Subject: [PATCH] subtitles crud --- app/controllers/api/videos.php | 42 ++++++++++++++++++- .../Services/Videos/VideoCustomServerTest.php | 32 ++++++++++++-- 2 files changed, 69 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/videos.php b/app/controllers/api/videos.php index 79c8411592..4026d79e65 100644 --- a/app/controllers/api/videos.php +++ b/app/controllers/api/videos.php @@ -159,7 +159,7 @@ App::patch('/v1/videos/profiles/:profileId') ->action(action: function (string $profileId, string $name, string $videoBitrate, string $audioBitrate, string $width, string $height, string $stream, Response $response, Database $dbForProject) { $profile = Authorization::skip(fn() => $dbForProject->getDocument('videos_profiles', $profileId)); - var_dump($profile); + ; if ($profile->isEmpty()) { throw new Exception('Project not found', 404, Exception::PROJECT_NOT_FOUND); } @@ -344,6 +344,46 @@ App::get('/v1/videos/:videoId/subtitles') ]), Response::MODEL_VIDEO_SUBTITLE_LIST); }); +App::patch('/v1/videos/:videoId/subtitles/:subtitleId') + ->desc('Update video subtitle') + ->groups(['api', 'video']) + ->label('scope', 'files.write') + ->label('sdk.auth', [APP_AUTH_TYPE_KEY]) + ->label('sdk.namespace', 'video') + ->label('sdk.method', 'update') + ->label('sdk.description', '/docs/references/videos/update-subtitle.md') // TODO: Create markdown + ->label('sdk.response.code', Response::STATUS_CODE_OK) + ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) + ->label('sdk.response.model', Response::MODEL_VIDEO_SUBTITLE) + ->param('subtitleId', null, new UID(), 'Video subtitle unique ID.') + ->param('videoId', null, new UID(), 'Video unique ID.') + ->param('bucketId', '', new CustomId(), 'Subtitle bucket unique ID.') + ->param('fileId', '', new CustomId(), 'Subtitle file unique ID.') + ->param('name', '', new Text(128), 'Subtitle name.') + ->param('code', '', new Text(128), 'Subtitle code name.') + ->param('default', false, new Boolean(true), 'Default subtitle.') + ->inject('response') + ->inject('dbForProject') + ->action(action: function (string $subtitleId, string $videoId, string $bucketId, string $fileId, string $name, string $code, bool $default, Response $response, Database $dbForProject) { + + $subtitle = Authorization::skip(fn() => $dbForProject->getDocument('videos_subtitles', $subtitleId)); + + if ($subtitle->isEmpty()) { + throw new Exception('Project not found', 404, Exception::PROJECT_NOT_FOUND); + } + + $subtitle->setAttribute('videoId', $videoId) + ->setAttribute('bucketId', $bucketId) + ->setAttribute('fileId', $fileId) + ->setAttribute('name', $name) + ->setAttribute('code', $code) + ->setAttribute('default', $default); + + $subtitle = Authorization::skip(fn() => $dbForProject->updateDocument('videos_subtitles', $subtitle->getId(), $subtitle)); + + $response->dynamic($subtitle, Response::MODEL_VIDEO_SUBTITLE); + }); + App::post('/v1/video') ->desc('Create Video') ->groups(['api', 'video']) diff --git a/tests/e2e/Services/Videos/VideoCustomServerTest.php b/tests/e2e/Services/Videos/VideoCustomServerTest.php index f2f9ad33a5..f70907df4d 100644 --- a/tests/e2e/Services/Videos/VideoCustomServerTest.php +++ b/tests/e2e/Services/Videos/VideoCustomServerTest.php @@ -148,10 +148,34 @@ class VideoCustomServerTest extends Scope $this->assertNotEmpty($response['body']['subtitles'][0]['$id']); $this->assertEquals('Eng', $response['body']['subtitles'][0]['code']); -// -//// $this->assertEquals(404, $response['headers']['status-code']); -//// $this->assertNotEmpty($response['body']); -//// $this->assertEquals('Video profile not found', $response['body']['message']); + $response = $this->client->call(Client::METHOD_PATCH, '/videos/' . $videoId . '/subtitles/' . $response['body']['subtitles'][0]['$id'], [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ], [ + 'bucketId' => $this->getBucket()['$id'], + 'fileId' => $this->getSubtitle()['$id'], + 'name' => 'Polish', + 'code' => 'Pol', + 'default' => false, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertNotEmpty($response['body']); + $this->assertNotEmpty($response['body']['$id']); + + $response = $this->client->call(Client::METHOD_GET, '/videos/'. $videoId . '/subtitles' , [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertNotEmpty($response['body']); + $this->assertEquals(1, $response['body']['total']); + $this->assertNotEmpty($response['body']['subtitles']); + $this->assertNotEmpty($response['body']['subtitles'][0]['$id']); + $this->assertEquals('Polish', $response['body']['subtitles'][0]['name']); }