]> git.plutz.net Git - rawnet/blobdiff - page_video.sh
upload function to external file, ui change: put video upload before meta edit
[rawnet] / page_video.sh
old mode 100644 (file)
new mode 100755 (executable)
index ef9a82e..28061c2
@@ -1,57 +1,20 @@
 #!/bin/sh
 
-if [ "$video" -a -f "$vid_db" -a -r "$vid_db" ]; then
-  read -r VIDEO_ID VIDEO_NAME VIDEO_DESCRIPTION VIDEO_RESX VIDEO_RESY \
-          VIDEO_LENGTH VIDEO_COVER VIDEO_STATUS VIDEO_UPLOADER VIDEO_HITS \
-          VIDEO_DESCR_CACHE VIDEO_FUTUREUSE <<-EOF
-       $(grep "^${video}       " "${vid_db}")
-       EOF
-  if [ "$VIDEO_ID" ]; then
-           VIDEO_NAME="$(UNSTRING "$VIDEO_NAME")"
-    VIDEO_DESCRIPTION="$(UNSTRING "$VIDEO_DESCRIPTION")"
-    VIDEO_DESCR_CACHE="$(UNSTRING "$VIDEO_DESCR_CACHE")"
-  else
-    video=''
-  fi
-fi
-
-# Video
-# ID   NAME    DESCRIPTION     RESX    RESY    LENGTH  COVER   STATUS (void|private|hidden|public)     UPLOADER        HITS    DESCR_CACHE     FUTUREUSE
-
-update_video(){
-  local id="${1}" name="${2}" description="${3}" resx="${4}" resy="${5}" \
-        length="${6}" cover="${7}" status="${8}" uploader="${9}" \
-        hits="${10}" descr_cache="${11}" futureuse="${12}"
-  local ID INFO
-
-  if LOCK "$vid_db"; then
-    while read -r ID INFO; do
-      if [ "$id" = "$ID" ]; then
-                # ID   NAME    DESCRIPTION RESX RESY   LENGTH  COVER   STATUS  UPLOADER HITS   DESCR_CACHE     FUTUREUSE
-        printf '%s     %s      %s      %i      %i      %i      %s      %s      %s      %i      %s      %s\n' \
-               "$id" "$(STRING "$name")" "$(STRING "$description")" "$resx" "$resy" "$length" \
-               "$(STRING "$cover")" "${status:-void}" "${uploader:-\\}" "$hits" \
-               "$(printf %s "$description" |markdown |STRING)" "${futureuse:-\\}"
-      else
-        printf '%s     %s\n' "$ID" "$INFO"
-      fi
-    done <"$vid_db" >"${vid_db}.$$"
-    mv -- "${vid_db}.$$" "${vid_db}"
-    RELEASE "$vid_db"
-  else
-    return 1
-  fi
-}
+. "$_EXEC/db_video.sh"
+. "$_EXEC/upload.sh"
 
+read_video "$video"
 
 [ "$REQUEST_METHOD" = POST ] && case "$(POST action)" in
   update_video)
     if [ ! "$USER_ID" ]; then
       REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_NOTLOGGEDIN"
-    elif [ "${CHANNEL_AUTHORS##*${USER_ID}*}" ]; then
+    elif ! AUTHOR; then
       REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_UPDATE_NOTALLOWED"
-    elif update_video "$video" "$(POST name)" "$(POST description)" 0 0 0 \
-                      "" "void" "$USER_ID" 0 ""; then
+    elif update_video "$video" "name=$(POST name)" \
+                      "description=$(POST description)" \
+                      "status=$(POST status |grep -m1 -xE 'void|private|hidden|public')" \
+                      "uploader=$USER_ID"; then
       REDIRECT "${_BASE}/channel/${channel}/${video}/#UPDATE_SUCCESS"
     else
       REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_UPDATE_NOLOCK"
@@ -60,35 +23,88 @@ update_video(){
   update_video_cancel)
     REDIRECT "${_BASE}/channel/${channel}/${video}/#CANCELED"
     ;;
+  delete)
+    if [ ! "$USER_ID" ]; then
+      REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_NOTLOGGEDIN"
+    elif ! AUTHOR; then
+      REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_UPDATE_NOTALLOWED"
+    elif [ "$(POST delconfirm)" != confirm ]; then
+      REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_NOT_CONFIRMED"
+    elif delete_video "$video"; then
+      REDIRECT "${_BASE}/channel/${channel}/#DELETE_CONFIRM"
+    else
+      REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_UPDATE_NOLOCK"
+    fi
+    ;;
 esac
 
