]> git.plutz.net Git - rawnet/commitdiff
For progress frame use chunked encoding instead of long poll master
authorPaul Hänsch <paul@plutz.net>
Wed, 3 Nov 2021 09:19:40 +0000 (10:19 +0100)
committerPaul Hänsch <paul@plutz.net>
Wed, 3 Nov 2021 09:19:40 +0000 (10:19 +0100)
page_video.sh
upload.sh

index e69089e058424df87a2013a3c0b08689aa04848d..3215bbb30d7a57237868eea8b617df14ab52774b 100755 (executable)
@@ -86,7 +86,6 @@ if [ "$CHANNEL_ID" -a "$VIDEO_ID" -a "$action" = edit ]; then
 
 elif [ "$CHANNEL_ID" -a "$VIDEO_ID" -a "$action" = frameuploadprogress ]; then
   AUTHOR || REDIRECT "$_BASE/$CHANNEL_ID/$VIDEO_ID/#ERROR_EDIT_NOTALLOWED"
-  printf '%s\r\n' 'Content-Type: text/html' 'Connection: close' ''
   frame_uploadprogress
 
 elif [ "$CHANNEL_ID" -a "$VIDEO_ID" -a ! -f "$VIDEO_FILE" ] && AUTHOR; then
index 0571b186926ee8eb2ab0f1f7e1be4eb232fc6c7b..f24a8d76b721dfcfdbbfe9b7e271047c8f6f851e 100755 (executable)
--- a/upload.sh
+++ b/upload.sh
@@ -35,24 +35,76 @@ UPLOAD(){
   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 ''
 }