]> git.plutz.net Git - shellwiki/commitdiff
attachment rename
authorPaul Hänsch <paul@plutz.net>
Tue, 2 Aug 2022 12:51:56 +0000 (14:51 +0200)
committerPaul Hänsch <paul@plutz.net>
Tue, 2 Aug 2022 12:51:56 +0000 (14:51 +0200)
handlers/20_edit_attachment.sh
themes/default.sh

index f400523b027a49d9e98846e7a3627ba77426d727..97a4b9df2d8825be71512714c98f6e8fbdd193cf 100755 (executable)
@@ -121,6 +121,100 @@ elif [ "$action" = move ]; then
   fi
   REDIRECT "${_BASE}${PATH_INFO}"
 
+elif [ "$action" = rename ]; then
+  fail='' success=''
+  set --
+
+  for file in "${_DATA}/pages${page}#attachments"/*; do
+    rename="$(POST rename_"$(slopecode "${file##*/}" |sed 's;=;%3D;g')")"
+
+    if [ "$REV_ATTACHMENTS" = true -a \
+         -f "${file}" -a \
+         "$rename" -a \
+         "${rename%/*}" = "${rename}" -a \
+         ! -e "${_DATA}/pages${page}#attachments/${rename}" ] \
+       && git -C "$_DATA" mv -- "pages${page}#attachments/${file##*/}" "pages${page}#attachments/${rename}"; then
+      success="${success}$(HTML "${file##*/}/${rename}")${BR}"
+      set -- "$@" "pages${page}#attachments/${file##*/}" "pages${page}#attachments/${rename}"
+
+    elif [ "$REV_ATTACHMENTS" = true -a "${rename}" ]; then
+      fail="${fail}$(HTML "${file##*/}/${rename}")${BR}"
+
+    elif [ -f "${file}" -a \
+           "$rename" -a \
+           "${rename%/*}" = "${rename}" -a \
+           ! -e "${_DATA}/pages${page}#attachments/${rename}" ] \
+         && mv -- "${file}" "${_DATA}/pages${page}#attachments/${rename}"; then
+      success="${success}$(HTML "${file##*/}/${rename}")${BR}"
+
+    elif [ "${rename}" ]; then
+      fail="${fail}$(HTML "${file##*/}/${rename}")${BR}"
+
+    fi
+  done
+
+  if [ "$REV_ATTACHMENTS" = true -a $# -gt 2 ]; then
+    git -C "$_DATA" commit -qm \
+        "Attachment files renamed by @ $USER_NAME @" -- "$@"
+  elif [ "$REV_ATTACHMENTS" = true -a $# -eq 2 ]; then
+    git -C "$_DATA" commit -qm \
+        "Attachment file renamed by @ $USER_NAME @" -- "$@"
+  fi
+
+  if [ "$success" -a "$fail" ]; then
+    printf "%s\r\n" "Status: 500 Internal Server Error"
+    theme_page - "Attachment rename" <<-EOF
+       <h1 class="rename partial">Some files could not be renamed</h1>
+       <h2 class="rename success">Successfully renamed:</h2>
+       <ul class="rename success">
+       $(printf %s "$success" |while read html; do
+         printf '<li><span class=from>%s</span> -&gt; <span class=to>%s</span></li>' \
+                "${html%%/*}" "${html##*/}"
+       done)
+       </ul>
+       <h2 class="rename fail">Errors:</h2>
+       <ul class="rename fail">
+       $(printf %s "$fail" |while read html; do
+         printf '<li><span class=from>%s</span> -&gt; <span class=to>%s</span></li>' \
+                "${html%%/*}" "${html##*/}"
+       done)
+       </ul>
+       <a class="button rename fail" href="[attachment]">OK</a>
+       EOF
+    exit 0
+
+  elif [ "$fail" ]; then
+    printf "%s\r\n" "Status: 500 Internal Server Error"
+    theme_page - "Attachment rename" <<-EOF
+       <h1 class="rename fail">Files could not be renamed</h1>
+       <ul class="rename fail">
+       $(printf %s "$fail" |while read html; do
+         printf '<li><span class=from>%s</span> -&gt; <span class=to>%s</span></li>' \
+                "${html%%/*}" "${html##*/}"
+       done)
+       </ul>
+       <a class="button rename fail" href="[attachment]">OK</a>
+       EOF
+    exit 0
+
+  elif [ "$success" ]; then
+    printf 'Refresh: %i\r\n' 4
+    theme_page - "Attachment rename" <<-EOF
+       <h1 class="rename success">Files were renamed</h1>
+       <ul class="rename success">
+       $(printf %s "$success" |while read html; do
+         printf '<li><span class=from>%s</span> -&gt; <span class=to>%s</span></li>' \
+                "${html%%/*}" "${html##*/}"
+       done)
+       </ul>
+       <a class="button rename success" href="[attachment]">OK</a>
+       EOF
+    exit 0
+
+  else
+    REDIRECT "${_BASE}${PATH_INFO}"
+
+  fi
 fi
 
 return 1
index 3c803f455716d56ff6bba276a2586690945fb958..e8b5f2f62802d53bfddc51f3e0dbc215a12a2df7 100755 (executable)
@@ -129,7 +129,7 @@ theme_attachments(){
                    <span class=date>%s</span>
                  </li>' \
                 "$hfile" "$hfile" "$hfile" "$hfile" \
-                "$hfile" "$hfile" "$hfile" "$hfile" \
+                "$(slopecode "${file##*/}")" "$hfile" "$hfile" "$hfile" \
                 "$(size_human "$size")" "$(date -d @"$date" +"%F %T")"
        done)
            </ul>