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:
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
parent0eb7cf254ffacebe4d18540fa9e77969895e3729 (diff)
Updated app for owncloud version 9.v9.x
-rw-r--r--README.md8
-rw-r--r--appinfo/app.php15
-rw-r--r--appinfo/info.xml9
-rw-r--r--appinfo/routes.php9
-rw-r--r--appinfo/version1
-rw-r--r--controller/checksumcontroller.php27
-rw-r--r--js/checksum.js50
-rw-r--r--js/checksum.plugin.js27
-rw-r--r--js/checksum.tabview.js89
-rw-r--r--lib/Controller/ChecksumController.php58
10 files changed, 201 insertions, 92 deletions
diff --git a/README.md b/README.md
index bc5af71..8a46e61 100644
--- a/README.md
+++ b/README.md
@@ -15,4 +15,10 @@ Installation
Usage
-----
-An info-icon appears on every file. Click it, to get the md5-hash.
+Open the details view. There should be a new tab called "Checksum". By opening the tab it will generate a md5 hash for you.
+
+
+Notice
+------
+
+I only tested the app for the current version of owncloud (9.x). I tried to use the current api as much as possible. It should be safe for future versions. \ No newline at end of file
diff --git a/appinfo/app.php b/appinfo/app.php
index 5bea808..10e3c7e 100644
--- a/appinfo/app.php
+++ b/appinfo/app.php
@@ -1,8 +1,13 @@
<?php
/**
- * Dependencies
+ * Load Javascrip
*/
-// Jquery
-//OCP\Util::addScript("3rdparty", "chosen/chosen.jquery.min");
-// checksum script
-OCP\Util::addScript('checksum', "checksum" );
+
+use OCP\Util;
+
+$eventDispatcher = \OC::$server->getEventDispatcher();
+$eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', function(){
+ Util::addScript('checksum', 'checksum.tabview' );
+ Util::addScript('checksum', 'checksum.plugin' );
+});
+
diff --git a/appinfo/info.xml b/appinfo/info.xml
index 7345471..61cb56f 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -3,12 +3,13 @@
<id>checksum</id>
<name>Checksum</name>
<description>Creating a md5 checksum of a file.</description>
- <version>1.0</version>
+ <version>0.2</version>
<licence>AGPL</licence>
<author>westberliner</author>
- <require>5</require>
<types>
<filesystem/>
</types>
- <version>0.1.1</version>
-</info>
+ <dependencies>
+ <owncloud min-version="9.0" max-version="11" />
+ </dependencies>
+</info> \ No newline at end of file
diff --git a/appinfo/routes.php b/appinfo/routes.php
index 81cb5a4..1359b9c 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -1,6 +1,7 @@
<?php
+/**
+ * adding route for ajax callback
+ */
return ['routes' => [
- ['name' => 'checksum#calculate', 'url' => '/checksum', 'verb' => 'GET']
-]];
-
-?>
+ ['name' => 'checksum#check', 'url' => '/check', 'verb' => 'GET']
+]]; \ No newline at end of file
diff --git a/appinfo/version b/appinfo/version
deleted file mode 100644
index 3b04cfb..0000000
--- a/appinfo/version
+++ /dev/null
@@ -1 +0,0 @@
-0.2
diff --git a/controller/checksumcontroller.php b/controller/checksumcontroller.php
deleted file mode 100644
index 9ac71c5..0000000
--- a/controller/checksumcontroller.php
+++ /dev/null
@@ -1,27 +0,0 @@
-<?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
deleted file mode 100644
index 042b7b9..0000000
--- a/js/checksum.js
+++ /dev/null
@@ -1,50 +0,0 @@
-(function($){
- var checksum = {
- init: function() {
- if (typeof FileActions !== 'undefined') {
- FileActions.register(
- 'all',
- t('checksum','checksum'),
- OC.PERMISSION_READ,
- OC.imagePath('core','actions/info'),
- checksum.check
- );
- };
- },
- check: function(file) {
- 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');
- checksum.ajax(file);
- } else {
- alert(dom.html());
- }
- },
- 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: url,
- dataType: 'json',
- data: data,
- async: true,
- success: function(info) {
- dom = $('.checksum-hashing').first();
- dom.text('MD5: '+info.checksum);
- dom.addClass('chcksum-hashed');
- dom.removeClass('checksum-hashing');
- }
- });
- }
- }
- $(document).ready(checksum.init);
-})(jQuery)
diff --git a/js/checksum.plugin.js b/js/checksum.plugin.js
new file mode 100644
index 0000000..77c41ff
--- /dev/null
+++ b/js/checksum.plugin.js
@@ -0,0 +1,27 @@
+(function() {
+
+ OCA.Checksum = OCA.Checksum || {};
+
+ /**
+ * @namespace
+ */
+ OCA.Checksum.Util = {
+
+ /**
+ * Initialize the Checksum plugin.
+ *
+ * @param {OCA.Files.FileList} fileList file list to be extended
+ */
+ attach: function(fileList) {
+
+ if (fileList.id === 'trashbin' || fileList.id === 'files.public') {
+ return;
+ }
+
+ fileList.registerTabView(new OCA.Checksum.ChecksumTabView('checksumTabView', {}));
+
+ }
+ };
+})();
+
+OC.Plugins.register('OCA.Files.FileList', OCA.Checksum.Util);
diff --git a/js/checksum.tabview.js b/js/checksum.tabview.js
new file mode 100644
index 0000000..4c349df
--- /dev/null
+++ b/js/checksum.tabview.js
@@ -0,0 +1,89 @@
+(function() {
+
+ var ChecksumTabView = OCA.Files.DetailTabView.extend({
+
+ id: 'checksumTabView',
+ className: 'tab checksumTabView',
+
+ /**
+ * get label of tab
+ */
+ getLabel: function() {
+
+ return t('checksum', 'Checksum');
+
+ },
+
+ /**
+ * Renders this details view
+ *
+ * @abstract
+ */
+ render: function() {
+
+ this.$el.html('<div style="text-align:center;" class="get-md5"><p><img src="'
+ + OC.imagePath('core','loading.gif')
+ + '"><br><br></p><p>'
+ + t('checksum', 'Creating MD5 Checksum ...')
+ + '</p></div>');
+ this.check(this.getFileInfo());
+
+ },
+
+ /**
+ * show tab only on files
+ */
+ canDisplay: function(fileInfo) {
+
+ if(fileInfo != null) {
+ if(!fileInfo.isDirectory()) {
+ return true;
+ }
+ }
+ return false;
+
+ },
+
+ /**
+ * ajax callback for generating md5 hash
+ */
+ check: function(fileInfo) {
+
+ var url = OC.generateUrl('/apps/checksum/check'),
+ data = {source: fileInfo.getFullPath()},
+ _self = this;
+ $.ajax({
+ type: 'GET',
+ url: url,
+ dataType: 'json',
+ data: data,
+ async: true,
+ success: function(data) {
+ _self.updateDisplay(data);
+ }
+ });
+
+ },
+
+ /**
+ * display message from ajax callback
+ */
+ updateDisplay: function(data) {
+
+ var msg = '';
+ if('success' == data.response) {
+ msg = 'MD5: ' + data.msg;
+ }
+ if('error' == data.response) {
+ msg = data.msg;
+ }
+ this.$el.find('.get-md5').html(msg);
+ }
+
+ });
+
+ OCA.Checksum = OCA.Checksum || {};
+
+ OCA.Checksum.ChecksumTabView = ChecksumTabView;
+
+})(); \ No newline at end of file
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;
+ }
+
+}
+