added metadata
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"git.kapelle.org/niklas/s3share/internal/client"
|
||||
"github.com/gorilla/mux"
|
||||
@@ -30,6 +31,7 @@ func StartWebserver(addr string, client client.Client) error {
|
||||
|
||||
share, err := client.GetShare(r.Context(), vars["slug"])
|
||||
if err != nil {
|
||||
logrus.Error(err.Error())
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
@@ -39,8 +41,20 @@ func StartWebserver(addr string, client client.Client) error {
|
||||
return
|
||||
}
|
||||
|
||||
metadata, err := client.GetObjectMetadata(r.Context(), share.Key)
|
||||
if err != nil {
|
||||
logrus.Error(err.Error())
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", metadata.ContentType)
|
||||
w.Header().Set("Content-Length", strconv.FormatInt(metadata.Size, 10))
|
||||
w.Header().Set("Content-Disposition", "attachment; filename=\""+metadata.Filename+"\"")
|
||||
|
||||
obj, err := client.GetObjectFromShare(r.Context(), share)
|
||||
if err != nil {
|
||||
logrus.Error(err.Error())
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
@@ -63,6 +77,7 @@ func StartWebserver(addr string, client client.Client) error {
|
||||
var shareParams createShare
|
||||
err := json.NewDecoder(r.Body).Decode(&shareParams)
|
||||
if err != nil {
|
||||
logrus.Error(err.Error())
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@@ -70,6 +85,7 @@ func StartWebserver(addr string, client client.Client) error {
|
||||
share, err := client.CreateShare(r.Context(), shareParams.Key)
|
||||
|
||||
if err != nil {
|
||||
logrus.Error(err.Error())
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
@@ -85,12 +101,14 @@ func StartWebserver(addr string, client client.Client) error {
|
||||
var shareParams deleteShare
|
||||
err := json.NewDecoder(r.Body).Decode(&shareParams)
|
||||
if err != nil {
|
||||
logrus.Error(err.Error())
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
err = client.DeleteShare(r.Context(), shareParams.Slug)
|
||||
if err != nil {
|
||||
logrus.Error(err.Error())
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user