]> git.plutz.net Git - rawnet/commitdiff
video file upload
authorPaul Hänsch <paul@plutz.net>
Thu, 30 Sep 2021 11:57:48 +0000 (13:57 +0200)
committerPaul Hänsch <paul@plutz.net>
Thu, 30 Sep 2021 11:57:48 +0000 (13:57 +0200)
index.cgi
page_video.sh

index 9beb6a9d6674369ef5cd1e2ea273aa0025e43ece..bd7e21b18085122b854d96bdd4c6391f722f5850 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
@@ -107,6 +107,10 @@ case ${PATH_INFO} in
        $(w_user_recover)
        EOF
     ;;
+  /video/*/*.mp4)
+    . "${_EXEC}/cgilite/file.sh"
+    FILE "${_DATA}/${PATH_INFO#/video/}"
+    ;;
   /|/channel/*) . "${_EXEC}/page_channel.sh";;
   /playlist/*) . "${_EXEC}/page_playlist.sh";;
   /search/*) . "${_EXEC}/page_search.sh";;
index ef9a82edc3f8a5c4a881fd23761661b521d1ab88..bf4ec8ab996b1aa7cdeedb6b894c164a0b72ef84 100644 (file)
@@ -43,12 +43,36 @@ update_video(){
   fi
 }
 
+UPLOAD(){
+  local file="$1"
+  local boundary line last
+  local CONTENT_TYPE="$(HEADER Content-Type)"
+
+  [ ! "${CONTENT_TYPE}" -o "${CONTENT_TYPE##multipart/form-data;*}" ] && return 1
+
+  boundary="${CONTENT_TYPE#*; boundary=}"
+  boundary="${boundary%%;*}"
+
+  head -c "$CONTENT_LENGTH" \
+  | sed -nE '
+    /^--'"${boundary}"'\r?$/!b;
+    :A; n;
+    /^\r?$/!bA;
+     n;
+    :FILE
+    p; n;
+    /^--'"${boundary}"'(--)?\r?$/!bFILE;
+    :END
+    $q; n; bEND;
+  ' >"$file"
+  truncate -s $(( $(stat -c %s -- "$file") -2 )) -- "$file"
+}
 
 [ "$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
@@ -62,6 +86,20 @@ update_video(){
     ;;
 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" "$VIDEO_NAME" "$VIDEO_DESCRIPTION" 0 0 0 \
+                 "$VIDEO_COVER" private "$VIDEO_UPOADER" "$VIDEO_HITS" \
+                 "" ""
+  fi
+fi
+
 if [ "$channel" -a "$video" -a "$action" = edit ]; then
   yield_page "$VIDEO_NAME - Edit" "video edit" <<-EOF
        [form .video .edit method=POST
@@ -82,10 +120,18 @@ if [ "$channel" -a "$video" -a "$action" = edit ]; then
 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]'
-         )
+         $(AUTHOR && printf ' - [a href="edit" edit]')
        ]
+       $( AUTHOR && [ $VIDEO_STATUS = void ] && printf '
+       [form .upload method=POST enctype="multipart/form-data"
+         [input type=file name=upload]
+         [submit "action" "video_upload" Upload]
+       ]')
+       $( [ $VIDEO_STATUS != void ] && printf '
+       [video
+         [source src="%s/video/%s/%s.mp4"]
+       ]' "$_BASE" "$channel" "$video"
+        )
        [h1 .name $(HTML "$VIDEO_NAME")]
        [div .description . ${VIDEO_DESCR_CACHE}]
        EOF