first draft of file storage

This commit is contained in:
2026-01-28 15:33:19 +02:00
parent d647854e98
commit d6496a427b
7 changed files with 394 additions and 158 deletions
+37 -10
View File
@@ -1,6 +1,8 @@
package handler
import (
"io"
"mstore/app/operator"
"mstore/app/router"
)
@@ -12,10 +14,18 @@ func (hand *Handler) FileExists(rctx *router.Context) {
params := &operator.FileExistsParams{
Filepath: filepath,
}
hand.logg.Debugf("filepath: %s", filepath)
code, _, _ := hand.oper.FileExists(params)
code, res, err := hand.oper.FileExists(params)
if err != nil {
hand.logg.Errorf("FileExists error: %v", err)
rctx.SetStatus(code)
return
}
rctx.SetHeader("Content-Type", res.ContentType)
rctx.SetHeader("Content-Length", res.ContentLength)
rctx.SetHeader("Content-Digest", res.ContentDigest)
rctx.SetStatus(code)
}
func (hand *Handler) PutFile(rctx *router.Context) {
@@ -31,12 +41,13 @@ func (hand *Handler) PutFile(rctx *router.Context) {
ContentType: contentType,
Source: rctx.Request.Body,
}
code, res, err := hand.oper.PutFile(params)
code, _, err := hand.oper.PutFile(params)
if err != nil {
hand.logg.Errorf("Error: %v", err)
hand.logg.Errorf("PutFile error: %v", err)
rctx.SetStatus(code)
return
}
rctx.SetStatus(code)
hand.SendResult(rctx, res)
}
func (hand *Handler) GetFile(rctx *router.Context) {
@@ -48,10 +59,25 @@ func (hand *Handler) GetFile(rctx *router.Context) {
}
hand.logg.Debugf("filepath: %s", filepath)
code, res, _ := hand.oper.GetFile(params)
code, res, err := hand.oper.GetFile(params)
if err != nil {
hand.logg.Errorf("PutFile error: %v", err)
rctx.SetStatus(code)
return
}
rctx.SetStatus(code)
rctx.SetHeader("Content-Type", res.ContentType)
rctx.SetHeader("Content-Length", res.ContentLength)
rctx.SetStatus(code)
rctx.SetHeader("Content-Digest", res.ContentDigest)
if res.Source != nil {
defer res.Source.Close()
_, err = io.Copy(rctx.Writer, res.Source)
if err != nil {
hand.logg.Errorf("GetFile error: %v", err)
return
}
}
}
func (hand *Handler) DeleteFile(rctx *router.Context) {
@@ -61,8 +87,9 @@ func (hand *Handler) DeleteFile(rctx *router.Context) {
params := &operator.DeleteFileParams{
Filepath: filepath,
}
hand.logg.Debugf("filepath: %s", filepath)
code, _, _ := hand.oper.DeleteFile(params)
code, _, err := hand.oper.DeleteFile(params)
if err != nil {
hand.logg.Errorf("GetFile error: %v", err)
}
rctx.SetStatus(code)
}