mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
subtitles crud
This commit is contained in:
@@ -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'])
|
||||
|
||||
@@ -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']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user