Fixes
- Be conservative about the number of goroutines - Minor fixes - Add Webdav to ui - Add more configs to UI
This commit is contained in:
+4
-2
@@ -31,6 +31,8 @@ type File struct {
|
||||
fileId string
|
||||
torrentId string
|
||||
|
||||
modTime time.Time
|
||||
|
||||
size int64
|
||||
offset int64
|
||||
isDir bool
|
||||
@@ -176,7 +178,7 @@ func (f *File) Stat() (os.FileInfo, error) {
|
||||
name: f.name,
|
||||
size: 0,
|
||||
mode: 0755 | os.ModeDir,
|
||||
modTime: time.Now(),
|
||||
modTime: f.modTime,
|
||||
isDir: true,
|
||||
}, nil
|
||||
}
|
||||
@@ -185,7 +187,7 @@ func (f *File) Stat() (os.FileInfo, error) {
|
||||
name: f.name,
|
||||
size: f.size,
|
||||
mode: 0644,
|
||||
modTime: time.Now(),
|
||||
modTime: f.modTime,
|
||||
isDir: false,
|
||||
}, nil
|
||||
}
|
||||
|
||||
+13
-1
@@ -116,6 +116,8 @@ func (h *Handler) OpenFile(ctx context.Context, name string, flag int, perm os.F
|
||||
metadataOnly = true
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
|
||||
// Fast path optimization with a map lookup instead of string comparisons
|
||||
switch name {
|
||||
case rootDir:
|
||||
@@ -125,6 +127,7 @@ func (h *Handler) OpenFile(ctx context.Context, name string, flag int, perm os.F
|
||||
children: h.getParentFiles(),
|
||||
name: "/",
|
||||
metadataOnly: metadataOnly,
|
||||
modTime: now,
|
||||
}, nil
|
||||
case path.Join(rootDir, "version.txt"):
|
||||
return &File{
|
||||
@@ -134,6 +137,7 @@ func (h *Handler) OpenFile(ctx context.Context, name string, flag int, perm os.F
|
||||
name: "version.txt",
|
||||
size: int64(len("v1.0.0")),
|
||||
metadataOnly: metadataOnly,
|
||||
modTime: now,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -152,6 +156,7 @@ func (h *Handler) OpenFile(ctx context.Context, name string, flag int, perm os.F
|
||||
name: folderName,
|
||||
size: 0,
|
||||
metadataOnly: metadataOnly,
|
||||
modTime: now,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -177,6 +182,7 @@ func (h *Handler) OpenFile(ctx context.Context, name string, flag int, perm os.F
|
||||
name: cachedTorrent.Name,
|
||||
size: cachedTorrent.Size,
|
||||
metadataOnly: metadataOnly,
|
||||
modTime: cachedTorrent.AddedOn,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -192,6 +198,7 @@ func (h *Handler) OpenFile(ctx context.Context, name string, flag int, perm os.F
|
||||
size: file.Size,
|
||||
link: file.Link,
|
||||
metadataOnly: metadataOnly,
|
||||
modTime: cachedTorrent.AddedOn,
|
||||
}
|
||||
return fi, nil
|
||||
}
|
||||
@@ -457,7 +464,12 @@ func (h *Handler) serveDirectory(w http.ResponseWriter, r *http.Request, file we
|
||||
}
|
||||
|
||||
// Parse and execute template
|
||||
tmpl, err := template.New("directory").Parse(directoryTemplate)
|
||||
funcMap := template.FuncMap{
|
||||
"add": func(a, b int) int {
|
||||
return a + b
|
||||
},
|
||||
}
|
||||
tmpl, err := template.New("directory").Funcs(funcMap).Parse(directoryTemplate)
|
||||
if err != nil {
|
||||
h.logger.Error().Err(err).Msg("Failed to parse directory template")
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
|
||||
+26
-7
@@ -73,6 +73,8 @@ const directoryTemplate = `
|
||||
display: block;
|
||||
border: 1px solid #eee;
|
||||
border-radius: 4px;
|
||||
position: relative;
|
||||
padding-left: 50px; /* Make room for the number */
|
||||
}
|
||||
a:hover {
|
||||
background-color: #f7f9fa;
|
||||
@@ -85,23 +87,40 @@ const directoryTemplate = `
|
||||
.parent-dir {
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
.file-number {
|
||||
position: absolute;
|
||||
left: 10px;
|
||||
top: 10px;
|
||||
width: 30px;
|
||||
color: #777;
|
||||
font-weight: bold;
|
||||
text-align: right;
|
||||
}
|
||||
.file-name {
|
||||
display: inline-block;
|
||||
max-width: 70%;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Index of {{.Path}}</h1>
|
||||
<ul>
|
||||
{{if .ShowParent}}
|
||||
<li><a href="{{.ParentPath}}" class="parent-dir">Parent Directory</a></li>
|
||||
<li><a href="{{.ParentPath}}" class="parent-dir"><span class="file-number"></span>Parent Directory</a></li>
|
||||
{{end}}
|
||||
{{range .Children}}
|
||||
{{range $index, $file := .Children}}
|
||||
<li>
|
||||
<a href="{{$.Path}}/{{.Name}}">
|
||||
{{.Name}}{{if .IsDir}}/{{end}}
|
||||
<a href="{{$.Path}}/{{$file.Name}}">
|
||||
<span class="file-number">{{add $index 1}}.</span>
|
||||
<span class="file-name">{{$file.Name}}{{if $file.IsDir}}/{{end}}</span>
|
||||
<span class="file-info">
|
||||
{{if not .IsDir}}
|
||||
{{.Size}} bytes
|
||||
{{if not $file.IsDir}}
|
||||
{{$file.Size}} bytes
|
||||
{{end}}
|
||||
{{.ModTime.Format "2006-01-02 15:04:05"}}
|
||||
{{$file.ModTime.Format "2006-01-02 15:04:05"}}
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
Reference in New Issue
Block a user