#235: rename Language column to Type; attachment pastes show file extension
CI / test (pull_request) Successful in 43s
CI / docker (pull_request) Skipped

- history/mine table column 'Language' -> 'Type' (data-sort key 'type')
- /api/public and /api/mine rows gain a 'type' field: file extension for
  attachment pastes, stored language otherwise (default 'text')
- paste page stats label 'Language' -> 'Type'; summary line uses the same
  label; get-paste JSON gains 'type'
- store list queries LEFT JOIN attachments to expose the filename
- table.js sorting accepts the 'type' key
This commit is contained in:
fen
2026-09-10 17:13:37 -05:00
parent e059ca1554
commit 0008b8ce0c
10 changed files with 132 additions and 20 deletions
+29 -2
View File
@@ -231,6 +231,20 @@ func (h *Handlers) renderPageStatus(w http.ResponseWriter, name string, status i
}
}
// attachmentExt returns the lowercase file extension (without dot) of a
// filename, or "" when the name has none. Used by the Type display (#235).
func attachmentExt(filename string) string {
name := filename
if i := strings.LastIndexByte(name, '/'); i >= 0 {
name = name[i+1:]
}
i := strings.LastIndexByte(name, '.')
if i <= 0 || i == len(name)-1 {
return ""
}
return strings.ToLower(name[i+1:])
}
func (h *Handlers) renderPaste(w http.ResponseWriter, row *store.PasteRow, justCreated bool, deletionToken string, readsRemaining *int) {
lines := strings.Count(row.Content, "\n") + 1
gutter := ""
@@ -258,7 +272,17 @@ func (h *Handlers) renderPaste(w http.ResponseWriter, row *store.PasteRow, justC
if attachment != nil {
summarySize = int(attachment.Size)
}
summary := fmt.Sprintf("%s · %s · %d views · %s", lang, humanSize(summarySize), row.ViewCount, agoString(row.CreatedAt))
// #235: column renamed to "Type". Text pastes keep the detected
// language; attachment pastes show the file extension instead.
attExt := ""
typeLabel := lang
if attachment != nil {
if ext := attachmentExt(attachment.Filename); ext != "" {
attExt = ext
typeLabel = ext
}
}
summary := fmt.Sprintf("%s · %s · %d views · %s", typeLabel, humanSize(summarySize), row.ViewCount, agoString(row.CreatedAt))
// #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
@@ -278,7 +302,10 @@ func (h *Handlers) renderPaste(w http.ResponseWriter, row *store.PasteRow, justC
"Page": "paste",
"ID": row.ID,
"Title": row.Title.String,
"Language": row.Language.String,
"Language": typeLabel,
"TypeLabel": typeLabel,
"HasAttachment": attachment != nil,
"AttachmentExt": attExt,
"StatsSummary": summary,
"SizeHuman": sizeHuman,
"HasPassword": row.PasswordHash.Valid,