From: Paul Hänsch Date: Thu, 30 Sep 2021 11:57:48 +0000 (+0200) Subject: video file upload X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=1a097515329996eda5dee8eb1ed8e753afea0c3b;p=rawnet video file upload --- diff --git a/index.cgi b/index.cgi index 9beb6a9..bd7e21b 100755 --- 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";; diff --git a/page_video.sh b/page_video.sh index ef9a82e..bf4ec8a 100644 --- a/page_video.sh +++ b/page_video.sh @@ -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