3 . "$_EXEC/cgilite/file.sh"
7 local cachepath="${attpath%/#attachments/*}/#cache/${attpath#*/#attachments/}"
11 *.webm|*.mp4|*.mkv|*.avi)
12 cachepath="${cachepath}.webm"
16 if [ -s "$cachepath" ]; then
17 printf %s "$cachepath"
19 elif [ -f "$cachepath" ]; then
22 elif ! mkdir -p -- "${cachepath%/*}" && touch "$cachepath"; then
29 read junk junk res junk <<-EOF
30 $(identify "$attpath")
32 if [ "${res%x*}" -gt 2048 ]; then
33 convert "$attpath" -resize 1920x-2 -quality 85 "$cachepath"
35 convert "$attpath" -quality 85 "$cachepath"
37 printf %s "$cachepath"
40 *.webm|*.mp4|*.mkv|*.avi)
41 res=$(ffprobe -show_entries stream=width "$attpath" 2>&-)
42 res="${res#*width=}" res="${res%%${BR}*}"
43 if [ "$res" -gt 1280 ]; then
45 ffmpeg -y -nostdin -i "$attpath" \
46 -c:v libvpx -vf scale=1280:-2 -crf 28 -b:v 0 \
47 -c:a libvorbis -q:a 6 \
48 "${cachepath%.*}.tmp.webm" \
49 && mv -- "${cachepatch%.*}.tmp.webm" "${cachepath}" \
54 ffmpeg -y -nostdin -i "$attpath" \
55 -c:v libvpx -crf 28 -b:v 0 \
56 -c:a libvorbis -q:a 6 \
57 "${cachepath%.*}.tmp.webm" \
58 && mv -- "${cachepatch%.*}.tmp.webm" "${cachepath}" \
69 REDIRECT "${_BASE}${PATH_INFO%/}"
72 tsid="$(POST session_key)"; tsid="${tsid%% *}"
73 attachment_delete="$(POST delete)"
75 if [ "${CONTENT_TYPE%%;*}" = "multipart/form-data" ] && acl_write "${PATH_INFO%\[attachment\]}"; then
76 . "$_EXEC/multipart.sh"
79 # Validate session id from form to prevent CSRF
80 # Only validate if username is present, because no username means
81 # anonymous uploads are allowed via acl and cgilite/session.sh does not
82 # validate anonymous sessions from a multipart/formdata
83 if [ "$USER_NAME" -a "$(multipart session_id)" != "$SESSION_ID" ]; then
84 rm -- "$multipart_cachefile"
85 printf 'Refresh: %i\r\n' 4
90 mkdir -p "$_DATA/pages/${PATH_INFO%/\[attachment\]}/#attachments/"
91 n=1; while filename=$(multipart_filename "file" "$n"); do
92 filename="$(printf %s "$filename" |tr /\\0 __)"
93 multipart "file" "$n" >"$_DATA/pages/${PATH_INFO%/\[attachment\]}/#attachments/$filename"
96 rm -- "$multipart_cachefile"
97 REDIRECT "${_BASE}${PATH_INFO}"
98 elif [ "${CONTENT_TYPE%%;*}" = "multipart/form-data" ]; then
99 printf 'Refresh: %i\r\n' 4
101 head -c $((CONTENT_LENGTH)) >/dev/null
103 elif [ "$attachment_delete" -a "$SESSION_ID" = "$tsid" ]; then
104 rm -- "$_DATA/pages/${PATH_INFO%/\[attachment\]}/#attachments/$attachment_delete"
105 REDIRECT "${_BASE}${PATH_INFO}"
106 elif [ "$attachment_delete" ]; then
107 printf 'Refresh: %i\r\n' 4
110 elif acl_read "${PATH_INFO%\[attachment\]}"; then
111 theme_attachments "${PATH_INFO%\[attachment\]}"
120 attpath="${PATH_INFO%/\[attachment\]/*}/#attachments/${PATH_INFO##*/}"
122 if ! acl_read "${PATH_INFO%/\[attachment\]/*}"; then
125 elif [ -f "$_DATA/pages/$attpath" ]; then
126 FILE "$_DATA/pages/$attpath"
128 elif [ -f "$_EXEC/pages/$attpath" ]; then
129 FILE "$_EXEC/pages/$attpath"
140 attpath="${PATH_INFO%/*}/#attachments/${PATH_INFO##*/}"
142 if ! acl_read "${PATH_INFO%/*}/"; then
145 elif [ -f "$_DATA/pages/$attpath" ]; then
146 FILE "$(attachment_convert "$_DATA/pages/$attpath")"
148 elif [ -f "$_EXEC/pages/$attpath" ]; then
149 FILE "$(attachment_convert "$_EXEC/pages/$attpath")"
151 elif [ -d "$_DATA/pages/${PATH_INFO}" -o -d "$_EXEC/pages/${PATH_INFO}" ]; then
152 REDIRECT "${_BASE}${PATH_INFO}/"
153 elif [ "${PATH_INFO%\[*\]}" = "${PATH_INFO}" ]; then