#235: rename Language column to Type; attachment pastes show file extension
- 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:
@@ -9,7 +9,7 @@ const t = PaletteTable.init({
|
||||
? `${t.esc(it.title)}${it.is_can ? ' <span class="badge" title="Can — bundle of items">can</span>' : ''}`
|
||||
: `<a class="slug paste-name" href="/${t.esc(it.id)}">${t.esc(it.id)}</a>${it.is_can ? ' <span class="badge" title="Can — bundle of items">can</span>' : ''}`) +
|
||||
`</td>` +
|
||||
`<td><span class="badge">${t.esc(it.language || 'text')}</span></td>` +
|
||||
`<td><span class="badge">${t.esc(it.type || it.language || 'text')}</span></td>` +
|
||||
`<td class="dim">${t.fmtSize(it.size)}</td><td class="dim">${it.view_count}</td><td class="dim" data-ts="${it.created_at}">${t.ago(it.created_at)}</td>` +
|
||||
(it.custom_slug ? `<td><a class="slug url-link" href="/${t.esc(it.custom_slug)}">/${t.esc(it.custom_slug)}</a></td>` : `<td class="dim">none</td>`) +
|
||||
`<td class="dim"><a class="id-link" href="/${t.esc(it.id)}">${t.esc(it.id)}</a></td></tr>`,
|
||||
|
||||
@@ -21,7 +21,7 @@ const t = PaletteTable.init({
|
||||
? `${t.esc(it.title)}${it.is_can ? ' <span class="badge" title="Can — bundle of items">can</span>' : ''}`
|
||||
: `<a class="slug paste-name" href="/${t.esc(it.id)}">${t.esc(it.id)}</a>${it.is_can ? ' <span class="badge" title="Can — bundle of items">can</span>' : ''}`) +
|
||||
`</td>` +
|
||||
`<td><span class="badge">${t.esc(it.language || 'text')}</span></td>` +
|
||||
`<td><span class="badge">${t.esc(it.type || it.language || 'text')}</span></td>` +
|
||||
`<td class="dim">${t.fmtSize(it.size)}</td><td class="dim" data-ts="${it.created_at}">${t.ago(it.created_at)}</td>` +
|
||||
(it.custom_slug ? `<td><a class="slug url-link" href="/${t.esc(it.custom_slug)}">/${t.esc(it.custom_slug)}</a></td>` : `<td class="dim">none</td>`) +
|
||||
`<td class="dim"><a class="id-link" href="/${t.esc(it.id)}">${t.esc(it.id)}</a></td>` +
|
||||
|
||||
@@ -16,7 +16,7 @@ const PaletteTable = (() => {
|
||||
const sortVal = (it, k) => {
|
||||
let v = it[k];
|
||||
if (k === 'title' || k === 'custom_slug') v = (v == null || v === '') ? null : String(v).toLowerCase();
|
||||
if (k === 'language') v = (v == null || v === '') ? 'text' : String(v).toLowerCase();
|
||||
if (k === 'language' || k === 'type') v = (v == null || v === '') ? 'text' : String(v).toLowerCase();
|
||||
if (k === 'size' || k === 'view_count' || k === 'created_at') return v == null ? -1 : v;
|
||||
return v == null ? null : v;
|
||||
};
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<colgroup><col class="col-a"><col class="col-b"><col class="col-c"><col class="col-d"><col class="col-e"><col class="col-f"><col class="col-g"></colgroup>
|
||||
<thead><tr>
|
||||
<th data-sort="title" class="sortable">Paste<span class="sort-ind"></span></th>
|
||||
<th data-sort="language" class="sortable">Language<span class="sort-ind"></span></th>
|
||||
<th data-sort="type" class="sortable">Type<span class="sort-ind"></span></th>
|
||||
<th data-sort="size" class="sortable">Size<span class="sort-ind"></span></th>
|
||||
<th data-sort="view_count" class="sortable">Views<span class="sort-ind"></span></th>
|
||||
<th data-sort="created_at" class="sortable">Created<span class="sort-ind"></span></th>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<colgroup><col class="col-a"><col class="col-b"><col class="col-c"><col class="col-d2"><col class="col-e"><col class="col-f"><col class="col-del"></colgroup>
|
||||
<thead><tr>
|
||||
<th data-sort="title" class="sortable">Paste<span class="sort-ind"></span></th>
|
||||
<th data-sort="language" class="sortable">Language<span class="sort-ind"></span></th>
|
||||
<th data-sort="type" class="sortable">Type<span class="sort-ind"></span></th>
|
||||
<th data-sort="size" class="sortable">Size<span class="sort-ind"></span></th>
|
||||
<th data-sort="created_at" class="sortable">Created<span class="sort-ind"></span></th>
|
||||
<th data-sort="custom_slug" class="sortable">URL<span class="sort-ind"></span></th>
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
</button>
|
||||
<div class="stats-body" id="stats-body" hidden>
|
||||
<div class="stats-grid">
|
||||
<span class="stats-k">Language</span><span class="stats-v">{{if .Language}}{{.Language}}{{else}}text{{end}}</span>
|
||||
<span class="stats-k">Type</span><span class="stats-v">{{.TypeLabel}}</span>
|
||||
<span class="stats-k">Size</span><span class="stats-v">{{.SizeHuman}} ({{.LineCount}} lines)</span>
|
||||
<span class="stats-k">Views</span><span class="stats-v">{{.ViewCount}}</span>
|
||||
<span class="stats-k">Created</span><span class="stats-v" data-ts="{{.CreatedAtUnix}}">{{.CreatedAgo}}</span>
|
||||
|
||||
+29
-2
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user