From f4203dafaaeb85c9db2bc374af04531f4334ca91 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Mon, 21 Mar 2022 15:02:08 +0100 Subject: [PATCH] use file size function from tools.sh --- macros/attachments | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/macros/attachments b/macros/attachments index 7acc806..428e770 100755 --- a/macros/attachments +++ b/macros/attachments @@ -1,6 +1,7 @@ #!/bin/sh . "$_EXEC/cgilite/cgilite.sh" +. "$_EXEC/tools.sh" page="$1" @@ -16,25 +17,9 @@ for file in "$_EXEC/pages/$page/#attachments"/* "$_DATA/pages/$page/#attachments stat="$(stat -c '%s %Y' -- "$file" 2>&-)" || continue size="${stat% *}" date="${stat#* }" - if [ $size -gt $((1024 * 1024 * 1024)) ]; then - size=$((size / 1024 / 1024 / 1024 * 10 + size / 1024 / 1024 % 1024 / 100)) - size="$((size / 10)).$((size % 10)) GB" - - elif [ $size -gt $((1024 * 1024)) ]; then - size=$((size / 1024 / 1024 * 10 + size / 1024 % 1024 / 100)) - size="$((size / 10)).$((size % 10)) MB" - - elif [ $size -gt $((1024)) ]; then - size=$((size / 1024 * 10 + size % 1024 / 100)) - size="$((size / 10)).$((size % 10)) KB" - - else - size="${size} B" - fi - printf '
  • %s %s%s
  • ' \ - "$(HTML "${file##*/}")" "$size" "$(date -d @"$date" +"%F %T")" + "$(HTML "${file##*/}")" "$(size_human "$size")" "$(date -d @"$date" +"%F %T")" done printf %s\\n '' -- 2.39.2