X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;f=macros%2Fattachments;h=0a49075a74afaa001de2eb0b1daeb118ce5c11fb;hb=c6cb47f6bf0415592ccd04e8fb6ccf5d804cab3d;hp=7acc8063b32af36fa84db64f40d89e6367ca1460;hpb=df5a47a0b129485391d78ca5622b89702fdf57f3;p=shellwiki
diff --git a/macros/attachments b/macros/attachments
index 7acc806..0a49075 100755
--- a/macros/attachments
+++ b/macros/attachments
@@ -1,6 +1,7 @@
#!/bin/sh
. "$_EXEC/cgilite/cgilite.sh"
+. "$_EXEC/tools.sh"
page="$1"
@@ -8,7 +9,7 @@ if [ "${page#/}" = "$page" ]; then
page="$(PATH "${PATH_INFO}/$page")"
fi
-printf %s\\n '
'
+printf %s\\n ''
for file in "$_EXEC/pages/$page/#attachments"/* "$_DATA/pages/$page/#attachments"/*; do
[ "$file" = "$_EXEC/pages/$page/#attachments/${file##*/}" \
@@ -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 '
'