diff --git a/db/migrations/0006_add_video_archive.rb b/db/migrations/0006_add_video_archive.rb new file mode 100644 index 0000000..3cda76a --- /dev/null +++ b/db/migrations/0006_add_video_archive.rb @@ -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 diff --git a/lib/routes/video.rb b/lib/routes/video.rb index a3e1657..00652f6 100644 --- a/lib/routes/video.rb +++ b/lib/routes/video.rb @@ -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 diff --git a/views/video/view.erb b/views/video/view.erb index 6fe7016..6eeeca2 100644 --- a/views/video/view.erb +++ b/views/video/view.erb @@ -1,6 +1,6 @@
-

<%= video.name %>

+

<%= video.name %>

<%= '

(archived)

' if video.archived %>

Item added at: <%= date_format(video.created_at) %>

<% if video.updated_at %>

Last updated at: <%= date_format(video.updated_at) %>

@@ -11,8 +11,8 @@