|
@@ -16,19 +16,19 @@ use Slim\Exception\HttpUnauthorizedException;
|
|
class MediaController extends Controller
|
|
class MediaController extends Controller
|
|
{
|
|
{
|
|
/**
|
|
/**
|
|
- * @param Request $request
|
|
|
|
- * @param Response $response
|
|
|
|
- * @param string $userCode
|
|
|
|
- * @param string $mediaCode
|
|
|
|
- * @param string|null $token
|
|
|
|
|
|
+ * @param Request $request
|
|
|
|
+ * @param Response $response
|
|
|
|
+ * @param string $userCode
|
|
|
|
+ * @param string $mediaCode
|
|
|
|
+ * @param string|null $token
|
|
*
|
|
*
|
|
- * @return Response
|
|
|
|
* @throws HttpNotFoundException
|
|
* @throws HttpNotFoundException
|
|
* @throws \Twig\Error\LoaderError
|
|
* @throws \Twig\Error\LoaderError
|
|
* @throws \Twig\Error\RuntimeError
|
|
* @throws \Twig\Error\RuntimeError
|
|
* @throws \Twig\Error\SyntaxError
|
|
* @throws \Twig\Error\SyntaxError
|
|
* @throws FileNotFoundException
|
|
* @throws FileNotFoundException
|
|
*
|
|
*
|
|
|
|
+ * @return Response
|
|
*/
|
|
*/
|
|
public function show(Request $request, Response $response, string $userCode, string $mediaCode, string $token = null): Response
|
|
public function show(Request $request, Response $response, string $userCode, string $mediaCode, string $token = null): Response
|
|
{
|
|
{
|
|
@@ -68,21 +68,21 @@ class MediaController extends Controller
|
|
|
|
|
|
return view()->render($response, 'upload/public.twig', [
|
|
return view()->render($response, 'upload/public.twig', [
|
|
'delete_token' => $token,
|
|
'delete_token' => $token,
|
|
- 'media' => $media,
|
|
|
|
- 'type' => $type,
|
|
|
|
- 'url' => urlFor("/{$userCode}/{$mediaCode}"),
|
|
|
|
|
|
+ 'media' => $media,
|
|
|
|
+ 'type' => $type,
|
|
|
|
+ 'url' => urlFor("/{$userCode}/{$mediaCode}"),
|
|
]);
|
|
]);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @param Request $request
|
|
|
|
- * @param Response $response
|
|
|
|
- * @param int $id
|
|
|
|
|
|
+ * @param Request $request
|
|
|
|
+ * @param Response $response
|
|
|
|
+ * @param int $id
|
|
*
|
|
*
|
|
- * @return Response
|
|
|
|
* @throws HttpNotFoundException
|
|
* @throws HttpNotFoundException
|
|
- *
|
|
|
|
* @throws FileNotFoundException
|
|
* @throws FileNotFoundException
|
|
|
|
+ *
|
|
|
|
+ * @return Response
|
|
*/
|
|
*/
|
|
public function getRawById(Request $request, Response $response, int $id): Response
|
|
public function getRawById(Request $request, Response $response, int $id): Response
|
|
{
|
|
{
|
|
@@ -96,17 +96,17 @@ class MediaController extends Controller
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @param Request $request
|
|
|
|
- * @param Response $response
|
|
|
|
- * @param string $userCode
|
|
|
|
- * @param string $mediaCode
|
|
|
|
- * @param string|null $ext
|
|
|
|
|
|
+ * @param Request $request
|
|
|
|
+ * @param Response $response
|
|
|
|
+ * @param string $userCode
|
|
|
|
+ * @param string $mediaCode
|
|
|
|
+ * @param string|null $ext
|
|
*
|
|
*
|
|
- * @return Response
|
|
|
|
* @throws HttpBadRequestException
|
|
* @throws HttpBadRequestException
|
|
* @throws HttpNotFoundException
|
|
* @throws HttpNotFoundException
|
|
- *
|
|
|
|
* @throws FileNotFoundException
|
|
* @throws FileNotFoundException
|
|
|
|
+ *
|
|
|
|
+ * @return Response
|
|
*/
|
|
*/
|
|
public function getRaw(Request $request, Response $response, string $userCode, string $mediaCode, ?string $ext = null): Response
|
|
public function getRaw(Request $request, Response $response, string $userCode, string $mediaCode, ?string $ext = null): Response
|
|
{
|
|
{
|
|
@@ -124,15 +124,15 @@ class MediaController extends Controller
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @param Request $request
|
|
|
|
- * @param Response $response
|
|
|
|
- * @param string $userCode
|
|
|
|
- * @param string $mediaCode
|
|
|
|
|
|
+ * @param Request $request
|
|
|
|
+ * @param Response $response
|
|
|
|
+ * @param string $userCode
|
|
|
|
+ * @param string $mediaCode
|
|
*
|
|
*
|
|
- * @return Response
|
|
|
|
* @throws HttpNotFoundException
|
|
* @throws HttpNotFoundException
|
|
- *
|
|
|
|
* @throws FileNotFoundException
|
|
* @throws FileNotFoundException
|
|
|
|
+ *
|
|
|
|
+ * @return Response
|
|
*/
|
|
*/
|
|
public function download(Request $request, Response $response, string $userCode, string $mediaCode): Response
|
|
public function download(Request $request, Response $response, string $userCode, string $mediaCode): Response
|
|
{
|
|
{
|
|
@@ -146,13 +146,13 @@ class MediaController extends Controller
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @param Request $request
|
|
|
|
- * @param Response $response
|
|
|
|
- * @param int $id
|
|
|
|
|
|
+ * @param Request $request
|
|
|
|
+ * @param Response $response
|
|
|
|
+ * @param int $id
|
|
*
|
|
*
|
|
- * @return Response
|
|
|
|
* @throws HttpNotFoundException
|
|
* @throws HttpNotFoundException
|
|
*
|
|
*
|
|
|
|
+ * @return Response
|
|
*/
|
|
*/
|
|
public function togglePublish(Request $request, Response $response, int $id): Response
|
|
public function togglePublish(Request $request, Response $response, int $id): Response
|
|
{
|
|
{
|
|
@@ -172,14 +172,14 @@ class MediaController extends Controller
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @param Request $request
|
|
|
|
- * @param Response $response
|
|
|
|
- * @param int $id
|
|
|
|
|
|
+ * @param Request $request
|
|
|
|
+ * @param Response $response
|
|
|
|
+ * @param int $id
|
|
*
|
|
*
|
|
- * @return Response
|
|
|
|
* @throws HttpUnauthorizedException
|
|
* @throws HttpUnauthorizedException
|
|
- *
|
|
|
|
* @throws HttpNotFoundException
|
|
* @throws HttpNotFoundException
|
|
|
|
+ *
|
|
|
|
+ * @return Response
|
|
*/
|
|
*/
|
|
public function delete(Request $request, Response $response, int $id): Response
|
|
public function delete(Request $request, Response $response, int $id): Response
|
|
{
|
|
{
|
|
@@ -205,16 +205,16 @@ class MediaController extends Controller
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @param Request $request
|
|
|
|
- * @param Response $response
|
|
|
|
- * @param string $userCode
|
|
|
|
- * @param string $mediaCode
|
|
|
|
- * @param string $token
|
|
|
|
|
|
+ * @param Request $request
|
|
|
|
+ * @param Response $response
|
|
|
|
+ * @param string $userCode
|
|
|
|
+ * @param string $mediaCode
|
|
|
|
+ * @param string $token
|
|
*
|
|
*
|
|
- * @return Response
|
|
|
|
* @throws HttpUnauthorizedException
|
|
* @throws HttpUnauthorizedException
|
|
- *
|
|
|
|
* @throws HttpNotFoundException
|
|
* @throws HttpNotFoundException
|
|
|
|
+ *
|
|
|
|
+ * @return Response
|
|
*/
|
|
*/
|
|
public function deleteByToken(Request $request, Response $response, string $userCode, string $mediaCode, string $token): Response
|
|
public function deleteByToken(Request $request, Response $response, string $userCode, string $mediaCode, string $token): Response
|
|
{
|
|
{
|
|
@@ -249,9 +249,9 @@ class MediaController extends Controller
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @param Request $request
|
|
|
|
- * @param string $storagePath
|
|
|
|
- * @param int $id
|
|
|
|
|
|
+ * @param Request $request
|
|
|
|
+ * @param string $storagePath
|
|
|
|
+ * @param int $id
|
|
*
|
|
*
|
|
* @throws HttpNotFoundException
|
|
* @throws HttpNotFoundException
|
|
*/
|
|
*/
|
|
@@ -285,15 +285,15 @@ class MediaController extends Controller
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @param Request $request
|
|
|
|
- * @param Response $response
|
|
|
|
- * @param Filesystem $storage
|
|
|
|
|
|
+ * @param Request $request
|
|
|
|
+ * @param Response $response
|
|
|
|
+ * @param Filesystem $storage
|
|
* @param $media
|
|
* @param $media
|
|
- * @param string $disposition
|
|
|
|
|
|
+ * @param string $disposition
|
|
*
|
|
*
|
|
- * @return Response
|
|
|
|
* @throws FileNotFoundException
|
|
* @throws FileNotFoundException
|
|
*
|
|
*
|
|
|
|
+ * @return Response
|
|
*/
|
|
*/
|
|
protected function streamMedia(Request $request, Response $response, Filesystem $storage, $media, string $disposition = 'inline'): Response
|
|
protected function streamMedia(Request $request, Response $response, Filesystem $storage, $media, string $disposition = 'inline'): Response
|
|
{
|
|
{
|
|
@@ -324,15 +324,15 @@ class MediaController extends Controller
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @param Filesystem $storage
|
|
|
|
|
|
+ * @param Filesystem $storage
|
|
* @param $media
|
|
* @param $media
|
|
- * @param null $width
|
|
|
|
- * @param null $height
|
|
|
|
- * @param string $disposition
|
|
|
|
|
|
+ * @param null $width
|
|
|
|
+ * @param null $height
|
|
|
|
+ * @param string $disposition
|
|
*
|
|
*
|
|
- * @return Response
|
|
|
|
* @throws FileNotFoundException
|
|
* @throws FileNotFoundException
|
|
*
|
|
*
|
|
|
|
+ * @return Response
|
|
*/
|
|
*/
|
|
protected function makeThumbnail(Filesystem $storage, $media, $width = null, $height = null, string $disposition = 'inline')
|
|
protected function makeThumbnail(Filesystem $storage, $media, $width = null, $height = null, string $disposition = 'inline')
|
|
{
|
|
{
|
|
@@ -346,10 +346,10 @@ class MediaController extends Controller
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @param Response $response
|
|
|
|
- * @param Stream $stream
|
|
|
|
- * @param string $range
|
|
|
|
- * @param string $disposition
|
|
|
|
|
|
+ * @param Response $response
|
|
|
|
+ * @param Stream $stream
|
|
|
|
+ * @param string $range
|
|
|
|
+ * @param string $disposition
|
|
* @param $media
|
|
* @param $media
|
|
* @param $mime
|
|
* @param $mime
|
|
*
|
|
*
|
|
@@ -371,11 +371,11 @@ class MediaController extends Controller
|
|
}
|
|
}
|
|
|
|
|
|
if ($range === '-') {
|
|
if ($range === '-') {
|
|
- $start = $stream->getSize() - (int)substr($range, 1);
|
|
|
|
|
|
+ $start = $stream->getSize() - (int) substr($range, 1);
|
|
} else {
|
|
} else {
|
|
$range = explode('-', $range);
|
|
$range = explode('-', $range);
|
|
- $start = (int)$range[0];
|
|
|
|
- $end = (isset($range[1]) && is_numeric($range[1])) ? (int)$range[1] : $stream->getSize();
|
|
|
|
|
|
+ $start = (int) $range[0];
|
|
|
|
+ $end = (isset($range[1]) && is_numeric($range[1])) ? (int) $range[1] : $stream->getSize();
|
|
}
|
|
}
|
|
|
|
|
|
$end = ($end > $stream->getSize() - 1) ? $stream->getSize() - 1 : $end;
|
|
$end = ($end > $stream->getSize() - 1) ? $stream->getSize() - 1 : $end;
|