9 local boundary line length=0
11 [ ! "${CONTENT_TYPE}" -o "${CONTENT_TYPE##multipart/form-data;*}" ] && return 1
13 boundary="${CONTENT_TYPE#*; boundary=}"
14 boundary="${boundary%%;*}"
16 while read -r line; do
17 length="$(( length + ${#line} + 1))"
18 [ "${line%${CR}}" = "--$boundary" ] && break
20 while read -r line; do
21 length="$(( length + ${#line} + 1))"
22 [ ! "${line%${CR}}" ] && break \
26 printf "%i\n" "$(( CONTENT_LENGTH - length ))" >"${file}.upload"
27 head -c "$(( CONTENT_LENGTH - length ))" \
29 # print lines until boundary ( = actual file upload)
31 /^--'"${boundary}"'(--)?\r?$/!bFILE;
32 # discard remaining lines
35 truncate -s $(( $(stat -c %s -- "$file") -2 )) -- "$file"
36 rm -- "${file}.upload"
39 [ "$REQUEST_METHOD" = POST ] && case "$(POST action)" in
41 if [ ! "$USER_ID" ]; then
42 REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_NOTLOGGEDIN"
44 REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_UPDATE_NOTALLOWED"
45 elif update_video "$video" "name=$(POST name)" \
46 "description=$(POST description)" \
47 "status=$(POST status |grep -m1 -xE 'void|private|hidden|public')" \
48 "uploader=$USER_ID"; then
49 REDIRECT "${_BASE}/channel/${channel}/${video}/#UPDATE_SUCCESS"
51 REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_UPDATE_NOLOCK"
55 REDIRECT "${_BASE}/channel/${channel}/${video}/#CANCELED"
58 if [ ! "$USER_ID" ]; then
59 REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_NOTLOGGEDIN"
61 REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_UPDATE_NOTALLOWED"
62 elif [ "$(POST delconfirm)" != confirm ]; then
63 REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_NOT_CONFIRMED"
64 elif delete_video "$video"; then
65 REDIRECT "${_BASE}/channel/${channel}/#DELETE_CONFIRM"
67 REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_UPDATE_NOLOCK"
72 if [ "$REQUEST_METHOD" = POST -a "$channel" -a "$video" ]; then
74 head -c "$CONTENT_LENGTH" >/dev/null
75 REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_UPLOAD_NOTALLOWED"
76 elif [ "$VIDEO_STATUS" != void ]; then
77 head -c "$CONTENT_LENGTH" >/dev/null
78 REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_UPLOAD_NOCLOBBER"
79 elif UPLOAD "$_DATA/$channel/$video.mp4"; then
80 update_video "$video" status=private
85 if [ "$channel" -a "$video" -a "$action" = edit ]; then
86 AUTHOR || REDIRECT "$_BASE/$channel/$video/#ERROR_EDIT_NOTALLOWED"
88 yield_page "$VIDEO_NAME - Edit" "video edit" <<-EOF
89 [form .video .edit method=POST
90 [input name="name" value="$(HTML "$VIDEO_NAME")" placeholder="Video Name"]
91 [fieldset .status $([ $VIDEO_STATUS = void ] && printf "disabled=disabled")
92 [radio "status" "private" #status_private $(checked $VIDEO_STATUS private void)]
93 [label for=status_private tooltip="Video is only visible to channel authors" Private]
94 [radio "status" "hidden" #status_hidden $(checked $VIDEO_STATUS hidden)]
95 [label for=status_hidden tooltip="Video will not be listed but can be viewed by anyone knowing the URL" Hidden]
96 [radio "status" "public" #status_public $(checked $VIDEO_STATUS public)]
97 [label for=status_public tooltip="Video will be listed publicly" Public]
99 [textarea name="description" placeholder="Description" . $(HTML "$VIDEO_DESCRIPTION")]
100 [submit "action" "update_video" . Update]
101 [submit "action" "update_video_cancel" . Cancel]
103 [checkbox "delconfirm" "confirm" id="delconfirm"]
104 [label for=delconfirm Delete Video]
105 [submit "action" "delete" Delete Video]
110 elif [ "$channel" -a "$video" -a "$action" = frameuploadprogress ]; then
111 AUTHOR || REDIRECT "$_BASE/$channel/$video/#ERROR_EDIT_NOTALLOWED"
112 printf '%s\r\n' 'Content-Type: text/html' 'Connection: close' ''
113 printf '<!DOCTYPE HTML>
115 <title>Upload Progress</title>
116 <style type="text/css"><!--
124 background-color: #FFF;
132 left: 0; top: 0; bottom: 0;
133 background-color: #666;
138 left: 0; top: 0; right: 0; bottom: 0;
139 line-height: 1.375em;
144 printf '<div class=progress><div class=bar style="width: 0%%;"></div><div class=count>%i / %i</div></div>\n' 0 0
145 while [ ! -f "$_DATA/$channel/$video.mp4" -a \
146 ! -f "$_DATA/$channel/$video.mp4.upload" ]; do sleep 1; done
147 read size <"$_DATA/$channel/$video.mp4.upload"
148 while [ -f "$_DATA/$channel/$video.mp4.upload" ]; do
149 stat="$(stat -c %s "$_DATA/$channel/$video.mp4" 2>&-)"
150 printf '<div class=progress><div class=bar style="width:%i%%;"></div><div class=count>%iMB / %iMB</div></div>\n' \
151 "$(( stat * 100 / size ))" "$((stat / 1048576))" "$((size / 1048576))"
154 printf '<span class=progress><div class=bar style="width:100%%;"></div><div class=count>Ready!</div></span>\n'
155 printf '</body></html>'
157 elif [ "$channel" -a "$video" -a "$action" = frameupload ]; then
158 AUTHOR || REDIRECT "$_BASE/$channel/$video/#ERROR_EDIT_NOTALLOWED"
159 printf '%s\r\n' 'Content-Type: text/html' ''
160 [ "$VIDEO_STATUS" = void ] && "$_EXEC"/cgilite/html-sh.sed <<-EOF
165 [form .upload method=POST enctype="multipart/form-data"
166 [input type=file name=upload]
167 [submit "action" "video_upload" Upload]
171 [ "$VIDEO_STATUS" != void ] && "$_EXEC"/cgilite/html-sh.sed <<-EOF
176 [a href="./" target="_parent" . Reload Page!]
180 elif [ "$channel" -a "$video" ]; then
181 [ $VIDEO_STATUS = public -o $VIDEO_STATUS = hidden ] || AUTHOR || { . ${_EXEC}/page_404.sh; exit 0; }
183 yield_page "$VIDEO_NAME" "video" <<-EOF
184 [nav [a href="../../" Channels] - [a href="../" $(HTML "${CHANNEL_NAME:-(Unnamed Channel)}")] - [span $(HTML "${VIDEO_NAME:-(Unnamed Video)}")]]
185 $( AUTHOR && [ $VIDEO_STATUS = void ] && printf '
186 [iframe src="frameuploadprogress" width="100%%" height="50"
187 [a href="freameuploadprogress" Iframe: Upload progress]
189 [iframe src="frameupload" width="100%%" height="50"
190 [form .upload method=POST enctype="multipart/form-data"
191 [input type=file name=upload]
192 [submit "action" "video_upload" Upload]
195 $( [ $VIDEO_STATUS != void ] && printf '
196 [video preload=none controls=controls width=%i height=%i
197 [source src="%s/video/%s/%s.mp4" type="video/mp4"]
198 ]' "$VIDEO_RESX" "$VIDEO_RESY" "$_BASE" "$channel" "$video"
200 $(AUTHOR && printf '[a .button href="edit" edit]')
201 [h1 .name $(HTML "$VIDEO_NAME")]
202 [div .description . ${VIDEO_DESCR_CACHE}]
206 . "$_EXEC/page_404.sh"