From: Paul Hänsch Date: Wed, 4 Jul 2018 07:46:21 +0000 (+0200) Subject: list view / index view X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=3c586e3fe4da20469de93897d03d41f82cb15b3b;p=serve0 list view / index view --- diff --git a/cgilite b/cgilite index 3a5f8da..a96b0fc 160000 --- a/cgilite +++ b/cgilite @@ -1 +1 @@ -Subproject commit 3a5f8da6c094474cb5de33d40fc94e4497450a25 +Subproject commit a96b0fcd8fb4afad4e169a3929270e2335cf4d0d diff --git a/index.cgi b/index.cgi index 94309f3..b4339ad 100755 --- a/index.cgi +++ b/index.cgi @@ -1,45 +1,47 @@ #!/bin/sh -[ -z "${_EXEC%/}" ] && _EXEC=. || _EXEC="${_DATA%/}" +[ -z "${_EXEC%/}" ] && _EXEC="$(realpath "${0%/*}")" || _EXEC="${_EXEC%/}" [ -z "${_DATA%/}" ] && _DATA=. || _DATA="${_DATA%/}" . "$_EXEC/cgilite/cgilite.sh" . "$_EXEC/widgets.sh" -filter="$(GET f)" -search="$(GET s)" -order="$(GET o |grep -m1 -xE 'Date|Name|Length' || printf Name)" -pagesize="$(COOKIE pagesize |grep -m1 -xE '[1-9][0-9]*' || printf 50)" +FILTER="$(GET f)" +SEARCH="$(GET s)" +ORDER="$(GET o |grep -m1 -xE 'Date|Name|Length' || printf Name)" +LISTSIZE="$(COOKIE pagesize |grep -m1 -xE '[1-9][0-9]*' || printf 50)" -item="$(printf %s "${PATH_INFO#/}" |sed -r ':X /(^|\/)\.\.($|\/)/s;(^|[^/]*/)..(/|$);;; tX;')" +ITEM="$(printf %s "${PATH_INFO#/}" |sed -r ':X /(^|\/)\.\.($|\/)/s;(^|[^/]*/)..(/|$);;; tX;')" case $(GET a) in setprefs) printf 'Status: 303 See Other\r\n' SET_COOKIE +$((86400 * 90)) pagesize="$(POST pagesize |grep -m1 -xE '[1-9][0-9]*' || printf 50)" + SET_COOKIE +$((86400 * 90)) mode="$(POST mode |grep -m1 -xE 'browse|index' || printf browse)" SET_COOKIE +$((86400 * 90)) fakemp4="$(POST fakemp4 |grep -m1 -xE 'yes' || printf no)" printf 'Location: %s\r\n\r\n' "$(POST ref)" exit 0 ;; esac -if [ "$item" = "/style.css" ]; then +if [ "$ITEM" = "style.css" ]; then . "$_EXEC/cgilite/file.sh" - [ -r "$_DATA/$item" ] && FILE "$_DATA/$item" \ + [ -r "$_DATA/$ITEM" ] && FILE "$_DATA/$ITEM" \ || FILE "$_EXEC/style.css" -elif [ -f "$_DATA/$item" ]; then +elif [ -f "$_DATA/$ITEM" ]; then case $(GET a) in tag) ;; thumbnail) + printf 'Status: 404 Not Found\r\nContent-Length 0:\r\n\r\n' ;; delete) ;; *) . "$_EXEC/cgilite/file.sh" - FILE "$_DATA/$item" + FILE "$_DATA/$ITEM" ;; esac -elif [ -d "$_DATA/$item" ]; then +elif [ -d "$_DATA/$ITEM" ]; then case $(GET a) in multitag) ;; @@ -47,6 +49,5 @@ elif [ -d "$_DATA/$item" ]; then ;; esac else - printf 'Status: 404 Not Found\r\n\r\n' - exit 0 + printf 'Status: 404 Not Found\r\nContent-Length 0:\r\n\r\n' fi diff --git a/list.sh b/list.sh index b8c3a4e..cb0e4c1 100644 --- a/list.sh +++ b/list.sh @@ -1,5 +1,44 @@ #!/bin/sh +list_dir(){ + dir="$(HTML "$1")" + printf '[a .list .dir href="%s" %s]' \ + "$dir" "$dir" +} + +list_file(){ + file="$(HTML "$1")" + printf '[div .list .file [a href="%s" [img src="%s?a=thumbnail"] %s]]' \ + "$file" "$file" "$file" +} + +list_dirs(){ + (cd "$_DATA/$ITEM"; + find ./ -type d -mindepth 1 -maxdepth 1 \ + -exec stat -c '%Y %n' '{}' + + ) \ + | { [ "$(GET o)" = Date ] && sort -rn || sort -k 2; } \ + | cut -d/ -f2- +} + +list_files(){ + (cd "$_DATA/$ITEM"; + find ./ -type f -mindepth 1 -maxdepth 1 \ + -exec stat -c '%Y %n' "${f#./}" '{}' + + ) \ + | { [ "$(GET o)" = Date ] && sort -rn || sort -k 2; } \ + | cut -d/ -f2- +} + +list_tree(){ + (cd "$_DATA/$ITEM"; + find ./ -type f \ + -exec stat -c '%Y %n' '{}' + + ) \ + | { [ "$(GET o)" = Date ] && sort -rn || sort -k 2; } \ + | cut -d/ -f2- +} + printf 'Content-Type: text/html;charset=utf-8\r\n\r\n' "$_EXEC/cgilite/html-sh.sed" <<-EOF @@ -10,6 +49,13 @@ printf 'Content-Type: text/html;charset=utf-8\r\n\r\n' $(w_search) [input type=checkbox #t_prefs .toggle ][label for=t_prefs ⚙] $(w_prefs) + $(if [ $(COOKIE mode) = index ]; then + list_tree |while read -r file; do list_file "$file"; done + else + list_dirs |while read -r dir; do list_dir "$dir"; done + printf '[br]' + list_files |while read -r file; do list_file "$file"; done + fi) ] ] EOF diff --git a/style.css b/style.css index 90bb4ea..f0a16b5 100644 --- a/style.css +++ b/style.css @@ -1,3 +1,7 @@ +* { + box-sizing: border-box; +} + body { color: white; background-color: black; @@ -52,3 +56,37 @@ label[for=t_prefs] { #prefs button { margin-top: 1em; } +#prefs input { vertical-align: top; } +#prefs input[type=radio] + label, +#prefs input[type=checkbox] + label { + display: inline-block; + margin-bottom: .5em; + max-width: 85%; +} + +.list { + position: relative; + display: inline-block; + width: 25%; + min-width: 250px; + padding: .5em 1em; + margin: 0; + overflow: none; + word-wrap: break-word; + vertical-align: top; +} +.list, .list a { color: black; } +.list:before { + position: absolute; + top: .25em; left: .25em; + bottom: .25em; right: .25em; + z-index: -2; + content: ''; +} +.list.dir:before { background-color: #CCF; } +.list.file:before { background-color: #FDD; } + +.list.file img { + display: block; + width: 100%; +} diff --git a/widgets.sh b/widgets.sh index fd9e72e..c0de813 100644 --- a/widgets.sh +++ b/widgets.sh @@ -12,20 +12,25 @@ w_search(){ [input name=s placeholder=Search value="%s"] ] ' \ - "$(HTML "$search")" + "$(HTML "$SEARCH")" } w_prefs(){ + fakemp4="$(COOKIE fakemp4)" + mode="$(COOKIE mode)" printf ' [form #prefs method="POST" action="?a=setprefs" [hidden "ref" "%s"] [label for=prefs_ps Pagesize] [input #prefs_ps type=number name=pagesize value="%s"][br] + [radio "mode" "browse" %s #prefs_modebrowse] [label for=prefs_modebrowse Browse Folders][br] + [radio "mode" "index" %s #prefs_modeindex ] [label for=prefs_modeindex View Full Index][br] [checkbox "fakemp4" "yes" %s #prefs_fmp4] [label for=prefs_fmp4 Fake .MP4 file ending][br] [submit "store" "store" Set Cookie] ] ' \ - "$(HTML "$REQUEST_URI")" \ - "$(COOKIE pagesize |grep -m1 -xE '[0-9]+' || printf 50)" \ - "$(COOKIE fakemp4 |grep -m1 -qx yes && printf checked)" + "$(HTML "$REQUEST_URI")" "$LISTSIZE" \ + "$([ "$mode" = index ] || printf checked)" \ + "$([ "$mode" = index ] && printf checked)" \ + "$([ "$fakemp4" = yes ] && printf checked)" }