rm -- "${file}.upload"
}
+base16(){
+ local num="$1"
+ case $num in
+ [0-9]) printf %i "$num";;
+ 10) printf a;;
+ 11) printf b;;
+ 12) printf c;;
+ 13) printf d;;
+ 14) printf e;;
+ 15) printf f;;
+ *) printf '%s%s' "$(base16 $((num / 16)))" "$(base16 $((num % 16)))"
+ esac
+}
+
+HTTP_CHUNK(){
+ local chunk="$*"
+ printf '%s\r\n%s\r\n' "$(base16 "${#chunk}")" "$chunk"
+}
+
frame_uploadprogress() {
- printf '<!DOCTYPE HTML>
- <html><head>
- <title>Upload Progress</title>
- <link rel="stylesheet" type="text/css" href="%s/rawnet.css" />
- </head><body id=uploadprogress>
- ' "$_BASE"
- printf '<div class=progress><div class=bar style="width: 0%%;"></div><div class=count>%i / %i</div></div>\n' 0 0
+ printf '%s: %s\r\n' "Content-Type" "text/html" "Transfer-Encoding" "chunked"
+ printf '\r\n'
+
+ HTTP_CHUNK "<!DOCTYPE HTML>
+ " "<html><head>
+ <title>Upload Progress</title>
+ <!-- <link rel=\"stylesheet\" type=\"text/css\" href=\"$_BASE/rawnet.css\" /> -->
+ <style type=\"text/css\"><!--
+ #uploadprogress {
+ text-align: center;
+ background: transparent;
+ margin: 0;
+ }
+ #uploadprogress .progress {
+ display: block;
+ position: absolute;
+ top: 0;
+ width: 99%; width: calc(100% - 2pt);
+ background-color: #FFF;
+ border: 1pt solid;
+ border-radius: 4pt;
+ height: 1.25em;
+ }
+ #uploadprogress .progress .bar {
+ display: block;
+ position: absolute;
+ left: 0; top: 0; bottom: 0;
+ background-color: #666;
+ }
+ #uploadprogress .progress .count {
+ display: block;
+ position: absolute;
+ left: 0; top: 0; right: 0; bottom: 0;
+ line-height: 1.375em;
+ }
+ --></style>
+ " "</head><body id=uploadprogress>
+ "
+ HTTP_CHUNK ' <div class=progress><div class=bar style="width: 0%;"></div><div class=count>0 / 0</div></div>'
while [ ! -f "${VIDEO_FILE}" -a ! -f "${VIDEO_FILE}.upload" ]; do
sleep 1
done
read size <"${VIDEO_FILE}.upload" 2>&-
while [ -f "${VIDEO_FILE}.upload" ]; do
stat="$(stat -c %s "$VIDEO_FILE" 2>&-)"
- printf '<div class=progress><div class=bar style="width:%i%%;"></div><div class=count>%iMB / %iMB</div></div>\n' \
- "$(( stat * 100 / size ))" "$((stat / 1048576))" "$((size / 1048576))"
+ HTTP_CHUNK " <div class=progress><div class=bar style=\"width:$(( stat * 100 / size))%;\">" \
+ "</div><div class=count>$((stat / 1048576))MB / $((size / 1048576))MB</div></div>" "$BR"
sleep 1
done
- printf '<span class=progress><div class=bar style="width:100%%;"></div><div class=count>Ready!</div></span>\n'
- printf '</body></html>'
+ HTTP_CHUNK ' <div class=progress><div class=bar style="width:100%%;"></div><div class=count>Ready!</div></div>' "$BR" \
+ '</body></html>'
+ HTTP_CHUNK ''
}