Skip to content

Commit 9068fa8

Browse files
committed
Enhance video public sharing functionality with video state checks and better error handling,
It contains some improvements in terms of proper error handling and info, as well as checking specifically for running videos in order to prevent users to access the video visibility change dialog and endpoints!
1 parent 2276039 commit 9068fa8

File tree

3 files changed

+212
-164
lines changed

3 files changed

+212
-164
lines changed

lib/Routes/Video/VideoWorldwideShareUpdate.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ public function __invoke(Request $request, Response $response, $args)
2929
throw new Error(_('Das Video kann nicht gefunden werden'), 404);
3030
}
3131

32+
// Take care of running videos by returning a proper response not throwing an exception!
33+
if ($video->state === 'running') {
34+
return $this->createResponse(
35+
_('Das Video befindet sich aktuell in der Bearbeitung. Bitte versuchen Sie es später erneut.'),
36+
$response->withStatus(409)
37+
);
38+
}
39+
3240
if (!$video->havePerm('write')
3341
|| !\Config::get()->OPENCAST_ALLOW_PUBLIC_SHARING
3442
) {
@@ -38,16 +46,21 @@ public function __invoke(Request $request, Response $response, $args)
3846
$json = $this->getRequestData($request);
3947
$visibility = $json['visibility'];
4048

41-
if ($video->setWorldVisibility($visibility) !== true) {
42-
return $this->createResponse(
43-
_('Beim Übertragen der Änderungen zum Videoserver ist ein Fehler aufgetreten.')
44-
, $response->withStatus(500));
45-
} else {
46-
return $this->createResponse(
47-
$visibility === 'public'
49+
$response_code = 500;
50+
$response_message = _('Beim Übertragen der Änderungen zum Videoserver ist ein Fehler aufgetreten.');
51+
52+
try {
53+
$result = $video->setWorldVisibility($visibility);
54+
if ($result === true) {
55+
$response_code = 200;
56+
$response_message = $visibility === 'public'
4857
? _('Das Video wurde auf weltweit zugreifbar gestellt.')
49-
: _('Das Video wurde nur berechtigten Personen zugreifbar gemacht.')
50-
, $response->withStatus(200));
58+
: _('Das Video wurde nur berechtigten Personen zugreifbar gemacht.');
59+
}
60+
} catch (\Throwable $th) {
61+
$response_message .= ' (' . $th->getMessage() . ')';
5162
}
63+
64+
return $this->createResponse($response_message, $response->withStatus($response_code));
5265
}
5366
}

0 commit comments

Comments
 (0)