- 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
48 lines
1.3 KiB
Ruby
48 lines
1.3 KiB
Ruby
# 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
|