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}" \
70 REDIRECT "${_BASE}${PATH_INFO%/}"
73 # attached files never end on /
77 # show attachment page
79 tsid="$(POST session_key)"; tsid="${tsid%% *}"
80 attachment_delete="$(POST delete)"
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" ] && acl_write "${page}"; then
87 . "$_EXEC/multipart.sh"
90 # Validate session id from form to prevent CSRF
91 # Only validate if username is present, because no username means
92 # anonymous uploads are allowed via acl and cgilite/session.sh does not
93 # validate anonymous sessions from a multipart/formdata
94 if [ "$USER_NAME" -a "$(multipart session_id)" != "$SESSION_ID" ]; then
95 rm -- "$multipart_cachefile"
96 printf 'Refresh: %i\r\n' 4
101 mkdir -p "$_DATA/pages${page}#attachments/"
102 n=1; while filename=$(multipart_filename "file" "$n"); do
103 filename="$(printf %s "$filename" |tr /\\0 __)"
104 multipart "file" "$n" >"$_DATA/pages${page}#attachments/$filename"
107 rm -- "$multipart_cachefile"
108 REDIRECT "${_BASE}${PATH_INFO}"
109 elif [ "${CONTENT_TYPE%%;*}" = "multipart/form-data" ]; then
110 printf 'Refresh: %i\r\n' 4
112 head -c $((CONTENT_LENGTH)) >/dev/null
114 elif [ "$attachment_delete" -a "$SESSION_ID" = "$tsid" ]; then
115 rm -- "$_DATA/pages${page}#attachments/$attachment_delete"
116 REDIRECT "${_BASE}${PATH_INFO}"
117 elif [ "$attachment_delete" ]; then
118 printf 'Refresh: %i\r\n' 4
121 elif ! acl_read "${page}"; then
125 theme_attachments "${page}"
131 attpath="${PATH_INFO%/\[attachment\]/*}/#attachments/${PATH_INFO##*/}"
133 if [ ! -f "$_DATA/pages/$attpath" -a ! -f "$_EXEC/pages/$attpath" ]; then
135 elif ! acl_read "${PATH_INFO%/\[attachment\]/*}"; then
138 elif [ -f "$_DATA/pages/$attpath" ]; then
139 FILE "$_DATA/pages/$attpath"
141 elif [ -f "$_EXEC/pages/$attpath" ]; then
142 FILE "$_EXEC/pages/$attpath"
147 attpath="${PATH_INFO%/*}/#attachments/${PATH_INFO##*/}"
149 if [ ! -f "$_DATA/pages/$attpath" -a ! -f "$_EXEC/pages/$attpath" ]; then
151 elif ! acl_read "${PATH_INFO%/*}/"; then
154 elif [ -f "$_DATA/pages/$attpath" ]; then
155 FILE "$(attachment_convert "$_DATA/pages/$attpath")"
157 elif [ -f "$_EXEC/pages/$attpath" ]; then
158 FILE "$(attachment_convert "$_EXEC/pages/$attpath")"