stage-manager/lib/routes/video.rb

52 lines
1.1 KiB
Ruby
Raw Normal View History

namespace '/video' do
get '' do
redirect '/video/list'
end
get '/list' do
videos = Video.reverse(:updated_at).all()
erb :'video/list', :locals => {
:title => 'List of videos',
:videos => videos
}
end
get '/create' do
channels = Channel.all()
erb :'video/create', :locals => {
:title => 'Create new video',
:channels => channels
}
end
post '/create' do
channel = Channel.where(id: params[:video_channel]).first()
video_serial = params[:video_serial].to_s.rjust(4, '0')
video_path = File.join(
channel.directory_path,
"##{video_serial} - #{params[:video_name]}"
)
video = Video.create(
serial: params[:video_serial],
name: params[:video_name],
channel_id: params[:video_channel],
directory_path: video_path,
description: params[:video_description]
)
Dir.mkdir(video_path)
redirect "/video/#{video.id}"
end
get '/:video_id' do
video = Video.where(id: params[:video_id]).first()
puts "#{video.name}"
erb :'video/view', :locals => {
:title => video.name,
:video => video
}
end
end