4 for n in "$@"; do case ${n%%=*} in
5 data) _DATA="${n#data=}";;
6 exec) _exec="${n#exec=}";;
10 [ -z "${_EXEC%/}" ] && _EXEC="$(realpath "${0%/*}")" || _EXEC="${_EXEC%/}"
11 [ -z "${_DATA%/}" ] && _DATA=. || _DATA="${_DATA%/}"
13 file_pattern='^.*\.(mov|ts|mpg|mpeg|mp4|m4v|avi|mkv|flv|sfv|wmv|ogm|ogv|webm|iso|rmvb)$'
15 . "$_EXEC/cgilite/cgilite.sh"
19 ORDER="$(GET o |grep -m1 -axE 'Date|Name|Length|Group' || printf Name)"
20 LISTSIZE="$(COOKIE pagesize |grep -m1 -axE '[1-9][0-9]*' || printf 60)"
26 SET_COOKIE +$((86400 * 90)) pagesize="$(POST pagesize |grep -m1 -axE '[1-9][0-9]*' || printf 60)"
27 SET_COOKIE +$((86400 * 90)) mode="$(POST mode |grep -m1 -axE 'browse|index' || printf browse)"
28 SET_COOKIE +$((86400 * 90)) fakemp4="$(POST fakemp4 |grep -m1 -axE 'yes' || printf no)"
29 SET_COOKIE +$((86400 * 90)) downscale="$(POST downscale |grep -m1 -axE 'yes' || printf no)"
30 [ "$(POST index)" = "update" ] && touch -cd @0 "${_DATA}/.index/meta.time"
31 REDIRECT "$(POST ref)"
34 bm="$_DATA/.index/bookmarks"
35 . "$_EXEC/cgilite/storage.sh"
37 s="$(POST search |STRING)"; f="$(POST filter |STRING)"
39 grep -avF " search=$s filter=$f${CR}" "$bm" >"$bm.tmp"
40 [ ! "$(POST delete)" ] \
41 && printf '%s search=%s filter=%s\r\n' \
42 "$(POST name |STRING)" "$s" "$f" >>"$bm.tmp"
46 REDIRECT "$(POST ref)"
49 . "$_EXEC/multitag.sh"
50 REDIRECT "$(POST ref)"
52 thumbnail) if [ -f "$_DATA/$PATH_INFO" ]; then
53 . "$_EXEC/cgilite/file.sh"
54 index="$_DATA/${PATH_INFO%/*}/.index"
55 thumb="$index/${PATH_INFO##*/}"; thumb="${thumb%.*}.jpg"
56 if [ -d "$index" -a ! -f "$thumb" ] && { printf %s "$PATH_INFO" |grep -qE -e "${file_pattern}" ;}; then
57 . "$_EXEC/thumbnail.sh"
58 gen_thumb "$_DATA/$PATH_INFO" "$thumb"
63 download) if [ -f "$_DATA/$PATH_INFO" ]; then
64 . "$_EXEC/cgilite/file.sh"
65 fakemp4="$(COOKIE fakemp4)"
66 downscale="$(COOKIE downscale)"
67 downfile="$_DATA/${PATH_INFO%/*}/.transcode/${PATH_INFO%.*}.480p.webm"
68 if [ "$downscale" = yes -a -f "$downfile" ]; then
69 FILE "$downfile" "$([ "$fakemp4" = yes ] && printf 'video/mp4')"
71 FILE "$_DATA/$PATH_INFO" "$([ "$fakemp4" = yes ] && printf 'video/mp4')"
75 delete) if [ -f "$_DATA/$PATH_INFO" ]; then
78 advsearch) if [ -d "$_DATA/$PATH_INFO" ]; then
79 . "$_EXEC/advsearch.sh"
82 spawnindex) if [ -d "$_DATA/$PATH_INFO" ]; then
83 if [ "$(POST recursive)" = yes ]; then
84 find "$_DATA/$PATH_INFO" -depth -type d \! -name .index \
85 -exec mkdir -p '{}'/.index \;
87 mkdir -p "$_DATA/$PATH_INFO/.index"
89 REDIRECT "$(POST ref)"
95 # . "$_EXEC/cgilite/file.sh"
96 # [ -r "$_DATA/$PATH_INFO" ] \
97 # && FILE "$_DATA/$PATH_INFO" \
98 # || FILE "$_EXEC/style.css"
102 # . "$_EXEC/cgilite/file.sh"
103 # FILE "$_EXEC/stereoview.js"
108 if [ -f "$_EXEC/$PATH_INFO" ]; then
109 . "$_EXEC/cgilite/file.sh"
110 FILE "$_EXEC/$PATH_INFO"
112 elif [ -f "$_DATA/$PATH_INFO" ]; then
115 elif [ -d "$_DATA/$PATH_INFO" ]; then
119 printf 'Status: 404 Not Found\r\nContent-Length 0:\r\n\r\n'