mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
subtitle lan code
This commit is contained in:
@@ -84,6 +84,15 @@ App::post('/v1/videos')
|
||||
->action(action: function (string $bucketId, string $fileId, Request $request, Response $response, Database $dbForProject, string $mode) {
|
||||
|
||||
$file = validateFilePermissions($dbForProject, $bucketId, $fileId, $mode);
|
||||
|
||||
if (
|
||||
!str_starts_with($file->getAttribute('mimeType'), 'video/') &&
|
||||
!str_starts_with($file->getAttribute('mimeType'), 'audio/') &&
|
||||
$file->getAttribute('mimeType') !== 'application/ogg'
|
||||
) {
|
||||
throw new Exception(Exception::VIDEO_NOT_VALID);
|
||||
}
|
||||
|
||||
$video = Authorization::skip(function () use ($dbForProject, $bucketId, $file) {
|
||||
return $dbForProject->createDocument('videos', new Document([
|
||||
'bucketId' => $bucketId,
|
||||
@@ -275,8 +284,10 @@ 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) {
|
||||
|
||||
$code = strtolower($code);
|
||||
$languages = Config::getParam('locale-languages');
|
||||
$found = array_search($code, array_column($languages, 'code2'));
|
||||
|
||||
if (!$found) {
|
||||
throw new Exception(Exception::VIDEO_LANGUAGE_CODE_NOT_FOUND);
|
||||
}
|
||||
@@ -288,7 +299,16 @@ App::post('/v1/videos/:videoId/subtitles')
|
||||
}
|
||||
|
||||
validateFilePermissions($dbForProject, $video['bucketId'], $video['fileId'], $mode);
|
||||
validateFilePermissions($dbForProject, $bucketId, $fileId, $mode);
|
||||
$file = validateFilePermissions($dbForProject, $bucketId, $fileId, $mode);
|
||||
|
||||
if (
|
||||
$file->getAttribute('mimeType') !== 'text/vtt' &&
|
||||
$file->getAttribute('mimeType') !== 'text/plain'
|
||||
) {
|
||||
throw new Exception(Exception::VIDEO_SUBTITLE_NOT_VALID);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$subtitle = Authorization::skip(fn() =>
|
||||
$dbForProject->createDocument('videos_subtitles', new Document([
|
||||
|
||||
@@ -307,6 +307,7 @@ class TranscodingV1 extends Worker
|
||||
}
|
||||
|
||||
console::info('Rendition ' . $query->getId() . ' conversion, done');
|
||||
|
||||
/** Upload & cleanup **/
|
||||
$start = 0;
|
||||
$fileNames = scandir($this->outDir);
|
||||
|
||||
Generated
+6
-6
@@ -943,16 +943,16 @@
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/psr7",
|
||||
"version": "2.4.3",
|
||||
"version": "2.4.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/psr7.git",
|
||||
"reference": "67c26b443f348a51926030c83481b85718457d3d"
|
||||
"reference": "3cf1b6d4f0c820a2cf8bcaec39fc698f3443b5cf"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/psr7/zipball/67c26b443f348a51926030c83481b85718457d3d",
|
||||
"reference": "67c26b443f348a51926030c83481b85718457d3d",
|
||||
"url": "https://api.github.com/repos/guzzle/psr7/zipball/3cf1b6d4f0c820a2cf8bcaec39fc698f3443b5cf",
|
||||
"reference": "3cf1b6d4f0c820a2cf8bcaec39fc698f3443b5cf",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -1042,7 +1042,7 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/guzzle/psr7/issues",
|
||||
"source": "https://github.com/guzzle/psr7/tree/2.4.3"
|
||||
"source": "https://github.com/guzzle/psr7/tree/2.4.4"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@@ -1058,7 +1058,7 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2022-10-26T14:07:24+00:00"
|
||||
"time": "2023-03-09T13:19:02+00:00"
|
||||
},
|
||||
{
|
||||
"name": "influxdb/influxdb-php",
|
||||
|
||||
@@ -188,6 +188,7 @@ class Exception extends \Exception
|
||||
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';
|
||||
public const VIDEO_SUBTITLE_NOT_VALID = 'video_subtitle_not_valid';
|
||||
|
||||
|
||||
/** GraphqQL */
|
||||
|
||||
@@ -116,6 +116,20 @@ class VideosCustomClientTest extends Scope
|
||||
'code' => 'It',
|
||||
]);
|
||||
|
||||
$this->assertEquals(404, $response['headers']['status-code']);
|
||||
|
||||
|
||||
$response = $this->client->call(Client::METHOD_POST, '/videos/' . $videoId . '/subtitles', [
|
||||
'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' => 'Italian',
|
||||
'code' => 'Ita',
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
$this->assertNotEmpty($response['body']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
|
||||
@@ -191,6 +191,17 @@ class VideosCustomServerTest extends Scope
|
||||
|
||||
public function testCreateVideo(): string
|
||||
{
|
||||
$response = $this->client->call(Client::METHOD_POST, '/videos', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
], [
|
||||
'bucketId' => $this->getBucket()['$id'],
|
||||
'fileId' => $this->getSubtitle()['$id']
|
||||
]);
|
||||
|
||||
$this->assertEquals(400, $response['headers']['status-code']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_POST, '/videos', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
@@ -212,6 +223,20 @@ class VideosCustomServerTest extends Scope
|
||||
*/
|
||||
public function testCreateSubtitles($videoId)
|
||||
{
|
||||
|
||||
$response = $this->client->call(Client::METHOD_POST, '/videos/' . $videoId . '/subtitles', [
|
||||
'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' => 'English',
|
||||
'code' => 'xxx',
|
||||
'default' => true,
|
||||
]);
|
||||
$this->assertEquals(404, $response['headers']['status-code']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_POST, '/videos/' . $videoId . '/subtitles', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
@@ -236,7 +261,7 @@ class VideosCustomServerTest extends Scope
|
||||
'bucketId' => $this->getBucket()['$id'],
|
||||
'fileId' => $this->getSubtitle()['$id'],
|
||||
'name' => 'Italian',
|
||||
'code' => 'It',
|
||||
'code' => 'ita',
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
@@ -398,7 +423,7 @@ class VideosCustomServerTest extends Scope
|
||||
'bucketId' => $this->getBucket()['$id'],
|
||||
'fileId' => $this->getSubtitle()['$id'],
|
||||
'name' => 'Italian',
|
||||
'code' => 'It',
|
||||
'code' => 'Ita',
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
|
||||
Reference in New Issue
Block a user