This commit is contained in:
Jonas Köritz 2021-01-26 13:16:48 -05:00 committed by GitHub
commit d617bbe502
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 84 additions and 5 deletions

10
.gitlab-ci.yml Normal file
View File

@ -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

View File

@ -186,7 +186,7 @@
*/
"info": {
"enabled": true,
"show": false,
"show": true,
"qrcode": true,
"qrFill": "#999",
"qrBack": "#fff"
@ -328,6 +328,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.

View File

@ -34,6 +34,7 @@ class Item {
public $href;
public $date;
public $size;
public $sha1;
public $is_folder;
public $is_content_fetched;
@ -45,6 +46,7 @@ class Item {
$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 @@ class Item {
$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) {

View File

@ -0,0 +1,34 @@
<?php
class SHA1 {
private static $cache = [];
public static function getHash($path) {
$sha1 = new SHA1();
return $sha1->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;
}
}

View File

@ -86,4 +86,13 @@ class Util {
$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;
}
}
}

View File

@ -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 {

View File

@ -20,6 +20,7 @@ const tpl =
<div class="label"></div>
<div class="time"></div>
<div class="size"></div>
<div class="sha1"></div>
<div class="content">
<span class="folders"></span> <span class="l10n-folders"></span>,
<span class="files"></span> <span class="l10n-files"></span>
@ -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');

View File

@ -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: {}