general: reduce more DI

cap
Varun Patil 2022-12-04 09:40:58 -08:00
parent 4c2bc5a675
commit 355b74e19b
8 changed files with 23 additions and 35 deletions

View File

@ -81,7 +81,7 @@ class Index extends Command
$this->config = $config; $this->config = $config;
$this->connection = $connection; $this->connection = $connection;
$this->connectionForSchema = $connectionForSchema; $this->connectionForSchema = $connectionForSchema;
$this->timelineWrite = new TimelineWrite($connection, $preview); $this->timelineWrite = new TimelineWrite($connection);
} }
protected function configure(): void protected function configure(): void

View File

@ -26,7 +26,6 @@ namespace OCA\Memories\Controller;
use OCA\Memories\AppInfo\Application; use OCA\Memories\AppInfo\Application;
use OCA\Memories\Db\TimelineQuery; use OCA\Memories\Db\TimelineQuery;
use OCA\Memories\Db\TimelineRoot; use OCA\Memories\Db\TimelineRoot;
use OCA\Memories\Db\TimelineWrite;
use OCA\Memories\Exif; use OCA\Memories\Exif;
use OCP\App\IAppManager; use OCP\App\IAppManager;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
@ -37,10 +36,8 @@ use OCP\Files\Folder;
use OCP\Files\IRootFolder; use OCP\Files\IRootFolder;
use OCP\IConfig; use OCP\IConfig;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IPreview;
use OCP\IRequest; use OCP\IRequest;
use OCP\IUserSession; use OCP\IUserSession;
use OCP\Share\IManager as IShareManager;
class ApiBase extends Controller class ApiBase extends Controller
{ {
@ -49,9 +46,6 @@ class ApiBase extends Controller
protected IRootFolder $rootFolder; protected IRootFolder $rootFolder;
protected IAppManager $appManager; protected IAppManager $appManager;
protected TimelineQuery $timelineQuery; protected TimelineQuery $timelineQuery;
protected TimelineWrite $timelineWrite;
protected IShareManager $shareManager;
protected IPreview $previewManager;
public function __construct( public function __construct(
IRequest $request, IRequest $request,
@ -59,9 +53,7 @@ class ApiBase extends Controller
IUserSession $userSession, IUserSession $userSession,
IDBConnection $connection, IDBConnection $connection,
IRootFolder $rootFolder, IRootFolder $rootFolder,
IAppManager $appManager, IAppManager $appManager
IShareManager $shareManager,
IPreview $preview
) { ) {
parent::__construct(Application::APPNAME, $request); parent::__construct(Application::APPNAME, $request);
@ -70,10 +62,7 @@ class ApiBase extends Controller
$this->connection = $connection; $this->connection = $connection;
$this->rootFolder = $rootFolder; $this->rootFolder = $rootFolder;
$this->appManager = $appManager; $this->appManager = $appManager;
$this->shareManager = $shareManager;
$this->previewManager = $preview;
$this->timelineQuery = new TimelineQuery($connection); $this->timelineQuery = new TimelineQuery($connection);
$this->timelineWrite = new TimelineWrite($connection, $preview);
} }
/** Get logged in user's UID or throw HTTP error */ /** Get logged in user's UID or throw HTTP error */
@ -243,14 +232,15 @@ class ApiBase extends Controller
} }
// Get share by token // Get share by token
$share = $this->shareManager->getShareByToken($token); $share = \OC::$server->getShareManager()->getShareByToken($token);
if (!PublicController::validateShare($share)) { if (!PublicController::validateShare($share)) {
return null; return null;
} }
// Check if share is password protected // Check if share is password protected
$session = \OC::$server->getSession();
if (($password = $share->getPassword()) !== null) { if (($password = $share->getPassword()) !== null) {
$session = \OC::$server->getSession();
// https://github.com/nextcloud/server/blob/0447b53bda9fe95ea0cbed765aa332584605d652/lib/public/AppFramework/PublicShareController.php#L119 // https://github.com/nextcloud/server/blob/0447b53bda9fe95ea0cbed765aa332584605d652/lib/public/AppFramework/PublicShareController.php#L119
if ($session->get('public_link_authenticated_token') !== $token if ($session->get('public_link_authenticated_token') !== $token
|| $session->get('public_link_authenticated_password_hash') !== $password) { || $session->get('public_link_authenticated_password_hash') !== $password) {

View File

@ -121,7 +121,7 @@ class DaysController extends ApiBase
// Convert to actual dayIds if month view // Convert to actual dayIds if month view
if ($this->isMonthView()) { if ($this->isMonthView()) {
$dayIds = $this->timelineQuery->monthIdToDayIds($dayIds[0]); $dayIds = $this->timelineQuery->monthIdToDayIds((int) $dayIds[0]);
} }
// Run actual query // Run actual query

View File

@ -95,6 +95,9 @@ class FacesController extends ApiBase
return new DataResponse([], Http::STATUS_NOT_FOUND); return new DataResponse([], Http::STATUS_NOT_FOUND);
} }
// Get preview manager
$previewManager = \OC::$server->getPreviewManager();
// Find the first detection that has a preview // Find the first detection that has a preview
/** @var \Imagick */ /** @var \Imagick */
$image = null; $image = null;
@ -113,7 +116,7 @@ class FacesController extends ApiBase
// Get (hopefully cached) preview image // Get (hopefully cached) preview image
try { try {
$preview = $this->previewManager->getPreview($files[0], 2048, 2048, false); $preview = $previewManager->getPreview($files[0], 2048, 2048, false);
$image = new \Imagick(); $image = new \Imagick();
if (!$image->readImageBlob($preview->getContent())) { if (!$image->readImageBlob($preview->getContent())) {

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace OCA\Memories\Controller; namespace OCA\Memories\Controller;
use OCA\Memories\AppInfo\Application; use OCA\Memories\AppInfo\Application;
use OCA\Memories\Db\TimelineWrite;
use OCA\Memories\Exif; use OCA\Memories\Exif;
use OCP\AppFramework\Http; use OCP\AppFramework\Http;
use OCP\AppFramework\Http\FileDisplayResponse; use OCP\AppFramework\Http\FileDisplayResponse;
@ -61,9 +62,9 @@ class ImageController extends ApiBase
} }
try { try {
$f = $this->previewManager->getPreview($file, $x, $y, !$a, $mode); $preview = \OC::$server->getPreviewManager()->getPreview($file, $x, $y, !$a, $mode);
$response = new FileDisplayResponse($f, Http::STATUS_OK, [ $response = new FileDisplayResponse($preview, Http::STATUS_OK, [
'Content-Type' => $f->getMimeType(), 'Content-Type' => $preview->getMimeType(),
]); ]);
$response->cacheFor(3600 * 24, false, true); $response->cacheFor(3600 * 24, false, true);
@ -146,7 +147,8 @@ class ImageController extends ApiBase
} }
// Reprocess the file // Reprocess the file
$this->timelineWrite->processFile($file, true); $timelineWrite = new TimelineWrite($this->connection);
$timelineWrite->processFile($file, true);
return new JSONResponse([], Http::STATUS_OK); return new JSONResponse([], Http::STATUS_OK);
} }

View File

@ -17,10 +17,10 @@ class TimelineWrite
protected IPreview $preview; protected IPreview $preview;
protected LivePhoto $livePhoto; protected LivePhoto $livePhoto;
public function __construct(IDBConnection $connection, IPreview &$preview) public function __construct(IDBConnection $connection)
{ {
$this->connection = $connection; $this->connection = $connection;
$this->preview = $preview; $this->preview = \OC::$server->getPreviewManager();
$this->livePhoto = new LivePhoto($connection); $this->livePhoto = new LivePhoto($connection);
} }

View File

@ -27,15 +27,14 @@ use OCP\EventDispatcher\IEventListener;
use OCP\Files\Events\Node\NodeDeletedEvent; use OCP\Files\Events\Node\NodeDeletedEvent;
use OCP\Files\Folder; use OCP\Files\Folder;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IPreview;
class PostDeleteListener implements IEventListener class PostDeleteListener implements IEventListener
{ {
private TimelineWrite $util; private TimelineWrite $util;
public function __construct(IDBConnection $connection, IPreview $preview) public function __construct(IDBConnection $connection)
{ {
$this->util = new TimelineWrite($connection, $preview); $this->util = new TimelineWrite($connection);
} }
public function handle(Event $event): void public function handle(Event $event): void

View File

@ -28,20 +28,14 @@ use OCP\Files\Events\Node\NodeTouchedEvent;
use OCP\Files\Events\Node\NodeWrittenEvent; use OCP\Files\Events\Node\NodeWrittenEvent;
use OCP\Files\Folder; use OCP\Files\Folder;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IPreview;
use OCP\IUserManager;
class PostWriteListener implements IEventListener class PostWriteListener implements IEventListener
{ {
private TimelineWrite $timelineWrite; private TimelineWrite $timelineWrite;
public function __construct( public function __construct(IDBConnection $connection)
IDBConnection $connection, {
IUserManager $userManager, $this->timelineWrite = new TimelineWrite($connection);
IPreview $preview
) {
$this->userManager = $userManager;
$this->timelineWrite = new TimelineWrite($connection, $preview);
} }
public function handle(Event $event): void public function handle(Event $event): void