]> git.plutz.net Git - serve0/commitdiff
changes in action/path selection
authorPaul Hänsch <paul@plutz.net>
Tue, 22 Sep 2020 22:29:34 +0000 (00:29 +0200)
committerPaul Hänsch <paul@plutz.net>
Tue, 22 Sep 2020 22:29:34 +0000 (00:29 +0200)
index.cgi

index 3cee46fa04bdf3a24b4169451c524cc8dd095c7b..000fabbf1e96fa89f886f59cc61e302ac4c7d327 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
@@ -1,5 +1,6 @@
 #!/bin/sh
 
+exec 2>/dev/null
 for n in "$@"; do case ${n%%=*} in
   data) _DATA="${n#data=}";;
   exec) _exec="${n#exec=}";;
@@ -48,59 +49,68 @@ case $ACTION in
     . "$_EXEC/multitag.sh"
     REDIRECT "$(POST ref)"
   ;;
+  thumbnail) if [ -f "$_DATA/$PATH_INFO" ]; then
+    . "$_EXEC/cgilite/file.sh"
+    index="$_DATA/${PATH_INFO%/*}/.index"
+    thumb="$index/${PATH_INFO##*/}"; thumb="${thumb%.*}.jpg"
+    if [ -d "$index" -a ! -f "$thumb" ] && { printf %s "$PATH_INFO" |grep -qE -e "${file_pattern}" ;}; then
+      . "$_EXEC/thumbnail.sh"
+      gen_thumb "$_DATA/$PATH_INFO" "$thumb"
+    fi
+    FILE "$thumb"
+    return 0
+  fi;;
+  download) if [ -f "$_DATA/$PATH_INFO" ]; then
+    . "$_EXEC/cgilite/file.sh"
+    fakemp4="$(COOKIE fakemp4)"
+    downscale="$(COOKIE downscale)"
+    downfile="$_DATA/${PATH_INFO%/*}/.transcode/${PATH_INFO%.*}.480p.webm"
+    if [ "$downscale" = yes -a -f "$downfile" ]; then
+      FILE "$downfile" "$([ "$fakemp4" = yes ] && printf 'video/mp4')"
+    else
+      FILE "$_DATA/$PATH_INFO" "$([ "$fakemp4" = yes ] && printf 'video/mp4')"
+    fi
+    return 0
+  fi;;
+  delete) if [ -f "$_DATA/$PATH_INFO" ]; then
+    :
+  fi;;
+  advsearch) if [ -d "$_DATA/$PATH_INFO" ]; then
+    . "$_EXEC/advsearch.sh"
+    return 0
+  fi;;
+  spawnindex) if [ -d "$_DATA/$PATH_INFO" ]; then
+    if [ "$(POST recursive)" = yes ]; then
+      find "$_DATA/$PATH_INFO" -depth -type d \! -name .index \
+                          -exec mkdir -p '{}'/.index \;
+    else
+      mkdir -p "$_DATA/$PATH_INFO/.index"
+    fi
+    REDIRECT "$(POST ref)"
+  fi;;
 esac
 
-if [ "$PATH_INFO" = "/style.css" ]; then
-  . "$_EXEC/cgilite/file.sh"
-  [ -r "$_DATA/$PATH_INFO" ] && FILE "$_DATA/$PATH_INFO" \
-                        || FILE "$_EXEC/style.css"
-elif [ "$PATH_INFO" = "/stereoview.js" ]; then
-  . "$_EXEC/cgilite/file.sh"
-  FILE "$_EXEC/stereoview.js"
-elif [ -f "$_DATA/$PATH_INFO" ]; then
-  case $ACTION in
-    thumbnail)
-      . "$_EXEC/cgilite/file.sh"
-      . "$_EXEC/thumbnail.sh"
-      index="$_DATA/${PATH_INFO%/*}/.index"
-      thumb="$index/${PATH_INFO##*/}"; thumb="${thumb%.*}.jpg"
-      [ -d "$index" -a ! -f "$thumb" ] \
-      && { printf %s "$PATH_INFO" |grep -qE -e "${file_pattern}" ;} \
-      && gen_thumb "$_DATA/$PATH_INFO" "$thumb"
-      FILE "$thumb"
-    ;;
-    delete)
-    ;;
-    download)
-      . "$_EXEC/cgilite/file.sh"
-      fakemp4="$(COOKIE fakemp4)"
-      downscale="$(COOKIE downscale)"
-      downfile="$_DATA/${PATH_INFO%/*}/.transcode/${PATH_INFO%.*}.480p.webm"
-      if [ "$downscale" = yes -a -f "$downfile" ]; then
-        FILE "$downfile" "$([ "$fakemp4" = yes ] && printf 'video/mp4')"
-      else
-        FILE "$_DATA/$PATH_INFO" "$([ "$fakemp4" = yes ] && printf 'video/mp4')"
-      fi
-    ;;
-    *) . "$_EXEC/view.sh"
-  esac
+case $PATH_INFO in
+  /style.css)
+    . "$_EXEC/cgilite/file.sh"
+    [ -r "$_DATA/$PATH_INFO" ] \
+    && FILE "$_DATA/$PATH_INFO" \
+    || FILE "$_EXEC/style.css"
+    return 0
+  ;;
+  /stereoview.js)
+    . "$_EXEC/cgilite/file.sh"
+    FILE "$_EXEC/stereoview.js"
+    return 0
+  ;;
+esac
+
+if [ -f "$_DATA/$PATH_INFO" ]; then
+  . "$_EXEC/view.sh"
+  return 0
 elif [ -d "$_DATA/$PATH_INFO" ]; then
-  case $ACTION in
-    advsearch)
-      . "$_EXEC/advsearch.sh"
-    ;;
-    spawnindex)
-      if [ "$(POST recursive)" = yes ]; then
-        find "$_DATA/$PATH_INFO" -depth -type d \! -name .index \
-                            -exec mkdir -p '{}'/.index \;
-      else
-        mkdir -p "$_DATA/$PATH_INFO/.index"
-      fi
-      REDIRECT "$(POST ref)"
-    ;;
-    *) . "$_EXEC/list.sh"
-    ;;
-  esac
+  . "$_EXEC/list.sh"
+  return 0
 else
   printf 'Status: 404 Not Found\r\nContent-Length 0:\r\n\r\n'
 fi