Added directories to channels and videos

This commit is contained in:
Gregory Ballantine 2023-03-03 23:22:17 -05:00
parent db74e26124
commit ef1813f16e
8 changed files with 48 additions and 5 deletions

View File

@ -1,3 +1,6 @@
stgm:
base_directory: '/srv/videos'
database:
adapter: 'sqlite'
database: 'data/stgm.db'

View File

@ -0,0 +1,13 @@
Sequel.migration do
up do
add_column(:channels, :directory_path, String)
add_column(:videos, :directory_path, String)
end
down do
drop_column(:channels, :directory_path)
drop_column(:videos, :directory_path)
end
end

View File

@ -13,15 +13,19 @@ namespace '/channel' do
get '/create' do
erb :'channel/create', :locals => {
:title => 'Create new channel'
:title => 'Create new channel',
:base_directory => $conf.get('stgm.base_directory')
}
end
post '/create' do
channel = Channel.create(
name: params[:channel_name],
directory_path: params[:channel_dir],
description: params[:channel_description]
)
Dir.mkdir(channel.directory_path)
redirect "/channel/#{channel.id}"
end

View File

@ -19,13 +19,23 @@ namespace '/video' do
}
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

View File

@ -11,7 +11,7 @@ set :public_folder, __dir__ + '/public'
set :views, settings.root + '/views'
# Load configuration file
conf = Config.new(File.join(__dir__, 'data/defaults.yaml'))
$conf = Config.new(File.join(__dir__, 'data/defaults.yaml'))
# Initialize logging
logger = Logger.new(STDOUT)
@ -20,7 +20,7 @@ logger.level = Logger::INFO
# Load the Sequel timestamps plugin
Sequel::Model.plugin :timestamps
# Initialize Sequel gem for database actions
DB = Sequel.connect(adapter: conf.get('database.adapter'), database: conf.get('database.database'))
DB = Sequel.connect(adapter: $conf.get('database.adapter'), database: $conf.get('database.database'))
# Load models
require_relative 'lib/models/channel.rb'
require_relative 'lib/models/video.rb'

View File

@ -14,6 +14,13 @@
</div>
</div>
<div class="row">
<div class="columns twelve">
<label for="channel_dir">Channel directory:</label>
<input class="u-full-width" type="text" id="channel_dir" name="channel_dir" required value="<%= base_directory %>">
</div>
</div>
<div class="row">
<div class="twelve columns">
<label for="channel_description">Channel description:</label>

View File

@ -14,6 +14,9 @@
<span><a href="/channel/<%= channel.id %>/edit">Edit <i class="fa-solid fa-pen-to-square"></i></a></span><span>
<a href="/channel/<%= channel.id %>/delete">Delete <i class="fa-solid fa-trash"></i></a></span>
</div>
<div class="channel-path">
<p><span><%= channel.directory_path %></span></p>
</div>
<div class="channel-open">
<p>Open projects: <span><%= channel.openProjects() %></span></p>
</div>

View File

@ -20,5 +20,8 @@
<div class="video-serial">
<p>Serial: <span><%= serialize(video.serial) %></span></p>
</div>
<div class="video-path">
<p><span><%= video.directory_path %></span></p>
</div>
</div>
</div>