Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/westberliner/checksum.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPatrick <patrick@westberliner.net>2016-10-22 16:26:37 +0300
committerPatrick <patrick@westberliner.net>2016-10-22 16:26:37 +0300
commit58080ba7aa61111161ad4c08d1b5b8b5015d2a3e (patch)
tree124a5d8b8b565dee78f63b0b883f990147f7a2ed /lib
parent0eb7cf254ffacebe4d18540fa9e77969895e3729 (diff)
Updated app for owncloud version 9.v9.x
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/ChecksumController.php58
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/Controller/ChecksumController.php b/lib/Controller/ChecksumController.php
new file mode 100644
index 0000000..34e308e
--- /dev/null
+++ b/lib/Controller/ChecksumController.php
@@ -0,0 +1,58 @@
+<?php
+namespace OCA\Checksum\Controller;
+
+use OCP\AppFramework\Controller;
+use OCP\IRequest;
+use OC\Files\Filesystem;
+use OCP\AppFramework\Http\JSONResponse;
+
+
+class ChecksumController extends Controller {
+
+ protected $language;
+
+ public function __construct($appName, IRequest $request) {
+
+ parent::__construct($appName, $request);
+
+ // get i10n
+ $this->language = \OC::$server->getL10N('checksum');
+
+ }
+
+ /**
+ * callback function to get md5 hash of a file
+ * @param (string) $source - filename
+ * @param (string) $dir - folder to file
+ */
+ public function check($source) {
+
+ if($md5 = $this->getHash($source)){
+ return new JSONResponse(
+ array(
+ 'response' => 'success',
+ 'msg' => $md5
+ )
+ );
+ } else {
+ return new JSONResponse(
+ array(
+ 'response' => 'error',
+ 'msg' => $this->language->t('File not found.')
+ )
+ );
+ };
+
+ }
+
+ protected function getHash($source) {
+
+ if($info = Filesystem::getLocalFile($source)) {
+ return md5_file($info);
+ }
+
+ return false;
+ }
+
+}
+