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) {
+5 -1
View File
@@ -57,7 +57,11 @@ func postUploadFile(w http.ResponseWriter, r *http.Request, a services.IAuthenti
filename := uf.File.Value.GetFilename()
log.Info().Str("filename", filename).Msg("file is uploading...")
if err := s.Save(uf.IntoMetadata(), uf.File.Value.File); err != nil {
resource := uf.IntoResource()
if err := s.Create(resource); err != nil {
uf.Error = err.Error()
tmpl, err := templates.ExecuteUploadFormTmpl(&uf, w)
if err != nil {
log.Err(err).Msg("unable to generate upload template")