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 tsid="$(POST session_key)"; tsid="${tsid%% *}"
70 attachment_delete="$(POST delete)"
72 if [ "${CONTENT_TYPE%%;*}" = "multipart/form-data" ] && acl_write "${PATH_INFO%\[attachment\]/}"; then
73 . "$_EXEC/multipart.sh"
76 # Validate session id from form to prevent CSRF
77 # Only validate if username is present, because no username means
78 # anonymous uploads are allowed via acl and cgilite/session.sh does not
79 # validate anonymous sessions from a multipart/formdata
80 if [ "$USER_NAME" -a "$(multipart session_id)" != "$SESSION_ID" ]; then
81 rm -- "$multipart_cachefile"
82 printf 'Refresh: %i\r\n' 4
87 mkdir -p "$_DATA/pages/${PATH_INFO%/\[attachment\]/}/#attachments/"
88 n=1; while filename=$(multipart_filename "file" "$n"); do
89 filename="$(printf %s "$filename" |tr /\\0 __)"
90 multipart "file" "$n" >"$_DATA/pages/${PATH_INFO%/\[attachment\]/}/#attachments/$filename"
93 rm -- "$multipart_cachefile"
94 REDIRECT "${_BASE}${PATH_INFO}"
95 elif [ "${CONTENT_TYPE%%;*}" = "multipart/form-data" ]; then
96 printf 'Refresh: %i\r\n' 4
98 head -c $((CONTENT_LENGTH)) >/dev/null
100 elif [ "$attachment_delete" -a "$SESSION_ID" = "$tsid" ]; then
101 rm -- "$_DATA/pages/${PATH_INFO%/\[attachment\]/}/#attachments/$attachment_delete"
102 REDIRECT "${_BASE}${PATH_INFO}"
103 elif [ "$attachment_delete" ]; then
104 printf 'Refresh: %i\r\n' 4
107 elif acl_read "${PATH_INFO%\[attachment\]/}"; then
108 theme_attachments "${PATH_INFO%\[attachment\]/}"
117 attpath="${PATH_INFO%/\[attachment\]/*}/#attachments/${PATH_INFO##*/}"
119 if ! acl_read "${PATH_INFO%/\[attachment\]/*}"; then
122 elif [ -f "$_DATA/pages/$attpath" ]; then
123 FILE "$_DATA/pages/$attpath"
125 elif [ -f "$_EXEC/pages/$attpath" ]; then
126 FILE "$_EXEC/pages/$attpath"
137 attpath="${PATH_INFO%/*}/#attachments/${PATH_INFO##*/}"
139 if ! acl_read "${PATH_INFO%/*}/"; then
142 elif [ -f "$_DATA/pages/$attpath" ]; then
143 FILE "$(attachment_convert "$_DATA/pages/$attpath")"
145 elif [ -f "$_EXEC/pages/$attpath" ]; then
146 FILE "$(attachment_convert "$_EXEC/pages/$attpath")"
148 elif [ -d "$_DATA/pages/${PATH_INFO}" -o -d "$_EXEC/pages/${PATH_INFO}" ]; then
149 REDIRECT "${_BASE}${PATH_INFO}/"
150 elif [ "${PATH_INFO%\[*\]}" = "${PATH_INFO}" ]; then