Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Put services in the constructor, do callings in the methods
Signed-off-by: Frederic Ruget <[email protected]>
  • Loading branch information
douzebis authored and CarlSchwan committed Sep 1, 2022
commit f392c41a73bc00e7e5d6c8972da2e79c13750f10
34 changes: 19 additions & 15 deletions lib/Controller/VideoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,29 @@
use OCP\Files\IRootFolder;
use OCP\IUserSession;

use OCA\Viewer\AppInfo\Application;

class VideoController extends Controller {

// I copied the annotation below without understanding it... is it useful?
/** @var IRootFolder */
private $storage;
private $rootFolder;

// I copied the annotation below without understanding it... is it useful?
/** @var array */
private $locales;
/** @var IFactory */
private $l10nFactory;

/** @var IUserSession */
private $userSession;

public function __construct(
string $AppName,
IRequest $request,
IRootFolder $storage,
IFactory $factory,
IRootFolder $rootFolder,
IFactory $l10nFactory,
IUserSession $userSession
){
parent::__construct($AppName, $request);
$this->storage = $storage;
$this->locales = $factory->findAvailableLocales();;
$this->currentUser = $userSession->getUser();
parent::__construct(Application::APP_ID, $request);
$this->rootFolder = $rootFolder;
$this->l10nFactory = $l10nFactory;
$this->userSession = $userSession;
}

// I copied the annotation below without understanding it... is it useful?
Expand All @@ -70,7 +72,8 @@ public function getTracks($videoPath): DataResponse {
// - language /* language for the track */
// - locale /* (usuallu) 2-letter code for the language */
//
$video = $this->storage->getUserFolder($this->currentUser->getUID())
$video = $this->rootFolder
->getUserFolder($this->userSession->getUser()->getUID())
->get($videoPath);
$rootName = pathinfo($video->getFileInfo()->getPath())['filename'];
$rootLen = strlen($rootName);
Expand All @@ -88,10 +91,11 @@ public function getTracks($videoPath): DataResponse {
$extension = substr($baseName, $rootPos + $rootLen);
// eg: $extension is '.en.vtt'
$pattern = "/^[.]([^.]+)[.]vtt$/";
$locales = $this->l10nFactory->findAvailableLocales();
if (preg_match($pattern, $extension)) {
$locale = preg_replace($pattern, "$1", $extension);
$key = array_search($locale, array_column($this->locales, 'code'));
$language = $key ? $this->locales[$key]['name'] : $locale;
$key = array_search($locale, array_column($locales, 'code'));
$language = $key ? $locales[$key]['name'] : $locale;
array_push($res, [
basename => $baseName,
language => $language, // eg: 'English'
Expand Down