Files
redux-scraper/app/helpers/telegram_bot_logs_helper.rb
Dylan Knutson e78baa6594 Refactor Telegram bot logs with performance enhancements and view improvements
- Add comprehensive file information display (content type, size, dimensions)
- Move complex image dimension logic from views to TelegramBotLogsHelper
- Add percentage calculations to performance metrics section
- Use Rails associations instead of manual BlobFile lookups
- Update slow requests filtering to use total_request_time column
- Enhance search result thumbnails and improve post linking
- Add comprehensive test coverage for helper methods
- Improve error handling and type safety throughout
2025-08-05 06:30:42 +00:00

48 lines
1.3 KiB
Ruby
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# typed: strict
module TelegramBotLogsHelper
extend T::Sig
sig { params(telegram_bot_log: TelegramBotLog).returns(String) }
def status_color_class(telegram_bot_log)
case telegram_bot_log.status
when "processing"
"bg-blue-100 text-blue-800"
when "success"
"bg-green-100 text-green-800"
when "error"
"bg-red-100 text-red-800"
when "invalid_image"
"bg-orange-100 text-orange-800"
else
"bg-slate-100 text-slate-800"
end
end
sig { params(blob_file: T.nilable(BlobFile)).returns(String) }
def image_dimensions_for_blob_file(blob_file)
return "N/A" unless blob_file
return "N/A" unless blob_file.content_type&.start_with?("image/")
begin
media =
LoadedMedia.from_file(
T.must(blob_file.content_type),
blob_file.absolute_file_path,
)
if media.is_a?(LoadedMedia::StaticImage)
vips_image = media.instance_variable_get(:@vips_image)
"#{vips_image.width}×#{vips_image.height}"
elsif media.is_a?(LoadedMedia::Gif)
width = media.instance_variable_get(:@width)
height = media.instance_variable_get(:@height)
"#{width}×#{height}"
else
"N/A"
end
rescue StandardError
"Unable to determine"
end
end
end