2023-03-03 14:19:20 -05:00
|
|
|
namespace '/channel' do
|
|
|
|
|
|
|
|
get '' do
|
|
|
|
redirect '/channel/list'
|
|
|
|
end
|
|
|
|
get '/list' do
|
|
|
|
channels = Channel.reverse(:updated_at).all()
|
|
|
|
erb :'channel/list', :locals => {
|
|
|
|
:title => 'List of channels',
|
|
|
|
:channels => channels
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
get '/create' do
|
|
|
|
erb :'channel/create', :locals => {
|
2023-03-03 23:22:17 -05:00
|
|
|
:title => 'Create new channel',
|
|
|
|
:base_directory => $conf.get('stgm.base_directory')
|
2023-03-03 14:19:20 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
post '/create' do
|
|
|
|
channel = Channel.create(
|
|
|
|
name: params[:channel_name],
|
2023-03-03 23:22:17 -05:00
|
|
|
directory_path: params[:channel_dir],
|
2023-03-03 14:19:20 -05:00
|
|
|
description: params[:channel_description]
|
|
|
|
)
|
2023-03-03 23:22:17 -05:00
|
|
|
|
|
|
|
Dir.mkdir(channel.directory_path)
|
|
|
|
|
2023-03-03 14:19:20 -05:00
|
|
|
redirect "/channel/#{channel.id}"
|
|
|
|
end
|
|
|
|
|
|
|
|
get '/:channel_id' do
|
|
|
|
channel = Channel.where(id: params[:channel_id]).first()
|
2023-03-04 10:59:30 -05:00
|
|
|
channel_videos = channel.videos_dataset.reverse(:updated_at).limit(10).all()
|
2023-03-03 14:19:20 -05:00
|
|
|
erb :'channel/view', :locals => {
|
|
|
|
:title => channel.name,
|
2023-03-04 10:59:30 -05:00
|
|
|
:channel => channel,
|
|
|
|
:channel_videos => channel_videos
|
2023-03-03 14:19:20 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2023-03-04 08:47:07 -05:00
|
|
|
get '/:channel_id/edit' do
|
|
|
|
channel = Channel.where(id: params[:channel_id]).first()
|
|
|
|
erb :'channel/edit', :locals => {
|
|
|
|
:title => "Editing: #{channel.name}",
|
|
|
|
:channel => channel
|
|
|
|
}
|
|
|
|
end
|
|
|
|
post '/:channel_id/edit' do
|
|
|
|
# get channel model and save old directory path
|
|
|
|
channel = Channel.where(id: params[:channel_id]).first()
|
|
|
|
old_path = channel.directory_path
|
|
|
|
|
|
|
|
# edit channel model
|
|
|
|
channel.update(
|
|
|
|
name: params[:channel_name],
|
|
|
|
directory_path: params[:channel_dir],
|
|
|
|
description: params[:channel_description]
|
|
|
|
)
|
|
|
|
|
|
|
|
# edit associate videos' directory paths
|
|
|
|
channel.videos.each do |v|
|
|
|
|
video_path = v.directory_path.sub(old_path, channel.directory_path)
|
|
|
|
v.update(directory_path: video_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
# rename channel directory
|
|
|
|
File.rename(old_path, channel.directory_path)
|
|
|
|
|
|
|
|
# redirect user
|
|
|
|
redirect "/channel/#{channel.id}"
|
|
|
|
end
|
|
|
|
|
2023-03-03 14:19:20 -05:00
|
|
|
end
|