- Add __bad__ for bad torrents

- Add colors to logs info
- Make logs a bit more clearer
- Mark torrent has bad instead of deleting them
This commit is contained in:
Mukhtar Akere
2025-05-13 13:17:26 +01:00
parent 7c1bb52793
commit 36e681d0e6
8 changed files with 110 additions and 48 deletions
+4 -3
View File
@@ -83,7 +83,7 @@ func (h *Handler) getTorrentsFolders(folder string) []os.FileInfo {
}
func (h *Handler) getParentItems() []string {
parents := []string{"__all__", "torrents"}
parents := []string{"__all__", "torrents", "__bad__"}
// Add custom folders
parents = append(parents, h.cache.GetCustomFolders()...)
@@ -122,7 +122,7 @@ func (h *Handler) getChildren(name string) []os.FileInfo {
name = utils.PathUnescape(path.Clean(name))
root := path.Clean(h.getRootPath())
// toplevel “parents” (e.g. __all__, torrents)
// toplevel “parents” (e.g. __all__, torrents etc)
if name == root {
return h.getParentFiles()
}
@@ -397,6 +397,7 @@ func (h *Handler) serveDirectory(w http.ResponseWriter, r *http.Request, file we
}
return fmt.Sprintf("%.2f %s", size, unit)
},
"hasSuffix": strings.HasSuffix,
}
tmpl, err := template.New("directory").Funcs(funcMap).Parse(directoryTemplate)
if err != nil {
@@ -443,7 +444,7 @@ func (h *Handler) handleGet(w http.ResponseWriter, r *http.Request) {
if file, ok := fRaw.(*File); ok && file.content == nil {
link, err := file.getDownloadLink()
if err != nil {
h.logger.Trace().
h.logger.Error().
Err(err).
Str("path", r.URL.Path).
Msg("Could not fetch download link")
+19 -1
View File
@@ -103,6 +103,19 @@ const directoryTemplate = `
text-overflow: ellipsis;
white-space: nowrap;
}
.disabled {
color: #999;
pointer-events: none;
border-color: #f0f0f0;
background-color: #f8f8f8;
cursor: not-allowed;
}
.disabled .file-number {
color: #bbb;
}
.disabled .file-info {
color: #aaa;
}
</style>
</head>
<body>
@@ -111,9 +124,14 @@ const directoryTemplate = `
{{if .ShowParent}}
<li><a href="{{urlpath .ParentPath}}" class="parent-dir"><span class="file-number"></span>Parent Directory</a></li>
{{end}}
{{$isBadPath := hasSuffix .Path "__bad__"}}
{{range $index, $file := .Children}}
<li>
<a href="{{urlpath (printf "%s/%s" $.Path $file.Name)}}">
{{if $isBadPath}}
<a class="disabled">
{{else}}
<a href="{{urlpath (printf "%s/%s" $.Path $file.Name)}}">
{{end}}
<span class="file-number">{{add $index 1}}.</span>
<span class="file-name">{{$file.Name}}{{if $file.IsDir}}/{{end}}</span>
<span class="file-info">