]> git.plutz.net Git - rawnet/blob - upload.sh
ignore transcoding status files
[rawnet] / upload.sh
1 #!/bin/sh
2
3 [ "$include_upload" ] && return 0
4 include_upload="$0"
5
6 UPLOAD(){
7   local file="$1"
8   local boundary line length=0
9
10   [ ! "${CONTENT_TYPE}" -o "${CONTENT_TYPE##multipart/form-data;*}" ] && return 1
11
12   boundary="${CONTENT_TYPE#*; boundary=}"
13   boundary="${boundary%%;*}"
14
15   while read -r line; do
16     length="$(( length + ${#line} + 1))"
17     [ "${line%${CR}}" = "--$boundary" ] && break
18   done
19   while read -r line; do
20     length="$(( length + ${#line} + 1))"
21     [ ! "${line%${CR}}" ] && break \
22     || debug "$line"
23   done
24
25   printf "%i\n" "$(( CONTENT_LENGTH - length ))" >"${file}.upload"
26   head -c "$(( CONTENT_LENGTH - length ))" \
27   | sed -nE '
28     # print lines until boundary ( = actual file upload)
29     :FILE; p; n;
30     /^--'"${boundary}"'(--)?\r?$/!bFILE;
31     # discard remaining lines
32     :END; $q; n; bEND;
33   ' >"$file"
34   truncate -s $(( $(stat -c %s -- "$file") -2 )) -- "$file"
35   rm -- "${file}.upload"
36 }
37
38 frame_uploadprogress() {
39   printf '<!DOCTYPE HTML>
40   <html><head>
41     <title>Upload Progress</title>
42     <link rel="stylesheet" type="text/css" href="%s/rawnet.css" />
43   </head><body id=uploadprogress>
44   ' "$_BASE"
45   printf '<div class=progress><div class=bar style="width: 0%%;"></div><div class=count>%i / %i</div></div>\n' 0 0
46   while [  ! -f "${VIDEO_FILE}" -a ! -f "${VIDEO_FILE}.upload" ]; do
47     sleep 1
48   done
49   read size <"${VIDEO_FILE}.upload"
50   while [ -f "${VIDEO_FILE}.upload" ]; do
51     stat="$(stat -c %s "$VIDEO_FILE" 2>&-)"
52     printf '<div class=progress><div class=bar style="width:%i%%;"></div><div class=count>%iMB / %iMB</div></div>\n' \
53       "$(( stat * 100 / size ))" "$((stat / 1048576))" "$((size / 1048576))"
54     sleep 1
55   done
56   printf '<span class=progress><div class=bar style="width:100%%;"></div><div class=count>Ready!</div></span>\n'
57   printf '</body></html>'
58 }