파일 업로드/삭제, maintenance 메뉴 추가

This commit is contained in:
2023-06-05 11:56:34 +09:00
parent 827abf34fe
commit 41387ba902
3 changed files with 199 additions and 73 deletions

View File

@ -2,7 +2,10 @@ package core
import (
"context"
"encoding/hex"
"net/http"
"os"
"path"
"sync/atomic"
"time"
@ -32,6 +35,10 @@ type servicePipelineDocument struct {
}
type filePipelineDocument struct {
OperationType string `bson:"operationType"`
DocumentKey struct {
Id primitive.ObjectID `bson:"_id"`
} `bson:"documentKey"`
File *fileDocumentDesc `bson:"fullDocument"`
}
@ -140,6 +147,7 @@ func (mg *Maingate) watchFileCollection(parentctx context.Context, serveMux *htt
Key: "$match", Value: bson.D{
{Key: "operationType", Value: bson.D{
{Key: "$in", Value: bson.A{
"delete",
"insert",
}},
}},
@ -148,6 +156,8 @@ func (mg *Maingate) watchFileCollection(parentctx context.Context, serveMux *htt
projectStage := bson.D{
{
Key: "$project", Value: bson.D{
{Key: "operationType", Value: 1},
{Key: "documentKey", Value: 1},
{Key: "fullDocument", Value: 1},
},
},
@ -186,7 +196,17 @@ func (mg *Maingate) watchFileCollection(parentctx context.Context, serveMux *htt
var data filePipelineDocument
if err := stream.Decode(&data); err == nil {
data.File.save()
switch data.OperationType {
case "insert":
data.File.save()
case "delete":
subfolder := hex.EncodeToString(data.DocumentKey.Id[:4])
rf := hex.EncodeToString(data.DocumentKey.Id[4:8])
subpath := path.Join("static", subfolder, rf)
os.RemoveAll(subpath)
}
}
}
}