From df0272e95d0f2c63294032aecc2ad9752704e993 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Fri, 2 Dec 2022 20:44:24 -0800 Subject: [PATCH] refactor: use args for controller query params --- lib/Controller/AlbumsController.php | 3 +-- lib/Controller/ImageController.php | 10 ++++++---- lib/Controller/TagsController.php | 7 ++----- lib/Controller/VideoController.php | 19 +++++++++++-------- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/lib/Controller/AlbumsController.php b/lib/Controller/AlbumsController.php index 2172c8ca..abd5ce97 100644 --- a/lib/Controller/AlbumsController.php +++ b/lib/Controller/AlbumsController.php @@ -33,7 +33,7 @@ class AlbumsController extends ApiBase * * Get list of albums with counts of images */ - public function albums(): JSONResponse + public function albums(int $t = 0): JSONResponse { $user = $this->userSession->getUser(); if (null === $user) { @@ -47,7 +47,6 @@ class AlbumsController extends ApiBase // Run actual query $list = []; - $t = (int) $this->request->getParam('t'); if ($t & 1) { // personal $list = array_merge($list, $this->timelineQuery->getAlbums($user->getUID())); } diff --git a/lib/Controller/ImageController.php b/lib/Controller/ImageController.php index 919a445f..5c79a6a8 100644 --- a/lib/Controller/ImageController.php +++ b/lib/Controller/ImageController.php @@ -39,20 +39,22 @@ class ImageController extends ApiBase * * @param string fileid */ - public function info(string $id): JSONResponse - { + public function info( + string $id, + bool $basic = false, + bool $current = false + ): JSONResponse { $file = $this->getUserFile((int) $id); if (!$file) { return new JSONResponse([], Http::STATUS_NOT_FOUND); } // Get the image info - $basic = false !== $this->request->getParam('basic', false); $info = $this->timelineQuery->getInfoById($file->getId(), $basic); // Get latest exif data if requested // Allow this ony for logged in users - if ($this->request->getParam('current', false) && null !== $this->userSession->getUser()) { + if ($current && null !== $this->userSession->getUser()) { $info['current'] = Exif::getExifFromFile($file); } diff --git a/lib/Controller/TagsController.php b/lib/Controller/TagsController.php index c689253d..536ea07f 100644 --- a/lib/Controller/TagsController.php +++ b/lib/Controller/TagsController.php @@ -64,7 +64,7 @@ class TagsController extends ApiBase * * Get previews for a tag */ - public function previews(): JSONResponse + public function previews(string $tag = 'unknown'): JSONResponse { $user = $this->userSession->getUser(); if (null === $user) { @@ -82,12 +82,9 @@ class TagsController extends ApiBase return new JSONResponse([], Http::STATUS_NOT_FOUND); } - // Get the tag - $tagName = $this->request->getParam('tag'); - // Run actual query $list = $this->timelineQuery->getTagPreviews( - $tagName, + $tag, $root, ); diff --git a/lib/Controller/VideoController.php b/lib/Controller/VideoController.php index 7b66279b..941b5914 100644 --- a/lib/Controller/VideoController.php +++ b/lib/Controller/VideoController.php @@ -99,8 +99,13 @@ class VideoController extends ApiBase * * Return the live video part of a live photo */ - public function livephoto(string $fileid) - { + public function livephoto( + string $fileid, + string $etag = '', + string $liveid = '', + string $format = '', + string $transcode = '' + ) { $fileid = (int) $fileid; $files = $this->rootFolder->getById($fileid); if (0 === \count($files)) { @@ -109,13 +114,11 @@ class VideoController extends ApiBase $file = $files[0]; // Check file etag - $etag = $file->getEtag(); - if ($etag !== $this->request->getParam('etag')) { + if ($etag !== $file->getEtag()) { return new JSONResponse(['message' => 'File changed'], Http::STATUS_PRECONDITION_FAILED); } // Check file liveid - $liveid = $this->request->getParam('liveid'); if (!$liveid) { return new JSONResponse(['message' => 'Live ID not provided'], Http::STATUS_BAD_REQUEST); } @@ -163,7 +166,7 @@ class VideoController extends ApiBase if ($liveFile instanceof File) { // Requested only JSON info - if ('json' === $this->request->getParam('format')) { + if ('json' === $format) { return new JSONResponse($lp); } @@ -171,11 +174,11 @@ class VideoController extends ApiBase $blob = $liveFile->getContent(); $mime = $liveFile->getMimeType(); - if (($id = $this->request->getParam('transcode')) && !$this->config->getSystemValue('memories.no_transcode', true)) { + if ($transcode && !$this->config->getSystemValue('memories.no_transcode', true)) { // Only Apple uses HEVC for now, so pass this to the transcoder // If this is H.264 it won't get transcoded anyway $liveVideoPath = $liveFile->getStorage()->getLocalFile($liveFile->getInternalPath()); - if ($this->getUpstream($id, $liveVideoPath, 'max.mov')) { + if ($this->getUpstream($transcode, $liveVideoPath, 'max.mov')) { exit; } }