Improve story handling on CLI

This commit is contained in:
Alexander Olofsson 2024-12-10 09:18:13 +01:00
parent 8dcb61154e
commit 2256adae26
Signed by: ace
GPG key ID: D439C9470CB04C73

View file

@ -57,19 +57,48 @@ class FicTracker::Cli::Story < Thor
end
end
desc 'update STORY...', 'Force-update the listed stories'
def update(*stories)
setup!
stories.each do |story|
puts "Updating #{story} ..."
bend = FicTracker::Backends.find_backend story
if bend.nil?
puts " Can't update, no available backends."
next
end
bend = FicTracker::Backends.get(bend)
slug = story
slug = bend.parse_slug(story) if bend.respond_to? :parse_slug
story = FicTracker::Models::Story.find(backend_name: bend.name, slug:)
unless story
puts " Not tracking, skipping."
next
end
before = story.etag
story.refresh_metadata!
story.refresh_content!
render_story! story if story.etag != before
end
end
desc 'del STORY...', 'Remove stories from tracker'
def del(*stories)
setup!
stories.each do |story|
if story.include? '/'
backend, slug = story.split '/'
backend = nil if backend == '*'
backend_name, slug = story.split '/'
backend_name = nil if backend_name == '*'
else
slug = story
end
search = {
backend:,
backend_name:,
slug:
}.compact
found = FicTracker::Models::Story.where(**search)