From 2adea9f215c202bd7054ffdb0b379f4cf1db3fd1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Wed, 3 Nov 2021 10:19:40 +0100 Subject: [PATCH] For progress frame use chunked encoding instead of long poll --- page_video.sh | 1 - upload.sh | 74 +++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 63 insertions(+), 12 deletions(-) diff --git a/page_video.sh b/page_video.sh index e69089e..3215bbb 100755 --- a/page_video.sh +++ b/page_video.sh @@ -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 diff --git a/upload.sh b/upload.sh index 0571b18..f24a8d7 100755 --- 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 ' - - Upload Progress - - - ' "$_BASE" - printf '
%i / %i
\n' 0 0 + printf '%s: %s\r\n' "Content-Type" "text/html" "Transfer-Encoding" "chunked" + printf '\r\n' + + HTTP_CHUNK " + " " + Upload Progress + + + " " + " + HTTP_CHUNK '
0 / 0
' 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 '
%iMB / %iMB
\n' \ - "$(( stat * 100 / size ))" "$((stat / 1048576))" "$((size / 1048576))" + HTTP_CHUNK "
" \ + "
$((stat / 1048576))MB / $((size / 1048576))MB
" "$BR" sleep 1 done - printf '
Ready!
\n' - printf '' + HTTP_CHUNK '
Ready!
' "$BR" \ + '' + HTTP_CHUNK '' } -- 2.39.2