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
42 ( ffmpeg -y -nostdin -i "$attpath" \
43 -c:v libvpx -vf scale=1280:-2 -crf 28 -b:v 0 \
44 -c:a libvorbis -q:a 6 \
45 "${cachepath%.*}.tmp.webm" \
46 && mv -- "${cachepatch%.*}.tmp.webm" "${cachepath}" \
50 ( ffmpeg -y -nostdin -i "$attpath" \
51 -c:v libvpx -crf 28 -b:v 0 \
52 -c:a libvorbis -q:a 6 \
53 "${cachepath%.*}.tmp.webm" \
54 && mv -- "${cachepatch%.*}.tmp.webm" "${cachepath}" \
63 if [ "${PATH_INFO%/\[attachment\]/}" != "${PATH_INFO}" ]; then
64 . "$_EXEC/multipart.sh"
65 if multipart_cache; then
66 mkdir -p "$_DATA/pages/${PATH_INFO%/\[attachment\]/}/#attachments/"
67 n=1; while filename=$(multipart_filename "file" "$n"); do
68 filename="$(printf %s "$filename" |tr /\\0 __)"
69 multipart "file" "$n" >"$_DATA/pages/${PATH_INFO%/\[attachment\]/}/#attachments/$filename"
72 rm -- "$multipart_cachefile"
73 REDIRECT "${_BASE}${PATH_INFO}"
75 theme_attachments "${PATH_INFO%\[attachment\]/}"
78 elif [ "${PATH_INFO%/\[attachment\]/*}" != "${PATH_INFO}" ]; then
79 attpath="${PATH_INFO%/\[attachment\]/*}/#attachments/${PATH_INFO##*/}"
80 if [ -f "$_DATA/pages/$attpath" ]; then
81 FILE "$_DATA/pages/$attpath"
82 elif [ -f "$_EXEC/pages/$attpath" ]; then
83 FILE "$_EXEC/pages/$attpath"
89 elif [ "${PATH_INFO%/}" = "${PATH_INFO}" ]; then
90 attpath="${PATH_INFO%/*}/#attachments/${PATH_INFO##*/}"
91 if [ -f "$_DATA/pages/$attpath" ]; then
92 FILE "$(attachment_convert "$_DATA/pages/$attpath")"
93 elif [ -f "$_EXEC/pages/$attpath" ]; then
94 FILE "$(attachment_convert "$_EXEC/pages/$attpath")"
95 elif [ -d "$_DATA/pages/${PATH_INFO}" -o -d "$_EXEC/pages/${PATH_INFO}" ]; then
96 REDIRECT "${_BASE}${PATH_INFO}/"