Fix issues with dupliacte names; other minor bug fixes

This commit is contained in:
Mukhtar Akere
2025-04-28 23:06:44 +01:00
parent 10467ff9f8
commit 5f06a244b8
8 changed files with 73 additions and 61 deletions
+3 -6
View File
@@ -71,7 +71,7 @@ func (f *File) getDownloadLink() (string, error) {
f.downloadLink = downloadLink
return downloadLink, nil
}
return "", fmt.Errorf("download link not found")
return "", os.ErrNotExist
}
func (f *File) stream() (*http.Response, error) {
@@ -203,7 +203,7 @@ func (f *File) Read(p []byte) (n int, err error) {
// Make the request to get the file
resp, err := f.stream()
if err != nil {
return 0, err
return 0, io.EOF
}
if resp == nil {
return 0, io.EOF
@@ -216,10 +216,7 @@ func (f *File) Read(p []byte) (n int, err error) {
n, err = f.reader.Read(p)
f.offset += int64(n)
if err == io.EOF {
f.reader.Close()
f.reader = nil
} else if err != nil {
if err != nil {
f.reader.Close()
f.reader = nil
}
+21
View File
@@ -361,6 +361,27 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
if r.Method == "HEAD" {
f, err := h.OpenFile(r.Context(), r.URL.Path, os.O_RDONLY, 0)
if err != nil {
h.logger.Error().Err(err).Str("path", r.URL.Path).Msg("Failed to open file")
http.NotFound(w, r)
return
}
defer f.Close()
fi, err := f.Stat()
if err != nil {
h.logger.Error().Err(err).Msg("Failed to stat file")
http.Error(w, "Server Error", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", getContentType(fi.Name()))
w.Header().Set("Content-Length", fmt.Sprintf("%d", fi.Size()))
w.WriteHeader(http.StatusOK)
return
}
// Fallback: for other methods, use the standard WebDAV handler.
handler := &webdav.Handler{
FileSystem: h,