3 for n in "$@"; do case ${n%%=*} in
4 data) _DATA="${n#data=}";;
5 exec) _exec="${n#exec=}";;
9 [ -z "${_EXEC%/}" ] && _EXEC="$(realpath "${0%/*}")" || _EXEC="${_EXEC%/}"
10 [ -z "${_DATA%/}" ] && _DATA=. || _DATA="${_DATA%/}"
12 file_pattern='^.*\.(mov|ts|mpg|mpeg|mp4|m4v|avi|mkv|flv|sfv|wmv|ogm|ogv|webm|iso|rmvb)$'
14 . "$_EXEC/cgilite/cgilite.sh"
18 ORDER="$(GET o |grep -m1 -axE 'Date|Name|Length' || printf Name)"
19 LISTSIZE="$(COOKIE pagesize |grep -m1 -axE '[1-9][0-9]*' || printf 50)"
20 ITEM="$(PATH "${PATH_INFO#/}")"
25 SET_COOKIE +$((86400 * 90)) pagesize="$(POST pagesize |grep -m1 -axE '[1-9][0-9]*' || printf 50)"
26 SET_COOKIE +$((86400 * 90)) mode="$(POST mode |grep -m1 -axE 'browse|index' || printf browse)"
27 SET_COOKIE +$((86400 * 90)) fakemp4="$(POST fakemp4 |grep -m1 -axE 'yes' || printf no)"
28 SET_COOKIE +$((86400 * 90)) downscale="$(POST downscale |grep -m1 -axE 'yes' || printf no)"
29 [ "$(POST index)" = "update" ] && touch -cd @0 "${_DATA}/.index/meta"
30 REDIRECT "$(POST ref)"
33 bm="$_DATA/.index/bookmarks"
34 . "$_EXEC/cgilite/storage.sh"
36 s="$(POST search |STRING)"; f="$(POST filter |STRING)"
38 grep -avF " search=$s filter=$f${CR}" "$bm" >"$bm.tmp"
39 [ ! "$(POST delete)" ] \
40 && printf '%s search=%s filter=%s\r\n' \
41 "$(POST name |STRING)" "$s" "$f" >>"$bm.tmp"
45 REDIRECT "$(POST ref)"
48 . "$_EXEC/multitag.sh"
49 REDIRECT "$(POST ref)"
53 if [ "$ITEM" = "/style.css" ]; then
54 . "$_EXEC/cgilite/file.sh"
55 [ -r "$_DATA/$ITEM" ] && FILE "$_DATA/$ITEM" \
56 || FILE "$_EXEC/style.css"
57 elif [ "$ITEM" = "/stereoview.js" ]; then
58 . "$_EXEC/cgilite/file.sh"
59 FILE "$_EXEC/stereoview.js"
60 elif [ -f "$_DATA/$ITEM" ]; then
63 . "$_EXEC/cgilite/file.sh"
64 . "$_EXEC/thumbnail.sh"
65 index="$_DATA/${ITEM%/*}/.index"
66 thumb="$index/${ITEM##*/}"; thumb="${thumb%.*}.jpg"
67 [ -d "$index" -a ! -f "$thumb" ] \
68 && { printf %s "$ITEM" |grep -qE -e "${file_pattern}" ;} \
69 && gen_thumb "$_DATA/$ITEM" "$thumb"
75 . "$_EXEC/cgilite/file.sh"
76 fakemp4="$(COOKIE fakemp4)"
77 downscale="$(COOKIE downscale)"
78 downfile="$_DATA/${ITEM%/*}/.transcode/${ITEM%.*}.480p.webm"
79 if [ "$downscale" = yes -a -f "$downfile" ]; then
80 FILE "$downfile" "$([ "$fakemp4" = yes ] && printf 'video/mp4')"
82 FILE "$_DATA/$ITEM" "$([ "$fakemp4" = yes ] && printf 'video/mp4')"
87 elif [ -d "$_DATA/$ITEM" ]; then
90 . "$_EXEC/advsearch.sh"
93 if [ "$(POST recursive)" = yes ]; then
94 find "$_DATA/$ITEM" -depth -type d \! -name .index \
95 -exec mkdir -p '{}'/.index \;
97 mkdir -p "$_DATA/$ITEM/.index"
99 REDIRECT "$(POST ref)"
101 *) . "$_EXEC/list.sh"
105 printf 'Status: 404 Not Found\r\nContent-Length 0:\r\n\r\n'