+if [ "$REQUEST_METHOD" = POST -a "$channel" -a "$video" ]; then
+  if ! AUTHOR; then
+    head -c "$CONTENT_LENGTH" >/dev/null
+    REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_UPLOAD_NOTALLOWED"
+  elif [ "$VIDEO_STATUS" != void ]; then
+    head -c "$CONTENT_LENGTH" >/dev/null
+    REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_UPLOAD_NOCLOBBER"
+  elif UPLOAD "$_DATA/$channel/$video.mp4"; then
+    update_video "$video" status=private
+    VIDEO_STATUS=private
+    REDIRECT "${_BASE}/channel/${channel}/${video}/edit"
+  fi
+fi
+
 if [ "$channel" -a "$video" -a "$action" = edit ]; then
+  AUTHOR || REDIRECT "$_BASE/$channel/$video/#ERROR_EDIT_NOTALLOWED"
+
   yield_page "$VIDEO_NAME - Edit" "video edit" <<-EOF
        [form .video .edit method=POST
          [input name="name" value="$(HTML "$VIDEO_NAME")" placeholder="Video Name"]
          [fieldset .status $([ $VIDEO_STATUS = void ] && printf "disabled=disabled")
-           [radio "status" "void" #status_private $(checked $VIDEO_STATUS private void)]
+           [radio "status" "private" #status_private $(checked $VIDEO_STATUS private void)]
              [label for=status_private tooltip="Video is only visible to channel authors" Private]
-           [radio "status" "void" #status_hidden  $(checked $VIDEO_STATUS hidden)]
+           [radio "status" "hidden" #status_hidden  $(checked $VIDEO_STATUS hidden)]
              [label for=status_hidden tooltip="Video will not be listed but can be viewed by anyone knowing the URL" Hidden]
-           [radio "status" "void" #status_public $(checked $VIDEO_STATUS public)]
+           [radio "status" "public" #status_public $(checked $VIDEO_STATUS public)]
              [label for=status_public tooltip="Video will be listed publicly" Public]
          ]
          [textarea name="description" placeholder="Description" . $(HTML "$VIDEO_DESCRIPTION")]
          [submit "action" "update_video" . Update]
          [submit "action" "update_video_cancel" . Cancel]
+         [fieldset .delete
+           [checkbox "delconfirm" "confirm" id="delconfirm"]
+           [label for=delconfirm Delete Video]
+           [submit "action" "delete" Delete Video]
+         ]
        ]
        EOF
+
+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' ''
+  frame_uploadprogress
+
 elif [ "$channel" -a "$video" ]; then
-  yield_page "$VIDEO_NAME" "video edit" <<-EOF
-       [nav [a href="../../" Channels] - [a href="../" $(HTML "${CHANNEL_NAME:-(Unnamed Channel)}")] - [span $(HTML "${VIDEO_NAME:-(Unnamed Video)}")]
-         $( [ "$USER_ID" -a ! "${CHANNEL_AUTHORS##*${USER_ID}*}" ] \
-            && printf ' - [a href="edit" edit]'
-         )
+  [ $VIDEO_STATUS = public -o $VIDEO_STATUS = hidden ] || AUTHOR || { . ${_EXEC}/page_404.sh; exit 0; }
+
+  yield_page "$VIDEO_NAME" "video" <<-EOF
+       [nav [a href="../../" Channels] - [a href="../" $(HTML "${CHANNEL_NAME:-(Unnamed Channel)}")] - [span $(HTML "${VIDEO_NAME:-(Unnamed Video)}")]]
+       $( AUTHOR && [ $VIDEO_STATUS = void ] && printf '
+        [iframe src="frameuploadprogress" width="100%%" height="50"
+         [a href="freameuploadprogress" Iframe: Upload progress]
        ]
+       [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
+         [source src="%s/video/%s/%s.mp4" type="video/mp4"]
+       ]' "$VIDEO_RESX" "$VIDEO_RESY" "$_BASE" "$channel" "$video"
+        )
+       $(AUTHOR && printf '[a .button href="edit" edit]')
        [h1 .name $(HTML "$VIDEO_NAME")]
        [div .description . ${VIDEO_DESCR_CACHE}]
        EOF
+
 else
   . "$_EXEC/page_404.sh"
 fi