Skip to content

Commit

Permalink
When listing a single text file, do not display the /editor/readme/co…
Browse files Browse the repository at this point in the history
…py/ link
  • Loading branch information
bengarrett committed Sep 8, 2024
1 parent 36d1c4c commit afef384
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
1 change: 0 additions & 1 deletion docs/todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* `<div class="modal-body"><picture><source srcset="/public/image/original/0191c3fc-a387-7715-ab41-441ea337f316.webp" type="image/webp" /></picture></div>`
* * Does not work, need to use `img` tag.
* 404 errors :/ /editor/thumbnail/top/ ~ /editor/preview/crop11/ etc.
* When listing a single text file, do not display the /editor/readme/copy/ link.
* Local file timestamp for file uploads is not being set.
* Redirect `/link/list` to wayback.defacto2.net.

Expand Down
23 changes: 15 additions & 8 deletions handler/app/internal/filerecord/filerecord.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type ListEntry struct {
}

// HTML returns the HTML for an file item in the "Download content" section of the File editor.
func (m ListEntry) HTML(bytes int64, platform string) string {
func (m ListEntry) HTML(bytes int64, platform, section string) string {
const blank = `<div class="col col-1"></div>`
name := url.QueryEscape(m.RelativeName)
ext := strings.ToLower(filepath.Ext(name))
Expand All @@ -84,17 +84,23 @@ func (m ListEntry) HTML(bytes int64, platform string) string {
default:
htm += blank
}
return m.readme(bytes, htm)
return m.readme(bytes, htm, platform, section)
}

func (m ListEntry) readme(bytes int64, htm string) string {
func (m ListEntry) readme(bytes int64, htm, platform, section string) string {
soloText := func() bool {
if !strings.EqualFold(platform, tags.Text.String()) && !strings.EqualFold(platform, textamiga) {
return false
}
return strings.EqualFold(section, tags.Nfo.String())
}
const blank = `<div class="col col-1"></div>`
name := url.QueryEscape(m.RelativeName)
ext := strings.ToLower(filepath.Ext(name))
switch {
case m.Texts && (ext == bat || ext == cmd || ext == ini):
htm += blank
case m.Texts:
case m.Texts && !soloText():
htm += readmecopy(m.UniqueID, name)
case m.Programs && ext == exe, m.Programs && ext == com:
htm += `<div class="col col-1 text-end"><svg width="16" height="16" fill="currentColor" aria-hidden="true">` +
Expand Down Expand Up @@ -452,9 +458,10 @@ func ListContent(art *models.File, src string) template.HTML {
if !tags.IsPlatform(platform) {
return "error, invalid platform"
}
section := strings.TrimSpace(strings.ToLower(art.Section.String))
dst, err := archive.ExtractSource(src, art.Filename.String)
if err != nil {
return extractErr(src, platform, zeroByteFiles, err)
return extractErr(src, platform, section, zeroByteFiles, err)
}
walkerCount := func(_ string, d fs.DirEntry, err error) error {
if err != nil || d.IsDir() {
Expand Down Expand Up @@ -485,7 +492,7 @@ func ListContent(art *models.File, src string) template.HTML {
}
entries++
le := listEntry(e, rel, unid)
b.WriteString(le.HTML(e.bytes, platform))
b.WriteString(le.HTML(e.bytes, platform, section))
if maxItems := 200; entries > maxItems {
more := fmt.Sprintf(`<div class="border-bottom row mb-1">... %d more files</div>`, files-entries)
b.WriteString(more)
Expand All @@ -500,7 +507,7 @@ func ListContent(art *models.File, src string) template.HTML {
return template.HTML(b.String())
}

func extractErr(src, platform string, zeroByteFiles int, err error) template.HTML {
func extractErr(src, platform, section string, zeroByteFiles int, err error) template.HTML {
if !errors.Is(err, archive.ErrNotArchive) && !errors.Is(err, archive.ErrNotImplemented) {
return template.HTML(err.Error())
}
Expand All @@ -510,7 +517,7 @@ func extractErr(src, platform string, zeroByteFiles int, err error) template.HTM
}
le := listErr(e)
var b strings.Builder
b.WriteString(le.HTML(e.bytes, platform))
b.WriteString(le.HTML(e.bytes, platform, section))
return template.HTML(b.String())
}

Expand Down

0 comments on commit afef384

Please sign in to comment.