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}" \
64 *) printf "$attpath";;
71 REDIRECT "${_BASE}${PATH_INFO%/}"
74 # attached files never end on /
78 # show attachment page
80 tsid="$(POST session_key)"; tsid="${tsid%% *}"
81 attachment_delete="$(POST delete)"
82 page="${PATH_INFO%\[attachment\]}"
84 if [ ! -d "$_DATA/pages${page}" -a ! -d "$_DATA/pages${page}" ]; then
85 # base page does not exist
87 elif [ "${CONTENT_TYPE%%;*}" = "multipart/form-data" ] && acl_write "${page}"; then
88 . "$_EXEC/multipart.sh"
91 # Validate session id from form to prevent CSRF
92 # Only validate if username is present, because no username means
93 # anonymous uploads are allowed via acl and cgilite/session.sh does not
94 # validate anonymous sessions from a multipart/formdata
95 if [ "$USER_NAME" -a "$(multipart session_id)" != "$SESSION_ID" ]; then
96 rm -- "$multipart_cachefile"
97 printf 'Refresh: %i\r\n' 4
102 mkdir -p "$_DATA/pages${page}#attachments/"
103 n=1; while filename=$(multipart_filename "file" "$n"); do
104 filename="$(printf %s "$filename" |tr /\\0 __)"
105 multipart "file" "$n" >"$_DATA/pages${page}#attachments/$filename"
108 rm -- "$multipart_cachefile"
109 REDIRECT "${_BASE}${PATH_INFO}"
110 elif [ "${CONTENT_TYPE%%;*}" = "multipart/form-data" ]; then
111 printf 'Refresh: %i\r\n' 4
113 head -c $((CONTENT_LENGTH)) >/dev/null
115 elif [ "$attachment_delete" -a "$SESSION_ID" = "$tsid" ]; then
116 rm -- "$_DATA/pages${page}#attachments/$attachment_delete"
117 REDIRECT "${_BASE}${PATH_INFO}"
118 elif [ "$attachment_delete" ]; then
119 printf 'Refresh: %i\r\n' 4
122 elif ! acl_read "${page}"; then
126 theme_attachments "${page}"
132 attpath="${PATH_INFO%/\[attachment\]/*}/#attachments/${PATH_INFO##*/}"
134 if [ ! -f "$_DATA/pages/$attpath" -a ! -f "$_EXEC/pages/$attpath" ]; then
136 elif ! acl_read "${PATH_INFO%/\[attachment\]/*}"; then
139 elif [ -f "$_DATA/pages/$attpath" ]; then
140 FILE "$_DATA/pages/$attpath"
142 elif [ -f "$_EXEC/pages/$attpath" ]; then
143 FILE "$_EXEC/pages/$attpath"
148 attpath="${PATH_INFO%/*}/#attachments/${PATH_INFO##*/}"
150 if [ ! -f "$_DATA/pages/$attpath" -a ! -f "$_EXEC/pages/$attpath" ]; then
152 elif ! acl_read "${PATH_INFO%/*}/"; then
155 elif [ -f "$_DATA/pages/$attpath" ]; then
156 FILE "$(attachment_convert "$_DATA/pages/$attpath")"
158 elif [ -f "$_EXEC/pages/$attpath" ]; then
159 FILE "$(attachment_convert "$_EXEC/pages/$attpath")"