]> git.plutz.net Git - rawnet/blob - page_video.sh
upload function to external file, ui change: put video upload before meta edit
[rawnet] / page_video.sh
1 #!/bin/sh
2
3 . "$_EXEC/db_video.sh"
4 . "$_EXEC/upload.sh"
5
6 read_video "$video"
7
8 [ "$REQUEST_METHOD" = POST ] && case "$(POST action)" in
9   update_video)
10     if [ ! "$USER_ID" ]; then
11       REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_NOTLOGGEDIN"
12     elif ! AUTHOR; then
13       REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_UPDATE_NOTALLOWED"
14     elif update_video "$video" "name=$(POST name)" \
15                       "description=$(POST description)" \
16                       "status=$(POST status |grep -m1 -xE 'void|private|hidden|public')" \
17                       "uploader=$USER_ID"; then
18       REDIRECT "${_BASE}/channel/${channel}/${video}/#UPDATE_SUCCESS"
19     else
20       REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_UPDATE_NOLOCK"
21     fi
22     ;;
23   update_video_cancel)
24     REDIRECT "${_BASE}/channel/${channel}/${video}/#CANCELED"
25     ;;
26   delete)
27     if [ ! "$USER_ID" ]; then
28       REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_NOTLOGGEDIN"
29     elif ! AUTHOR; then
30       REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_UPDATE_NOTALLOWED"
31     elif [ "$(POST delconfirm)" != confirm ]; then
32       REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_NOT_CONFIRMED"
33     elif delete_video "$video"; then
34       REDIRECT "${_BASE}/channel/${channel}/#DELETE_CONFIRM"
35     else
36       REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_UPDATE_NOLOCK"
37     fi
38     ;;
39 esac
40
41 if [ "$REQUEST_METHOD" = POST -a "$channel" -a "$video" ]; then
42   if ! AUTHOR; then
43     head -c "$CONTENT_LENGTH" >/dev/null
44     REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_UPLOAD_NOTALLOWED"
45   elif [ "$VIDEO_STATUS" != void ]; then
46     head -c "$CONTENT_LENGTH" >/dev/null
47     REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_UPLOAD_NOCLOBBER"
48   elif UPLOAD "$_DATA/$channel/$video.mp4"; then
49     update_video "$video" status=private
50     VIDEO_STATUS=private
51     REDIRECT "${_BASE}/channel/${channel}/${video}/edit"
52   fi
53 fi
54
55 if [ "$channel" -a "$video" -a "$action" = edit ]; then
56   AUTHOR || REDIRECT "$_BASE/$channel/$video/#ERROR_EDIT_NOTALLOWED"
57
58   yield_page "$VIDEO_NAME - Edit" "video edit" <<-EOF
59         [form .video .edit method=POST
60           [input name="name" value="$(HTML "$VIDEO_NAME")" placeholder="Video Name"]
61           [fieldset .status $([ $VIDEO_STATUS = void ] && printf "disabled=disabled")
62             [radio "status" "private" #status_private $(checked $VIDEO_STATUS private void)]
63               [label for=status_private tooltip="Video is only visible to channel authors" Private]
64             [radio "status" "hidden" #status_hidden  $(checked $VIDEO_STATUS hidden)]
65               [label for=status_hidden tooltip="Video will not be listed but can be viewed by anyone knowing the URL" Hidden]
66             [radio "status" "public" #status_public $(checked $VIDEO_STATUS public)]
67               [label for=status_public tooltip="Video will be listed publicly" Public]
68           ]
69           [textarea name="description" placeholder="Description" . $(HTML "$VIDEO_DESCRIPTION")]
70           [submit "action" "update_video" . Update]
71           [submit "action" "update_video_cancel" . Cancel]
72           [fieldset .delete
73             [checkbox "delconfirm" "confirm" id="delconfirm"]
74             [label for=delconfirm Delete Video]
75             [submit "action" "delete" Delete Video]
76           ]
77         ]
78         EOF
79
80 elif [ "$channel" -a "$video" -a "$action" = frameuploadprogress ]; then
81   AUTHOR || REDIRECT "$_BASE/$channel/$video/#ERROR_EDIT_NOTALLOWED"
82   printf '%s\r\n' 'Content-Type: text/html' 'Connection: close' ''
83   frame_uploadprogress
84
85 elif [ "$channel" -a "$video" ]; then
86   [ $VIDEO_STATUS = public -o $VIDEO_STATUS = hidden ] || AUTHOR || { . ${_EXEC}/page_404.sh; exit 0; }
87
88   yield_page "$VIDEO_NAME" "video" <<-EOF
89         [nav [a href="../../" Channels] - [a href="../" $(HTML "${CHANNEL_NAME:-(Unnamed Channel)}")] - [span $(HTML "${VIDEO_NAME:-(Unnamed Video)}")]]
90         $( AUTHOR && [ $VIDEO_STATUS = void ] && printf '
91         [iframe src="frameuploadprogress" width="100%%" height="50"
92           [a href="freameuploadprogress" Iframe: Upload progress]
93         ]
94         [form .upload method=POST enctype="multipart/form-data"
95           [input type=file name=upload]
96           [submit "action" "video_upload" Upload]
97         ]')
98         $( [ $VIDEO_STATUS != void ] && printf '
99         [video preload=none controls=controls width=%i height=%i
100           [source src="%s/video/%s/%s.mp4" type="video/mp4"]
101         ]' "$VIDEO_RESX" "$VIDEO_RESY" "$_BASE" "$channel" "$video"
102         )
103         $(AUTHOR && printf '[a .button href="edit" edit]')
104         [h1 .name $(HTML "$VIDEO_NAME")]
105         [div .description . ${VIDEO_DESCR_CACHE}]
106         EOF
107
108 else
109   . "$_EXEC/page_404.sh"
110 fi