restructuration

This commit is contained in:
rmanach
2025-01-08 10:55:27 +01:00
parent 708db35214
commit 60111911da
10 changed files with 351 additions and 295 deletions
+4 -4
View File
@@ -12,18 +12,18 @@ import (
const URL = "/download"
func Handler(bs services.IStore) func(http.ResponseWriter, *http.Request) {
func Handler(s services.IStore) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
getDownload(w, r, bs)
getDownload(w, r, s)
default:
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
}
}
}
func getDownload(w http.ResponseWriter, r *http.Request, bs services.IStore) {
func getDownload(w http.ResponseWriter, r *http.Request, s services.IStore) {
queryParams := r.URL.Query()
downloadFiles, ok := queryParams["file"]
if !ok {
@@ -39,7 +39,7 @@ func getDownload(w http.ResponseWriter, r *http.Request, bs services.IStore) {
}
filename := downloadFiles[0]
filePath := filepath.Join(bs.GetStoreDir(), filename)
filePath := filepath.Join(s.GetDir(), filename)
if _, err := os.Stat(filePath); err != nil {
if os.IsNotExist(err) {