Initial commit
This commit is contained in:
commit
ff7217c38c
9 changed files with 1019 additions and 0 deletions
81
lib/Controller/PrinterController.php
Normal file
81
lib/Controller/PrinterController.php
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
namespace OCA\Printer\Controller;
|
||||
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\IRequest;
|
||||
use OC\Files\Filesystem;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
|
||||
|
||||
class PrinterController extends Controller {
|
||||
|
||||
protected $language;
|
||||
|
||||
public function __construct($appName, IRequest $request) {
|
||||
|
||||
parent::__construct($appName, $request);
|
||||
|
||||
// get i10n
|
||||
$this->language = \OC::$server->getL10N('printer');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* callback function to get md5 hash of a file
|
||||
* @NoAdminRequired
|
||||
* @param (string) $source - filename
|
||||
* @param (string) $orientation - Orientation of printed file
|
||||
*/
|
||||
public function printfile($source, $orientation) {
|
||||
if(!$this->checkAlgorithmType($type)) {
|
||||
return new JSONResponse(
|
||||
array(
|
||||
'response' => 'error',
|
||||
'msg' => $this->language->t('Print failed!')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if($hash = $this->getHash($source, $type)){
|
||||
return new JSONResponse(
|
||||
array(
|
||||
'response' => 'success',
|
||||
'msg' => $this->language->t('Print succeeded!')
|
||||
)
|
||||
);
|
||||
} else {
|
||||
return new JSONResponse(
|
||||
array(
|
||||
'response' => 'error',
|
||||
'msg' => $this->language->t('File to print not found.')
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
protected function getHash($source, $type) {
|
||||
|
||||
if($info = Filesystem::getLocalFile($source)) {
|
||||
return hash_file($type, $info);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function checkAlgorithmType($type) {
|
||||
$list_algos = hash_algos();
|
||||
return in_array($type, $this->getAllowedAlgorithmTypes()) && in_array($type, $list_algos);
|
||||
}
|
||||
|
||||
protected function getAllowedAlgorithmTypes() {
|
||||
return array(
|
||||
'md5',
|
||||
'sha1',
|
||||
'sha256',
|
||||
'sha384',
|
||||
'sha512',
|
||||
'crc32'
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue