Files
mstore/app/handler/file.go
T
2026-01-28 13:06:04 +02:00

69 lines
1.6 KiB
Go

package handler
import (
"mstore/app/operator"
"mstore/app/router"
)
func (hand *Handler) FileExists(rctx *router.Context) {
hand.logg.Debugf("Handle FileExists")
filepath := rctx.PathMap["filepath"]
params := &operator.FileExistsParams{
Filepath: filepath,
}
hand.logg.Debugf("filepath: %s", filepath)
code, _, _ := hand.oper.FileExists(params)
rctx.SetStatus(code)
}
func (hand *Handler) PutFile(rctx *router.Context) {
hand.logg.Debugf("Handle PutFile")
contentLength := rctx.GetHeader("Content-Length")
contentType := rctx.GetHeader("Content-Type")
filepath := rctx.PathMap["filepath"]
params := &operator.PutFileParams{
Filepath: filepath,
ContentLength: contentLength,
ContentType: contentType,
Source: rctx.Request.Body,
}
code, res, err := hand.oper.PutFile(params)
if err != nil {
hand.logg.Errorf("Error: %v", err)
}
rctx.SetStatus(code)
hand.SendResult(rctx, res)
}
func (hand *Handler) GetFile(rctx *router.Context) {
hand.logg.Debugf("Handle GetFile")
filepath := rctx.PathMap["filepath"]
params := &operator.GetFileParams{
Filepath: filepath,
}
hand.logg.Debugf("filepath: %s", filepath)
code, res, _ := hand.oper.GetFile(params)
rctx.SetHeader("Content-Type", res.ContentType)
rctx.SetHeader("Content-Length", res.ContentLength)
rctx.SetStatus(code)
}
func (hand *Handler) DeleteFile(rctx *router.Context) {
hand.logg.Debugf("Handle DeleteFile")
filepath := rctx.PathMap["filepath"]
params := &operator.DeleteFileParams{
Filepath: filepath,
}
hand.logg.Debugf("filepath: %s", filepath)
code, _, _ := hand.oper.DeleteFile(params)
rctx.SetStatus(code)
}