feat: handle binary content
This commit is contained in:
@@ -174,4 +174,3 @@ func NewLocalFsAdapter(roots []string) (FileAdapter, error) {
|
|||||||
roots: roots,
|
roots: roots,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,6 +3,8 @@ package handler
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"git.max-richter.dev/max/marka/server-new/internal/adapters"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ErrorResponse struct {
|
type ErrorResponse struct {
|
||||||
@@ -18,3 +20,8 @@ func writeJSON(w http.ResponseWriter, code int, v any) {
|
|||||||
w.WriteHeader(code)
|
w.WriteHeader(code)
|
||||||
_ = json.NewEncoder(w).Encode(v)
|
_ = json.NewEncoder(w).Encode(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func writeFile(w http.ResponseWriter, file *adapters.FsFile) {
|
||||||
|
w.Header().Set("Content-Type", file.Type)
|
||||||
|
w.Write(file.Content)
|
||||||
|
}
|
||||||
|
@@ -52,15 +52,7 @@ func (h *Handler) get(w http.ResponseWriter, target string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
res := ResponseItem{
|
writeFile(w, fsEntry.File)
|
||||||
Name: fsEntry.File.Name,
|
|
||||||
Content: fsEntry.File.Content,
|
|
||||||
Type: fsEntry.File.Type,
|
|
||||||
IsDir: false,
|
|
||||||
Size: int64(len(fsEntry.File.Content)),
|
|
||||||
ModTime: fsEntry.File.ModTime,
|
|
||||||
}
|
|
||||||
writeJSON(w, 200, res)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user