]> git.plutz.net Git - rawnet/commitdiff
upload function to external file, ui change: put video upload before meta edit
authorPaul Hänsch <paul@plutz.net>
Thu, 21 Oct 2021 14:17:25 +0000 (16:17 +0200)
committerPaul Hänsch <paul@plutz.net>
Thu, 21 Oct 2021 14:17:25 +0000 (16:17 +0200)
page_channel.sh
page_video.sh
rawnet.css
upload.sh [new file with mode: 0755]

index 09fae095baf1aae17471098c916047303e1d2283..a1e0161d95c9fa90a952803aed48300d313a4dac 100755 (executable)
@@ -75,7 +75,7 @@ AUTHOR(){
     elif ! AUTHOR; then
       REDIRECT "${_BASE}/channel/${channel}/#ERROR_UPDATE_NOTALLOWED"
     elif new_video "$video"; then
-      REDIRECT "${_BASE}/channel/${channel}/${video}/edit"
+      REDIRECT "${_BASE}/channel/${channel}/${video}/"
     else
       REDIRECT "${_BASE}/channel/${channel}/#ERROR_NEWVIDEO_NOLOCK"
     fi
index 587ee526f18e0b1b72d7043c990519756e02538b..28061c2e18f458aa32ae8d9ab6badb7ba05dc21a 100755 (executable)
@@ -1,41 +1,10 @@
 #!/bin/sh
 
 . "$_EXEC/db_video.sh"
+. "$_EXEC/upload.sh"
 
 read_video "$video"
 
-UPLOAD(){
-  local file="$1"
-  local boundary line length=0
-
-  [ ! "${CONTENT_TYPE}" -o "${CONTENT_TYPE##multipart/form-data;*}" ] && return 1
-
-  boundary="${CONTENT_TYPE#*; boundary=}"
-  boundary="${boundary%%;*}"
-
-  while read -r line; do
-    length="$(( length + ${#line} + 1))"
-    [ "${line%${CR}}" = "--$boundary" ] && break
-  done
-  while read -r line; do
-    length="$(( length + ${#line} + 1))"
-    [ ! "${line%${CR}}" ] && break \
-    || debug "$line"
-  done
-
-  printf "%i\n" "$(( CONTENT_LENGTH - length ))" >"${file}.upload"
-  head -c "$(( CONTENT_LENGTH - length ))" \
-  | sed -nE '
-    # print lines until boundary ( = actual file upload)
-    :FILE; p; n;
-    /^--'"${boundary}"'(--)?\r?$/!bFILE;
-    # discard remaining lines
-    :END; $q; n; bEND;
-  ' >"$file"
-  truncate -s $(( $(stat -c %s -- "$file") -2 )) -- "$file"
-  rm -- "${file}.upload"
-}
-
 [ "$REQUEST_METHOD" = POST ] && case "$(POST action)" in
   update_video)
     if [ ! "$USER_ID" ]; then
@@ -79,6 +48,7 @@ if [ "$REQUEST_METHOD" = POST -a "$channel" -a "$video" ]; then
   elif UPLOAD "$_DATA/$channel/$video.mp4"; then
     update_video "$video" status=private
     VIDEO_STATUS=private
+    REDIRECT "${_BASE}/channel/${channel}/${video}/edit"
   fi
 fi
 
@@ -110,72 +80,7 @@ if [ "$channel" -a "$video" -a "$action" = edit ]; then
 elif [ "$channel" -a "$video" -a "$action" = frameuploadprogress ]; then
   AUTHOR || REDIRECT "$_BASE/$channel/$video/#ERROR_EDIT_NOTALLOWED"
   printf '%s\r\n' 'Content-Type: text/html' 'Connection: close' ''
