5 local cachepath="${attpath%/#attachments/*}/#cache/${attpath#*/#attachments/}"
9 *.webm|*.mp4|*.mkv|*.avi)
10 cachepath="${cachepath}.webm"
14 if [ -s "$cachepath" ]; then
15 printf %s "$cachepath"
17 elif [ -f "$cachepath" ]; then
20 elif ! mkdir -p -- "${cachepath%/*}" && touch "$cachepath"; then
27 read junk junk res junk <<-EOF
28 $(identify "$attpath")
30 if [ "${res%x*}" -gt 2048 ]; then
31 convert "$attpath" -resize 1920x-2 -quality 85 "$cachepath"
33 convert "$attpath" -quality 85 "$cachepath"
35 printf %s "$cachepath"
38 *.webm|*.mp4|*.mkv|*.avi)
39 res=$(ffprobe -show_entries stream=width "$attpath" 2>&-)
40 res="${res#*width=}" res="${res%%${BR}*}"
41 if [ "$res" -gt 1280 ]; then
43 ffmpeg -y -nostdin -i "$attpath" \
44 -c:v libvpx -vf scale=1280:-2 -crf 28 -b:v 0 \
45 -c:a libvorbis -q:a 6 \
46 "${cachepath%.*}.tmp.webm" \
47 && mv -- "${cachepatch%.*}.tmp.webm" "${cachepath}" \
52 ffmpeg -y -nostdin -i "$attpath" \
53 -c:v libvpx -crf 28 -b:v 0 \
54 -c:a libvorbis -q:a 6 \
55 "${cachepath%.*}.tmp.webm" \
56 && mv -- "${cachepatch%.*}.tmp.webm" "${cachepath}" \
65 if [ "${PATH_INFO%/\[attachment\]/}" != "${PATH_INFO}" ]; then
66 tsid="$(POST session_key)"; tsid="${tsid%% *}"
67 attachment_delete="$(POST delete)"
69 if [ "${CONTENT_TYPE%%;*}" = "multipart/form-data" ] && acl_write "${PATH_INFO%\[attachment\]/}"; then
70 . "$_EXEC/multipart.sh"
73 # Validate session id from form to prevent CSRF
74 # Only validate if username is present, because no username means
75 # anonymous uploads are allowed via acl and cgilite/session.sh does not
76 # validate anonymous sessions from a multipart/formdata
77 if [ "$USER_NAME" -a "$(multipart session_id)" != "$SESSION_ID" ]; then
78 rm -- "$multipart_cachefile"
79 printf 'Refresh: %i\r\n' 4
84 mkdir -p "$_DATA/pages/${PATH_INFO%/\[attachment\]/}/#attachments/"
85 n=1; while filename=$(multipart_filename "file" "$n"); do
86 filename="$(printf %s "$filename" |tr /\\0 __)"
87 multipart "file" "$n" >"$_DATA/pages/${PATH_INFO%/\[attachment\]/}/#attachments/$filename"
90 rm -- "$multipart_cachefile"
91 REDIRECT "${_BASE}${PATH_INFO}"
92 elif [ "${CONTENT_TYPE%%;*}" = "multipart/form-data" ]; then
93 printf 'Refresh: %i\r\n' 4
95 head -c $((CONTENT_LENGTH)) >/dev/null
96 elif [ "$attachment_delete" -a "$SESSION_ID" = "$tsid" ]; then
97 rm -- "$_DATA/pages/${PATH_INFO%/\[attachment\]/}/#attachments/$attachment_delete"
98 REDIRECT "${_BASE}${PATH_INFO}"
99 elif [ "$attachment_delete" ]; then
100 printf 'Refresh: %i\r\n' 4
102 elif acl_read "${PATH_INFO%\[attachment\]/}"; then
103 theme_attachments "${PATH_INFO%\[attachment\]/}"
108 elif [ "${PATH_INFO%/\[attachment\]/*}" != "${PATH_INFO}" ]; then
109 attpath="${PATH_INFO%/\[attachment\]/*}/#attachments/${PATH_INFO##*/}"
111 if ! acl_read "${PATH_INFO%/\[attachment\]/*}"; then
113 elif [ -f "$_DATA/pages/$attpath" ]; then
114 FILE "$_DATA/pages/$attpath"
115 elif [ -f "$_EXEC/pages/$attpath" ]; then
116 FILE "$_EXEC/pages/$attpath"
122 elif [ "${PATH_INFO%/}" = "${PATH_INFO}" ]; then
123 attpath="${PATH_INFO%/*}/#attachments/${PATH_INFO##*/}"
125 if ! acl_read "${PATH_INFO%/*}/"; then
127 elif [ -f "$_DATA/pages/$attpath" ]; then
128 FILE "$(attachment_convert "$_DATA/pages/$attpath")"
129 elif [ -f "$_EXEC/pages/$attpath" ]; then
130 FILE "$(attachment_convert "$_EXEC/pages/$attpath")"
131 elif [ -d "$_DATA/pages/${PATH_INFO}" -o -d "$_EXEC/pages/${PATH_INFO}" ]; then
132 REDIRECT "${_BASE}${PATH_INFO}/"