From: Paul Hänsch Date: Tue, 22 Sep 2020 22:29:34 +0000 (+0200) Subject: changes in action/path selection X-Git-Url: http://git.plutz.net/?p=serve0;a=commitdiff_plain;h=fdc8b1be6f0f22550de83cdca95c5067e1dff17d changes in action/path selection --- diff --git a/index.cgi b/index.cgi index 3cee46f..000fabb 100755 --- 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