-  printf '<!DOCTYPE HTML>
-  <html><head>
-    <title>Upload Progress</title>
-    <style type="text/css"><!--
-    body {
-      text-align: center;
-    }
-    .progress {
-      display: block;
-      position: absolute;
-      width: 20em;
-      background-color: #FFF;
-      border: 1pt solid;
-      border-radius: 4pt;
-      height: 1.25em;
-    }
-    .progress .bar {
-      display: block;
-      position: absolute;
-      left: 0; top: 0; bottom: 0;
-      background-color: #666;
-    }
-    .progress .count {
-      display: block;
-      position: absolute;
-      left: 0; top: 0; right: 0; bottom: 0;
-      line-height: 1.375em;
-    }
-    --></style>
-  </head><body>
-  '
-  printf '<div class=progress><div class=bar style="width: 0%%;"></div><div class=count>%i / %i</div></div>\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 '<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))"
-    sleep 1
-  done
-  printf '<span class=progress><div class=bar style="width:100%%;"></div><div class=count>Ready!</div></span>\n'
-  printf '</body></html>'
-
-elif [ "$channel" -a "$video" -a "$action" = frameupload ]; then
-  AUTHOR || REDIRECT "$_BASE/$channel/$video/#ERROR_EDIT_NOTALLOWED"
-  printf '%s\r\n' 'Content-Type: text/html' ''
-  [ "$VIDEO_STATUS" = void ] && "$_EXEC"/cgilite/html-sh.sed <<-EOF
-       [!DOCTYPE HTML]
-       [html [head
-         [title Upload Form]
-       ][body
-       [form .upload method=POST enctype="multipart/form-data"
-         [input type=file name=upload]
-         [submit "action" "video_upload" Upload]
-       ]
-       ]]
-       EOF
-  [ "$VIDEO_STATUS" != void ] && "$_EXEC"/cgilite/html-sh.sed <<-EOF
-       [!DOCTYPE HTML]
-       [html [head
-         [title Upload Form]
-       ][body
-         [a href="./" target="_parent" . Reload Page!]
-       ]]
-       EOF
+  frame_uploadprogress
 
 elif [ "$channel" -a "$video" ]; then
   [ $VIDEO_STATUS = public -o $VIDEO_STATUS = hidden ] || AUTHOR || { . ${_EXEC}/page_404.sh; exit 0; }
@@ -186,11 +91,9 @@ elif [ "$channel" -a "$video" ]; then
         [iframe src="frameuploadprogress" width="100%%" height="50"
          [a href="freameuploadprogress" Iframe: Upload progress]
        ]
-       [iframe src="frameupload" width="100%%" height="50"
-         [form .upload method=POST enctype="multipart/form-data"
-           [input type=file name=upload]
-           [submit "action" "video_upload" Upload]
-         ]
+       [form .upload method=POST enctype="multipart/form-data"
+         [input type=file name=upload]
+         [submit "action" "video_upload" Upload]
        ]')
        $( [ $VIDEO_STATUS != void ] && printf '
        [video preload=none controls=controls width=%i height=%i
index 320ec9a62e228fc56931ba55a7802e586b5c7497..5fa017b12fd6dadb14824cb9f3856e89395e622c 100644 (file)
@@ -96,7 +96,9 @@ body.channel main h1.name {
   text-align: center;
 }
 body main .description,
-body main form {
+body main form,
+body main iframe {
+  display: block;
   max-width: 40em;
   margin: auto;
 }
@@ -238,3 +240,30 @@ body.video video {
   margin: 0 auto;
   max-height: 80vh;
 }
+
+#uploadprogress {
+  text-align: center;
+  background: transparent;
+  margin: 0;
+}
+#uploadprogress .progress {
+  display: block;
+  position: absolute;
+  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;
+}
diff --git a/upload.sh b/upload.sh
new file mode 100755 (executable)
index 0000000..dd678fe
--- /dev/null
+++ b/upload.sh
@@ -0,0 +1,54 @@
+#!/bin/sh
+
+UPLOAD(){
+  local file="$1"
+  local boundary line length=0
+
+  [ ! "${CONTENT_TYPE}" -o "${CONTENT_TYPE##multipart/form-data;*}" ] && return 1
+
+  boundary="${CONTENT_TYPE#*; boundary=}"
+  boundary="${boundary%%;*}"
+
+  while read -r line; do
+    length="$(( length + ${#line} + 1))"
+    [ "${line%${CR}}" = "--$boundary" ] && break
+  done
+  while read -r line; do
+    length="$(( length + ${#line} + 1))"
+    [ ! "${line%${CR}}" ] && break \
+    || debug "$line"
+  done
+
+  printf "%i\n" "$(( CONTENT_LENGTH - length ))" >"${file}.upload"
+  head -c "$(( CONTENT_LENGTH - length ))" \
+  | sed -nE '
+    # print lines until boundary ( = actual file upload)
+    :FILE; p; n;
+    /^--'"${boundary}"'(--)?\r?$/!bFILE;
+    # discard remaining lines
+    :END; $q; n; bEND;
+  ' >"$file"
+  truncate -s $(( $(stat -c %s -- "$file") -2 )) -- "$file"
+  rm -- "${file}.upload"
+}
+
+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
+  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 '<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))"
+    sleep 1
+  done
+  printf '<span class=progress><div class=bar style="width:100%%;"></div><div class=count>Ready!</div></span>\n'
+  printf '</body></html>'
+}