5 local boundary line length=0
7 [ ! "${CONTENT_TYPE}" -o "${CONTENT_TYPE##multipart/form-data;*}" ] && return 1
9 boundary="${CONTENT_TYPE#*; boundary=}"
10 boundary="${boundary%%;*}"
12 while read -r line; do
13 length="$(( length + ${#line} + 1))"
14 [ "${line%${CR}}" = "--$boundary" ] && break
16 while read -r line; do
17 length="$(( length + ${#line} + 1))"
18 [ ! "${line%${CR}}" ] && break \
22 printf "%i\n" "$(( CONTENT_LENGTH - length ))" >"${file}.upload"
23 head -c "$(( CONTENT_LENGTH - length ))" \
25 # print lines until boundary ( = actual file upload)
27 /^--'"${boundary}"'(--)?\r?$/!bFILE;
28 # discard remaining lines
31 truncate -s $(( $(stat -c %s -- "$file") -2 )) -- "$file"
32 rm -- "${file}.upload"
35 frame_uploadprogress() {
36 printf '<!DOCTYPE HTML>
38 <title>Upload Progress</title>
39 <link rel="stylesheet" type="text/css" href="%s/rawnet.css" />
40 </head><body id=uploadprogress>
42 printf '<div class=progress><div class=bar style="width: 0%%;"></div><div class=count>%i / %i</div></div>\n' 0 0
43 while [ ! -f "$_DATA/$channel/$video.mp4" -a \
44 ! -f "$_DATA/$channel/$video.mp4.upload" ]; do sleep 1; done
45 read size <"$_DATA/$channel/$video.mp4.upload"
46 while [ -f "$_DATA/$channel/$video.mp4.upload" ]; do
47 stat="$(stat -c %s "$_DATA/$channel/$video.mp4" 2>&-)"
48 printf '<div class=progress><div class=bar style="width:%i%%;"></div><div class=count>%iMB / %iMB</div></div>\n' \
49 "$(( stat * 100 / size ))" "$((stat / 1048576))" "$((size / 1048576))"
52 printf '<span class=progress><div class=bar style="width:100%%;"></div><div class=count>Ready!</div></span>\n'
53 printf '</body></html>'