language = \OC::$server->getL10N('printer'); $this->printer = $printer; $this->config = $config; } /** * @NoAdminRequired */ public function printfile(string $sourcefile, string $orientation): JSONResponse { $file = \OC\Files\Filesystem::getLocalFile($sourcefile); $success = [ 'response' => 'success', 'msg' => $this->language->t('Print succeeded!'), ]; $error = [ 'response' => 'error', 'msg' => $this->language->t('Print failed'), ]; $notAllowed = [ 'response' => 'error', 'msg' => $this->language->t('User not allowed'), ]; $user = \OC::$server[IUserSession::class]->getUser(); if (!$user || $this->config->isDisabledForUser($user)) { return new JSONResponse($notAllowed); } if (!$this->printer->isValidOrientation($orientation)) { return new JSONResponse($error); } try { $this->printer->print($file, $orientation); return new JSONResponse($success); } catch (ProcessFailedException $exception) { return new JSONResponse($error); } } }