Files
simple-aircraft-manager-rails/app/views/squawks/_attachments.html.erb
T
rickyandClaude Opus 5.5 908c943e21 Fix crashes found by fuzzing malformed input
- Components can't be made into a parent loop, and the parts tree walks
  stop safely if one exists (logbook entry and squawk resolution pages
  crashed).
- A rejected aircraft photo no longer breaks the edit page; empty photos
  are refused; images that can't be read aren't resized, and a failed
  resize sends the original instead of an error.
- Unsupported formats (/report.pdf…) answer 406; tampered upload
  references, out-of-range numbers and constraint violations get a form
  message instead of a 500; requests with null bytes are refused (400).
- Blank values in required columns with defaults take the default;
  optional links to records that don't exist are validation errors.
- Imports (oil report, logbook scans, .sam.zip) accept only uploaded files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 13:17:43 -05:00

56 lines
3.8 KiB
ERB
Raw 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.
<%# A squawk's files: photos show as thumbnails that open the in-app viewer
(which has Download); other files open in a new tab and have a download link. %>
<% files = squawk.attachments.to_a %>
<% if files.any? %>
<%# Thumbnails for images that can be resized; others are listed as files. %>
<% photos, others = files.partition { _1.image? && _1.blob.resizable_image? } %>
<div class="mt-1" data-controller="gallery">
<ul class="flex flex-wrap gap-1.5">
<% photos.each do |file| %>
<li>
<%= link_to rails_blob_path(file, disposition: :inline),
class: "block overflow-hidden rounded-md ring-1 ring-slate-300 hover:ring-2 hover:ring-sky-500 focus-visible:ring-2 focus-visible:ring-sky-500",
title: t(".preview", filename: file.filename),
data: { gallery_target: "item", action: "gallery#open", gallery_name: file.filename.to_s,
gallery_download: rails_blob_path(file, disposition: :attachment) } do %>
<%= image_tag file.variant(resize_to_fill: [ 160, 160 ]), alt: file.filename.to_s, loading: "lazy", width: 64, height: 64,
class: "block h-16 w-16 bg-slate-100 object-cover" %>
<% end %>
</li>
<% end %>
<% others.each do |file| %>
<li class="inline-flex items-center overflow-hidden rounded-md text-xs ring-1 ring-slate-300">
<%= link_to "📎 #{file.filename.to_s.truncate(28, omission: "…")}", rails_blob_path(file, disposition: :inline),
class: "px-2 py-1 text-sky-700 hover:bg-slate-100", target: "_blank", rel: "noopener", title: t(".open", filename: file.filename) %>
<%= link_to "⬇", rails_blob_path(file, disposition: :attachment), download: file.filename.to_s,
class: "border-l border-slate-300 px-1.5 py-1 text-slate-500 hover:bg-slate-100 hover:text-sky-700",
title: t(".download", filename: file.filename), aria: { label: t(".download", filename: file.filename) } %>
</li>
<% end %>
</ul>
<% if photos.any? %>
<dialog data-gallery-target="dialog" aria-label="<%= t(".photo_viewer") %>"
class="m-0 h-dvh max-h-none w-screen max-w-none bg-transparent p-0 text-white backdrop:bg-black/90"
data-action="click->gallery#backdrop keydown->gallery#keydown touchstart->gallery#touchstart touchend->gallery#touchend">
<div class="flex h-full flex-col" data-gallery-close>
<div class="flex items-center gap-3 bg-black/60 px-4 py-2 text-sm">
<span data-gallery-target="caption" class="min-w-0 flex-1 truncate font-medium"></span>
<span data-gallery-target="counter" class="text-white/60 tabular-nums"></span>
<%= t(".open_2_html") %>
<%= t(".download_2_html") %>
<button type="button" data-action="gallery#close" class="rounded px-2 py-1 text-lg leading-none hover:bg-white/15" aria-label="<%= t(".close") %>" autofocus>✕</button>
</div>
<div class="relative flex min-h-0 flex-1 items-center justify-center p-2 sm:p-6" data-gallery-close>
<button type="button" data-gallery-target="nav" data-action="gallery#previous" aria-label="<%= t(".previous_photo") %>"
class="absolute left-2 top-1/2 -translate-y-1/2 rounded-full bg-black/50 px-3 py-2 text-2xl hover:bg-black/70">‹</button>
<img data-gallery-target="image" alt="" class="max-h-full max-w-full select-none object-contain shadow-2xl">
<button type="button" data-gallery-target="nav" data-action="gallery#next" aria-label="<%= t(".next_photo") %>"
class="absolute right-2 top-1/2 -translate-y-1/2 rounded-full bg-black/50 px-3 py-2 text-2xl hover:bg-black/70">›</button>
</div>
</div>
</dialog>
<% end %>
</div>
<% end %>