#221: image paste view fixes
- image pastes scale to fit the viewer box (max-width/max-height, object-fit) - no text/code box rendered below the image for image pastes - link pill positioning cleaned up on the image view - /raw for attachment pastes redirects to the file itself - view details size now uses the attachment blob size, not empty text len
This commit is contained in:
+11
-3
@@ -245,28 +245,36 @@ func (h *Handlers) renderPaste(w http.ResponseWriter, row *store.PasteRow, justC
|
||||
if lang == "" {
|
||||
lang = "text"
|
||||
}
|
||||
summary := fmt.Sprintf("%s · %s · %d views · %s", lang, humanSize(len(row.Content)), row.ViewCount, agoString(row.CreatedAt))
|
||||
// #38: one optional file attachment per paste; nil when none.
|
||||
attachment, err := h.Store.GetAttachmentForPaste(row.ID)
|
||||
if err != nil {
|
||||
http.Error(w, "db error", 500)
|
||||
return
|
||||
}
|
||||
// #221: for attachment pastes the stored text content is empty (the file
|
||||
// replaced it), so size must come from the attachment blob, not
|
||||
// len(row.Content), or the view details show a wrong size.
|
||||
sizeBytes := len(row.Content)
|
||||
if attachment != nil {
|
||||
sizeBytes = int(attachment.Size)
|
||||
}
|
||||
summary := fmt.Sprintf("%s · %s · %d views · %s", lang, humanSize(sizeBytes), row.ViewCount, agoString(row.CreatedAt))
|
||||
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": humanSize(sizeBytes),
|
||||
"HasPassword": row.PasswordHash.Valid,
|
||||
"BurnAfterRead": row.BurnAfterRead,
|
||||
"CustomSlug": row.CustomSlug.String,
|
||||
"IsImagePaste": attachment != nil && strings.HasPrefix(attachment.Mime, "image/"),
|
||||
"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,
|
||||
"SizeBytes": len(row.Content),
|
||||
"SizeBytes": sizeBytes,
|
||||
"CreatedAgo": agoString(row.CreatedAt),
|
||||
"CreatedAtUnix": row.CreatedAt,
|
||||
"ViewCount": row.ViewCount,
|
||||
|
||||
Reference in New Issue
Block a user