Skip to content

Commit

Permalink
Improved the GUI and system checks that handle uploading video data
Browse files Browse the repository at this point in the history
  • Loading branch information
brand-it committed Apr 16, 2024
1 parent d316ad5 commit 89b104e
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 67 deletions.
8 changes: 0 additions & 8 deletions app/assets/stylesheets/bg_process.scss
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
.bg-processes {
position: fixed;
right: 0;
top: 0;
z-index: 4;
}

.bg-process {
--bs-toast-bg: rgba(var(--bs-body-bg-rgb), 0.85);
--bs-toast-border-color: var(--bs-border-color-translucent);
Expand All @@ -31,7 +24,6 @@
margin: 2em;
max-width: 100%;
pointer-events: auto;
width: var(--bs-toast-max-width);

.header {
display: flex;
Expand Down
17 changes: 14 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
class ApplicationController < ActionController::Base
include Rescuer

before_action :plex_config
before_action :movie_db_config
before_action :mkv_config
before_action :continue_upload
before_action :load_disk_worker
before_action :mkv_config
before_action :movie_db_config
before_action :plex_config
helper_method :free_disk_space, :total_disk_space

def current_user
Expand All @@ -27,6 +28,16 @@ def load_disk_worker
LoadDiskWorker.perform_async
end

def continue_upload
return if UploadWorker.job.pending?

Video.find_each do |video|
next unless video.tmp_plex_path_exists?

UploadWorker.perform_async(disk_title: video.disk_title)
end
end

private

def stats
Expand Down
16 changes: 11 additions & 5 deletions app/listeners/upload_progress_listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ def update_component
end

def component
ProgressBarComponent.new \
model: DiskTitle,
completed: percentage,
status: :info,
message: title
progress_bar = render(
ProgressBarComponent.new(
model: Video,
completed: percentage,
status: :info,
message: title
), layout: false
)
component = ProcessComponent.new(worker: UploadWorker)
component.with_body { progress_bar }
component
end

def percentage
Expand Down
52 changes: 52 additions & 0 deletions app/views/layouts/_bg_progress.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<div class="bg-processes">
<%= render ProcessComponent.new worker: ScanPlexWorker do |c| %>
<%= c.with_body do %>
<% if ScanPlexWorker.job.pending? %>
<%=
render(
ProgressBarComponent.new(
model: Movie,
completed: (ScanPlexWorker.job.worker.completed.zero? ? 20 : ScanPlexWorker.job.worker.completed),
status: :success,
message: 'scanning plex for movies',
show_percentage: false
)
)
%>
<% else %>
<span>Done! you have a total of <%= pluralize(Video.count, 'video') %> on plex.</span>
<% end %>
<% end %>
<% end %>

<%= render ProcessComponent.new worker: LoadDiskWorker do |c| %>
<%= c.with_body do %>
<% if LoadDiskWorker.job.pending? %>
<span>Loading the disk info</span>
<% elsif (disks = FindExistingDisksService.call).any? %>
<span><%= disks.map(&:name).join(', ') %> is ready to be ripped.</span>
<% else %>
<span>No disks found</span>
<% end %>
<% end %>
<% end %>
<%= render ProcessComponent.new worker: UploadWorker do |c| %>
<%= c.with_body do %>
<% if UploadWorker.job.pending? %>

<%=
render(
ProgressBarComponent.new(
model: DiskTitle,
show_percentage: false,
status: :info,
message: 'upload in progress'
)
)
%>
<% else %>
<span>Nothing is being uploaded to <%= Config::Plex.newest.settings_ftp_host %> </span>
<% end %>
<% end %>
<% end %>
</div>
48 changes: 10 additions & 38 deletions app/views/layouts/application.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,21 @@
<%= render 'layouts/head' %>
</head>
<body>
<div class="bg-processes">
<%= render ProcessComponent.new worker: ScanPlexWorker do |c| %>
<%= c.with_body do %>
<% if ScanPlexWorker.job.pending? %>
<%=
render(
ProgressBarComponent.new(
model: Movie,
completed: (ScanPlexWorker.job.worker.completed.zero? ? 20 : ScanPlexWorker.job.worker.completed),
status: :success,
message: 'scanning plex for movies',
show_percentage: false
)
)
%>
<% else %>
<span>Done! you have a total of <%= pluralize(Video.count, 'video') %> on plex.</span>
<% end %>
<% end %>
<% end %>

<%= render ProcessComponent.new worker: LoadDiskWorker do |c| %>
<%= c.with_body do %>
<% if LoadDiskWorker.job.pending? %>
<span>Loading the disk info</span>
<% elsif (disks = FindExistingDisksService.call).any? %>
<span><%= disks.map(&:name).join(', ') %> is ready to be ripped.</span>
<% else %>
<span>No disks found</span>
<% end %>
<% end %>
<% end %>
</div>

<div class="d-flex w-100 h-90 mx-auto flex-column">
<%= render ToastComponent.new do |c| %>
<%= c.body do %>
testing
<% end %>
<% end %>
<%= render 'layouts/header' %>

<main role="main" class="inner p-3 h-100"><%= yield %></main>
<main role="main" class="inner p-3 h-100">
<div class="col-12 row">
<div class="col-4">
<%= render 'layouts/bg_progress' %>
</div>
<div class="col-8">
<%= yield %>
</div>
</div>
</main>
</div>
</body>
</html>
11 changes: 1 addition & 10 deletions app/workers/load_disk_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,10 @@

class LoadDiskWorker < ApplicationWorker
def perform
cable_ready[DiskTitleChannel.channel_name].morph \
selector: "##{component.dom_id}",
html: render(component, layout: false)
cable_ready[DiskTitleChannel.channel_name].reload if existing_disks.nil?
cable_ready[DiskTitleChannel.channel_name].reload if existing_disks.nil? && disks.present?
cable_ready.broadcast
end

def component
component = ProcessComponent.new(worker: ScanPlexWorker)
component.with_body { disks.map(&:name).join(', ') }
component
end

def disks
@disks ||= existing_disks || CreateDisksService.call
end
Expand Down
5 changes: 2 additions & 3 deletions app/workers/rip_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ def create_mkv(disk_title)
end

def upload_mkv(disk_title)
@progress_listener = UploadProgressListener.new(file_size: disk_title.size)
Ftp::UploadMkvService.call disk_title:,
progress_listener:
sleep 1 while UploadWorker.job.pending?
UploadWorker.perform_async(disk_title)
end

def disk_titles
Expand Down
14 changes: 14 additions & 0 deletions app/workers/upload_worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

class UploadWorker < ApplicationWorker
option :disk_title, Types.Instance(DiskTitle)

def perform
progress_listener = UploadProgressListener.new(
title: "Uploading #{disk_title.video.title}",
file_size: disk_title.size
)
Ftp::UploadMkvService.call disk_title:,
progress_listener:
end
end

0 comments on commit 89b104e

Please sign in to comment.