3 . "$_EXEC/cgilite/file.sh"
5 # REV_ATTACHMENTS="${REV_ATTACHMENTS:-false}"
9 local cachepath="${attpath%/#attachments/*}/#cache/${attpath#*/#attachments/}"
13 *.webm|*.mp4|*.mkv|*.avi)
14 cachepath="${cachepath}.webm"
18 if [ -s "$cachepath" ]; then
19 printf %s "$cachepath"
21 elif [ -f "$cachepath" ]; then
24 elif ! mkdir -p -- "${cachepath%/*}" && touch "$cachepath"; then
31 read junk junk res junk <<-EOF
32 $(identify "$attpath")
34 if [ "${res%x*}" -gt 2048 ]; then
35 convert "$attpath" -resize 1920x-2 -quality 85 "$cachepath"
37 convert "$attpath" -quality 85 "$cachepath"
39 printf %s "$cachepath"
42 *.webm|*.mp4|*.mkv|*.avi)
43 res=$(ffprobe -show_entries stream=width "$attpath" 2>&-)
44 res="${res#*width=}" res="${res%%${BR}*}"
45 if [ "$res" -gt 1280 ]; then
47 ffmpeg -y -nostdin -i "$attpath" \
48 -c:v libvpx -vf scale=1280:-2 -crf 28 -b:v 0 \
49 -c:a libvorbis -q:a 6 \
50 "${cachepath%.*}.tmp.webm" \
51 && mv -- "${cachepatch%.*}.tmp.webm" "${cachepath}" \
56 ffmpeg -y -nostdin -i "$attpath" \
57 -c:v libvpx -crf 28 -b:v 0 \
58 -c:a libvorbis -q:a 6 \
59 "${cachepath%.*}.tmp.webm" \
60 && mv -- "${cachepatch%.*}.tmp.webm" "${cachepath}" \
66 *) printf "$attpath";;
73 REDIRECT "${_BASE}${PATH_INFO%/}"
76 # attached files never end on /
80 # show attachment page
81 page="${PATH_INFO%\[attachment\]}"
83 if [ ! -d "$_DATA/pages${page}" -a ! -d "$_DATA/pages${page}" ]; then
84 # base page does not exist
86 elif [ "${CONTENT_TYPE%%;*}" = "multipart/form-data" ]; then
87 # pass uploads to next handler
89 elif [ "$(POST action)" ]; then
90 # pass edits to next handler
92 elif ! acl_read "${page}"; then
96 theme_attachments "${page}"
102 attpath="${PATH_INFO%/\[attachment\]/*}/#attachments/${PATH_INFO##*/}"
104 if [ ! -f "$_DATA/pages/$attpath" -a ! -f "$_EXEC/pages/$attpath" ]; then
106 elif ! acl_read "${PATH_INFO%/\[attachment\]/*}"; then
109 elif [ -f "$_DATA/pages/$attpath" ]; then
110 FILE "$_DATA/pages/$attpath"
112 elif [ -f "$_EXEC/pages/$attpath" ]; then
113 FILE "$_EXEC/pages/$attpath"
118 attpath="${PATH_INFO%/*}/#attachments/${PATH_INFO##*/}"
120 if [ ! -f "$_DATA/pages/$attpath" -a ! -f "$_EXEC/pages/$attpath" ]; then
122 elif ! acl_read "${PATH_INFO%/*}/"; then
125 elif [ -f "$_DATA/pages/$attpath" ]; then
126 FILE "$(attachment_convert "$_DATA/pages/$attpath")"
128 elif [ -f "$_EXEC/pages/$attpath" ]; then
129 FILE "$(attachment_convert "$_EXEC/pages/$attpath")"