Added ability to archive videos

This commit is contained in:
Gregory Ballantine 2023-03-07 00:07:29 -05:00
parent 9b6e38a313
commit 414cabb9f8
3 changed files with 53 additions and 8 deletions

View File

@ -0,0 +1,11 @@
Sequel.migration do
up do
add_column(:videos, :archived, TrueClass, default: false)
end
down do
drop_column(:videos, :archived)
end
end

View File

@ -117,13 +117,47 @@ namespace '/video' do
return "success"
end
get '/:video_id/delete' do
# find the video and delete it
get '/:video_id/archive' do
# find the video
video = Video.where(id: params[:video_id]).first()
FileUtils.rm_rf(video.directory_path)
video.delete()
video_base = File.basename(video.directory_path)
redirect '/video'
# move project to channel's archive
archive_dir = File.join(
video.channel.directory_path,
'Archive',
video_base
)
FileUtils.mv(video.directory_path, archive_dir)
# mark the video as archived and update directory
video.update(
directory_path: archive_dir,
archived: true
)
redirect '/video/' + video.id.to_s()
end
get '/:video_id/unarchive' do
# find the video
video = Video.where(id: params[:video_id]).first()
video_base = File.basename(video.directory_path)
# move project to channel's archive
active_dir = File.join(
video.channel.directory_path,
'Main',
video_base
)
FileUtils.mv(video.directory_path, active_dir)
# mark the video as archived and update directory
video.update(
directory_path: active_dir,
archived: false
)
redirect '/video/' + video.id.to_s()
end
get '/:video_id/edit/script' do

View File

@ -1,6 +1,6 @@
<div id="video-header" class="row">
<div class="eight columns">
<h1 class="video-name"><%= video.name %></h1>
<h1 class="video-name"><%= video.name %></h1><%= '<h4>(archived)</h4>' if video.archived %>
<h4 class="video-created">Item added at: <%= date_format(video.created_at) %></h4>
<% if video.updated_at %>
<h4 class="video-updated">Last updated at: <%= date_format(video.updated_at) %></h4>
@ -11,8 +11,8 @@
<div id="sidebar" class="four columns">
<div class="actions-bar">
<span><a href="/video/<%= video.id %>/edit">Edit <i class="fa-solid fa-pen-to-square"></i></a></span><span>
<a href="/video/<%= video.id %>/delete">Delete <i class="fa-solid fa-trash"></i></a></span>
<span><a href="/video/<%= video.id %>/edit">Edit <i class="fa-solid fa-pen-to-square"></i></a></span><% unless video.archived %><span><a href="/video/<%= video.id %>/archive">Archive <i class="fa-solid fa-box-archive"></i></a></span><% else %><span><a href="/video/<%= video.id %>/unarchive">Unarchive <i class="fa-solid fa-box-archive"></i></a></span>
<% end %>
</div>
<div class="video-channel">
<p>Channel: <a href="/channel/<%= video.channel.id %>"><span><%= video.channel.name %></span></a></p>