fix #221: scale image pastes, drop text box, fix raw view and size
CI / test (pull_request) Successful in 45s
CI / docker (pull_request) Skipped

- image pastes render the image scaled to fit the viewer box (aspect
  ratio preserved, max-height 70vh), no text/code box below it
- link pill moved under the image as a small inline chip
- /raw serves image attachment bytes as an image instead of empty text
- view details size reports the actual attachment file size
This commit is contained in:
fen
2026-09-10 14:19:07 -05:00
parent 44cff7e718
commit 98ea7eefa9
5 changed files with 80 additions and 9 deletions
+18 -2
View File
@@ -252,20 +252,35 @@ func (h *Handlers) renderPaste(w http.ResponseWriter, row *store.PasteRow, justC
http.Error(w, "db error", 500)
return
}
// #221: image attachments render the image, not a text/code box. Size
// comes from the attachment's actual file size, not the text content.
attImage := false
if attachment != nil {
switch attachment.Mime {
case "image/png", "image/jpeg", "image/gif", "image/webp":
attImage = true
}
}
sizeHuman := humanSize(len(row.Content))
lineCount := lines
if attachment != nil {
sizeHuman = attachment.SizeHuman
lineCount = 1
}
data := map[string]any{
"Page": "paste",
"ID": row.ID,
"Title": row.Title.String,
"Language": row.Language.String,
"StatsSummary": summary,
"SizeHuman": humanSize(len(row.Content)),
"SizeHuman": sizeHuman,
"HasPassword": row.PasswordHash.Valid,
"BurnAfterRead": row.BurnAfterRead,
"CustomSlug": row.CustomSlug.String,
"ContentHTML": template.HTML(langpkg.HighlightCode(row.Content, row.Language.String)), // safe: HighlightCode escapes all non-span text
"ContentAttr": row.Content,
"Gutter": strings.TrimSuffix(gutter, "\n"),
"LineCount": lines,
"LineCount": lineCount,
"SizeBytes": len(row.Content),
"CreatedAgo": agoString(row.CreatedAt),
"CreatedAtUnix": row.CreatedAt,
@@ -279,6 +294,7 @@ func (h *Handlers) renderPaste(w http.ResponseWriter, row *store.PasteRow, justC
"ReadsTotal": int(row.ReadsLimit.Int64),
"JustCreated": justCreated,
"Attachment": attachment,
"AttachmentImage": attImage,
"Host": "this host",
}
h.renderPage(w, "paste.html", data)