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
diff options
context:
space:
mode:
authorSebastian Sauer <sauer.sebastian@gmail.com>2015-07-15 21:46:49 +0300
committerSebastian Sauer <sauer.sebastian@gmail.com>2015-07-15 21:50:46 +0300
commite17c95919a50b548d0568d6542eabdade78806e0 (patch)
treea055dc141011558ed0d5cf5c8b796beda979ba70
parentdd5fbb63b37c9863c806a32f9e39719194bc5b97 (diff)
Compatibility with Owncloud 8.1.
Create an API Controller that provides REST-API. Fix JavaScript code.
-rw-r--r--ajax/checksum.php18
-rw-r--r--appinfo/app.php2
-rw-r--r--appinfo/routes.php6
-rw-r--r--appinfo/version2
-rw-r--r--controller/checksumcontroller.php27
-rw-r--r--js/checksum.js15
6 files changed, 46 insertions, 24 deletions
diff --git a/ajax/checksum.php b/ajax/checksum.php
deleted file mode 100644
index fab7692..0000000
--- a/ajax/checksum.php
+++ /dev/null
@@ -1,18 +0,0 @@
-<?php
-// chech if app is enabled
-OCP\JSON::checkAppEnabled('checksum');
-OCP\JSON::checkLoggedIn();
-OCP\JSON::callCheck();
-
-// get file
-$source = $_GET['source'];
-$dir = $_GET['dir'];
-$file = $dir.$source;
-if($info = \OC\Files\Filesystem::getLocalFile($file)){
- $md5 = md5_file($info);
- OCP\JSON::success(array('data' => array($md5)));
-} else {
- OCP\JSON::error(array('data' => array('An Error occured.')));
-};
-
-
diff --git a/appinfo/app.php b/appinfo/app.php
index 63a53ef..5bea808 100644
--- a/appinfo/app.php
+++ b/appinfo/app.php
@@ -3,6 +3,6 @@
* Dependencies
*/
// Jquery
-OCP\Util::addScript("3rdparty", "chosen/chosen.jquery.min");
+//OCP\Util::addScript("3rdparty", "chosen/chosen.jquery.min");
// checksum script
OCP\Util::addScript('checksum', "checksum" );
diff --git a/appinfo/routes.php b/appinfo/routes.php
new file mode 100644
index 0000000..81cb5a4
--- /dev/null
+++ b/appinfo/routes.php
@@ -0,0 +1,6 @@
+<?php
+return ['routes' => [
+ ['name' => 'checksum#calculate', 'url' => '/checksum', 'verb' => 'GET']
+]];
+
+?>
diff --git a/appinfo/version b/appinfo/version
index be12806..3b04cfb 100644
--- a/appinfo/version
+++ b/appinfo/version
@@ -1 +1 @@
-0.1a
+0.2
diff --git a/controller/checksumcontroller.php b/controller/checksumcontroller.php
new file mode 100644
index 0000000..9ac71c5
--- /dev/null
+++ b/controller/checksumcontroller.php
@@ -0,0 +1,27 @@
+<?php
+ namespace OCA\Checksum\Controller;
+ use OCP\IRequest;
+ use OCP\AppFramework\Http\JSONResponse;
+ use OCP\AppFramework\ApiController;
+
+ class ChecksumController extends ApiController {
+
+ public function __construct($AppName, IRequest $request){
+ parent::__construct($AppName, $request);
+ }
+ /**
+ * @NoAdminRequired
+ */
+ public function calculate($source, $dir) {
+ $file = $dir.$source;
+
+ if($info = \OC\Files\Filesystem::getLocalFile($file)){
+ $md5 = md5_file($info);
+
+ return new JSONResponse(array("checksum" => $md5));
+ } else {
+ return new JSONResponse(array("error" => "File not found."));
+ };
+ }
+ }
+?>
diff --git a/js/checksum.js b/js/checksum.js
index ce8bdb9..042b7b9 100644
--- a/js/checksum.js
+++ b/js/checksum.js
@@ -12,7 +12,12 @@
};
},
check: function(file) {
- dom = this.elem.find('.action[data-action=checksum]');
+ var elem = this.elem;
+ if(!elem){
+ elem = this.currentFile;
+ }
+
+ dom = elem.find('.action[data-action=checksum]');
if(!dom.hasClass('chcksum-hashed')) {
dom.html(checksum.load);
dom.addClass('checksum-hashing');
@@ -23,16 +28,18 @@
},
load: 'Creating MD5 Checksum <img src="'+OC.imagePath('core','loading.gif')+'">',
ajax: function(file) {
+
+ var url = OC.generateUrl('/apps/checksum/checksum');
var data = {source: file, dir: $('#dir').val()+'/'};
$.ajax({
type: 'GET',
- url: OC.filePath('checksum', 'ajax', 'checksum.php'),
+ url: url,
dataType: 'json',
data: data,
- async: false,
+ async: true,
success: function(info) {
dom = $('.checksum-hashing').first();
- dom.text('MD5: '+info.data[0]);
+ dom.text('MD5: '+info.checksum);
dom.addClass('chcksum-hashed');
dom.removeClass('checksum-hashing');
}