From f243452783b4a08a494d6470f6367549f1241439 Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Mon, 6 Mar 2023 15:59:09 -0500 Subject: [PATCH] Added functionality to create directory structure for channels and videos --- lib/models/channel.rb | 13 +++++++++++++ lib/models/video.rb | 13 +++++++++++++ lib/routes/channel.rb | 2 ++ lib/routes/video.rb | 4 ++++ views/channel/list.erb | 2 +- views/video/list.erb | 2 +- 6 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/models/channel.rb b/lib/models/channel.rb index a13061f..066a1b1 100644 --- a/lib/models/channel.rb +++ b/lib/models/channel.rb @@ -2,6 +2,19 @@ class Channel < Sequel::Model one_to_many :videos + def ensureDirectoryStructure() + sub_dirs = ['Archive', 'Channel Documents', 'Main', 'Shorts'] + sub_dirs.each do |d| + sub_path = File.join( + @values[:directory_path], + d + ) + unless Dir.exist?(sub_path) + Dir.mkdir(sub_path) + end + end + end + def openProjects() return 0 end diff --git a/lib/models/video.rb b/lib/models/video.rb index 32db117..224a3c2 100644 --- a/lib/models/video.rb +++ b/lib/models/video.rb @@ -4,6 +4,19 @@ class Video < Sequel::Model many_to_one :channel + def ensureDirectoryStructure() + sub_dirs = ['Audio', 'B-Roll', 'Clips', 'Images', 'Export'] + sub_dirs.each do |d| + sub_path = File.join( + @values[:directory_path], + d + ) + unless Dir.exist?(sub_path) + Dir.mkdir(sub_path) + end + end + end + def parseScript() return Kramdown::Document.new(@values[:script]).to_html end diff --git a/lib/routes/channel.rb b/lib/routes/channel.rb index 818fbb5..ba258ea 100644 --- a/lib/routes/channel.rb +++ b/lib/routes/channel.rb @@ -24,7 +24,9 @@ namespace '/channel' do description: params[:channel_description] ) + # create supporting directory structure Dir.mkdir(channel.directory_path) + channel.ensureDirectoryStructure() redirect "/channel/#{channel.id}" end diff --git a/lib/routes/video.rb b/lib/routes/video.rb index c1fdf7a..69a78d0 100644 --- a/lib/routes/video.rb +++ b/lib/routes/video.rb @@ -25,6 +25,7 @@ namespace '/video' do video_serial = params[:video_serial].to_s.rjust(4, '0') video_path = File.join( channel.directory_path, + 'Main', "##{video_serial} - #{params[:video_name]}" ) @@ -37,7 +38,9 @@ namespace '/video' do script: "# Introduction\n\n# Body\n\n# Conclusions" ) + # create supporting directory structure Dir.mkdir(video_path) + video.ensureDirectoryStructure() redirect "/video/#{video.id}" end @@ -72,6 +75,7 @@ namespace '/video' do video_serial = params[:video_serial].to_s.rjust(4, '0') video_path = File.join( channel.directory_path, + 'Main', "##{video_serial} - #{params[:video_name]}" ) diff --git a/views/channel/list.erb b/views/channel/list.erb index b681e97..1f003d1 100644 --- a/views/channel/list.erb +++ b/views/channel/list.erb @@ -1,6 +1,6 @@
-

Hardware Inventory List

+

Channel List

diff --git a/views/video/list.erb b/views/video/list.erb index 14f6515..87dae4c 100644 --- a/views/video/list.erb +++ b/views/video/list.erb @@ -1,6 +1,6 @@
-

Hardware Inventory List

+

Video List