]> git.plutz.net Git - shellwiki/blobdiff - macros/attachments
Merge commit '6bc502434737d7f08379e79b94fc6fda424ef779'
[shellwiki] / macros / attachments
index 7acc8063b32af36fa84db64f40d89e6367ca1460..3a75f8687524113896520f5a09a082a36ee7cd12 100755 (executable)
@@ -1,6 +1,22 @@
 #!/bin/sh
 
+# Copyright 2022 Paul Hänsch
+# 
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+# 
+# THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+# IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
 . "$_EXEC/cgilite/cgilite.sh"
+. "$_EXEC/acl.sh"
+. "$_EXEC/tools.sh"
 
 page="$1"
 
@@ -8,7 +24,9 @@ if [ "${page#/}" = "$page" ]; then
   page="$(PATH "${PATH_INFO}/$page")"
 fi
 
-printf %s\\n '<ul class="attachment list">'
+acl_read "$page" || exit 0
+
+printf %s\\n '<ul class="macro attachment list">'
 
 for file in "$_EXEC/pages/$page/#attachments"/* "$_DATA/pages/$page/#attachments"/*; do
   [ "$file" = "$_EXEC/pages/$page/#attachments/${file##*/}" \
@@ -16,25 +34,10 @@ 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 '<li><span class=name>%s</span>
+  printf '<li><a class=name href="[attachment]/%s">%s</a>
           <span class=size>%s</span><span class=date>%s</span></li>' \
-    "$(HTML "${file##*/}")" "$size" "$(date -d @"$date" +"%F %T")"
+    "$(HTML "${file##*/}")" "$(HTML "${file##*/}")" \
+    "$(size_human "$size")" "$(date -d @"$date" +"%F %T")"
 done
 
 printf %s\\n '</ul>'