subtitle lan code

This commit is contained in:
shimon
2023-03-12 14:53:56 +02:00
parent cb217b43b4
commit 883d48c2e5
3 changed files with 199 additions and 7 deletions
File diff suppressed because it is too large Load Diff
+8 -1
View File
@@ -7,6 +7,7 @@ use Appwrite\Utopia\Database\Validator\Queries\Files;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\View;
use Utopia\App;
use Utopia\Config\Config;
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Query;
@@ -266,7 +267,7 @@ App::post('/v1/videos/:videoId/subtitles')
->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('code', '', new Text(3), 'Subtitle ISO 639-2 three letters alpha code.')
->param('default', false, new Boolean(true), 'Default subtitle.')
->inject('request')
->inject('response')
@@ -274,6 +275,12 @@ App::post('/v1/videos/:videoId/subtitles')
->inject('mode')
->action(action: function (string $videoId, string $bucketId, string $fileId, string $name, string $code, bool $default, Request $request, Response $response, Database $dbForProject, string $mode) {
$languages = Config::getParam('locale-languages');
$found = array_search($code, array_column($languages, 'code2'));
if (!$found) {
throw new Exception(Exception::VIDEO_LANGUAGE_CODE_NOT_FOUND);
}
$video = Authorization::skip(fn() => $dbForProject->getDocument('videos', $videoId));
if ($video->isEmpty()) {
+1
View File
@@ -186,6 +186,7 @@ class Exception extends \Exception
public const VIDEO_SUBTITLE_NOT_FOUND = 'video_subtitle_not_found';
public const VIDEO_NOT_FOUND = 'video_not_found';
public const VIDEO_RENDITION_SEGMENT_NOT_FOUND = 'video_rendition_segment_not_found';
public const VIDEO_LANGUAGE_CODE_NOT_FOUND = 'video_language_code_not_found';
public const VIDEO_SUBTITLE_SEGMENT_NOT_FOUND = 'video_subtitle_segment_not_found';