diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 000000000..2e2e7d9c3 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,10 @@ +build_and_deploy: + stage: build + script: + - npm install + - npm run build + - git log --oneline --decorate > ./build/_h5ai/CHANGELOG.txt + - cd ./build/ + - rm h5ai-*.zip + - scp -r . root@dose.rsc.lan:/var/www/ + environment: staging \ No newline at end of file diff --git a/src/_h5ai/private/conf/options.json b/src/_h5ai/private/conf/options.json index 1ec53edc0..6c9af0755 100644 --- a/src/_h5ai/private/conf/options.json +++ b/src/_h5ai/private/conf/options.json @@ -181,7 +181,7 @@ */ "info": { "enabled": true, - "show": false, + "show": true, "qrcode": true, "qrFill": "#999", "qrBack": "#fff" @@ -323,6 +323,14 @@ "checkboxes": true }, + /* + Calc the SHA-1 checksum of files. + This operation is real slow for large files. + */ + "sha1": { + "enabled": true + }, + /* Default sort order. "column" and "reverse" are locally stored. diff --git a/src/_h5ai/private/php/core/class-item.php b/src/_h5ai/private/php/core/class-item.php index 2b9ce3486..a52c091b3 100644 --- a/src/_h5ai/private/php/core/class-item.php +++ b/src/_h5ai/private/php/core/class-item.php @@ -34,6 +34,7 @@ public static function get($context, $path, &$cache) { public $href; public $date; public $size; + public $sha1; public $is_folder; public $is_content_fetched; @@ -45,6 +46,7 @@ private function __construct($context, $path) { $this->href = $context->to_href($this->path, $this->is_folder); $this->date = @filemtime($this->path); $this->size = Util::filesize($context, $this->path); + $this->sha1 = Util::sha1($context, $this->path); $this->is_content_fetched = false; } @@ -52,7 +54,8 @@ public function to_json_object() { $obj = [ 'href' => $this->href, 'time' => $this->date * 1000, // seconds (PHP) to milliseconds (JavaScript) - 'size' => $this->size + 'size' => $this->size, + 'sha1' => $this->sha1 ]; if ($this->is_folder) { diff --git a/src/_h5ai/private/php/core/class-sha1.php b/src/_h5ai/private/php/core/class-sha1.php new file mode 100644 index 000000000..3b3019a1b --- /dev/null +++ b/src/_h5ai/private/php/core/class-sha1.php @@ -0,0 +1,34 @@ +hash($path); + } + + public static function getCachedHash($path, $clear_cache = false) { + if (array_key_exists($path, SHA1::$cache) && !$clear_cache) { + return SHA1::$cache[$path]; + } + + $hash = SHA1::getHash($path, $clear_cache); + + SHA1::$cache[$path] = $hash; + return $hash; + } + + + private function __construct() { + + } + + private function hash($path) { + if (is_file($path)) { + return sha1_file($path); + } + + return null; + } +} diff --git a/src/_h5ai/private/php/core/class-util.php b/src/_h5ai/private/php/core/class-util.php index ce6c80295..ae4f11581 100644 --- a/src/_h5ai/private/php/core/class-util.php +++ b/src/_h5ai/private/php/core/class-util.php @@ -86,4 +86,13 @@ public static function filesize($context, $path) { $withDu = $context->get_setup()->get('HAS_CMD_DU') && $context->query_option('foldersize.type', null) === 'shell-du'; return Filesize::getCachedSize($path, $withFoldersize, $withDu); } + + public static function sha1($context, $path, $clear_cache = false) { + $sha1Enabled = $context->query_option('sha1.enabled', false); + if($sha1Enabled) { + return SHA1::getCachedHash($path, $clear_cache); + } else { + return null; + } + } } diff --git a/src/_h5ai/public/css/lib/ext/info.less b/src/_h5ai/public/css/lib/ext/info.less index cc8d7e56d..8ed167417 100644 --- a/src/_h5ai/public/css/lib/ext/info.less +++ b/src/_h5ai/public/css/lib/ext/info.less @@ -3,13 +3,12 @@ flex: 0 0 auto; order: 99; - padding: 32px 32px 32px 48px; + padding: 32px; white-space: nowrap; overflow-x: hidden; - width: 240px; + width: 320px; .icon { - width: 240px; height: 180px; img { diff --git a/src/_h5ai/public/js/lib/ext/info.js b/src/_h5ai/public/js/lib/ext/info.js index 85f9b0f35..b5527bb22 100644 --- a/src/_h5ai/public/js/lib/ext/info.js +++ b/src/_h5ai/public/js/lib/ext/info.js @@ -20,6 +20,7 @@ const tpl =
+
, @@ -39,6 +40,7 @@ let $img; let $label; let $time; let $size; +let $sha1; let $content; let $folders; let $files; @@ -85,6 +87,13 @@ const update = item => { $size.hide(); } + if(item.sha1) { + $sha1.text(item.sha1 + ' (SHA-1)'); + $sha1.show(); + } else { + $sha1.hide(); + } + if (item.isContentFetched) { const stats = item.getStats(); $folders.text(stats.folders); @@ -131,6 +140,7 @@ const init = () => { $label = $info.find('.label'); $time = $info.find('.time'); $size = $info.find('.size'); + $sha1 = $info.find('.sha1'); $content = $info.find('.content'); $folders = $info.find('.folders'); $files = $info.find('.files'); diff --git a/src/_h5ai/public/js/lib/model/item.js b/src/_h5ai/public/js/lib/model/item.js index 3d725b16c..a0491cd23 100644 --- a/src/_h5ai/public/js/lib/model/item.js +++ b/src/_h5ai/public/js/lib/model/item.js @@ -64,6 +64,11 @@ const getItem = options => { if (isNum(options.size)) { item.size = options.size; } + + if(options.sha1) { + item.sha1 = options.sha1; + } + if (options.managed) { item.isManaged = true; } @@ -120,6 +125,7 @@ const Item = absHref => { label: createLabel(absHref === '/' ? location.getDomain() : split.name), time: null, size: null, + sha1: null, parent: null, isManaged: null, content: {}