X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;f=upload.sh;h=f24a8d76b721dfcfdbbfe9b7e271047c8f6f851e;hb=HEAD;hp=dd678fef8a6aa4020b0f623b2b82e6139e0d3e20;hpb=74cc921e6bcc52387f4e652f0d95f67eb9edfd50;p=rawnet
diff --git a/upload.sh b/upload.sh
index dd678fe..f24a8d7 100755
--- a/upload.sh
+++ b/upload.sh
@@ -1,5 +1,8 @@
#!/bin/sh
+[ "$include_upload" ] && return 0
+include_upload="$0"
+
UPLOAD(){
local file="$1"
local boundary line length=0
@@ -32,23 +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 '\n' 0 0
- while [ ! -f "$_DATA/$channel/$video.mp4" -a \
- ! -f "$_DATA/$channel/$video.mp4.upload" ]; do sleep 1; done
- read size <"$_DATA/$channel/$video.mp4.upload"
- while [ -f "$_DATA/$channel/$video.mp4.upload" ]; do
- stat="$(stat -c %s "$_DATA/$channel/$video.mp4" 2>&-)"
- printf '\n' \
- "$(( stat * 100 / size ))" "$((stat / 1048576))" "$((size / 1048576))"
+ printf '%s: %s\r\n' "Content-Type" "text/html" "Transfer-Encoding" "chunked"
+ printf '\r\n'
+
+ HTTP_CHUNK "
+ " "
+ Upload Progress
+
+
+ " "
+ "
+ HTTP_CHUNK ' '
+ 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>&-)"
+ HTTP_CHUNK " " \
+ "
$((stat / 1048576))MB / $((size / 1048576))MB
" "$BR"
sleep 1
done
- printf 'Ready!
\n'
- printf ''
+ HTTP_CHUNK ' ' "$BR" \
+ ''
+ HTTP_CHUNK ''
}