/
quantification-management.go
65 lines (53 loc) · 2.48 KB
/
quantification-management.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package wsHandler
import (
"errors"
"fmt"
"path"
"strings"
"github.com/pixlise/core/v4/api/dbCollections"
"github.com/pixlise/core/v4/api/filepaths"
"github.com/pixlise/core/v4/api/ws/wsHelpers"
protos "github.com/pixlise/core/v4/generated-protos"
)
func HandleQuantBlessReq(req *protos.QuantBlessReq, hctx wsHelpers.HandlerContext) (*protos.QuantBlessResp, error) {
return nil, errors.New("HandleQuantBlessReq not implemented yet")
}
func HandleQuantDeleteReq(req *protos.QuantDeleteReq, hctx wsHelpers.HandlerContext) (*protos.QuantDeleteResp, error) {
// Can't use the helper: DeleteUserObject because we also have to delete stuff from S3 and we need the scanId associated to find
// the path. So here we do a get first, with edit priviledges required
dbItem, _, err := wsHelpers.GetUserObjectById[protos.QuantificationSummary](true, req.QuantId, protos.ObjectType_OT_QUANTIFICATION, dbCollections.QuantificationsName, hctx)
if err != nil {
return nil, err
}
// We have the item, form the paths that need to be deleted
toDelete := []string{
filepaths.GetQuantPath(hctx.SessUser.User.Id, dbItem.ScanId, dbItem.Id+".bin"),
filepaths.GetQuantPath(hctx.SessUser.User.Id, dbItem.ScanId, dbItem.Id+".csv"),
}
// Add all the known log files too
for _, logFile := range dbItem.Status.OtherLogFiles {
toDelete = append(toDelete, filepaths.GetQuantPath(hctx.SessUser.User.Id, dbItem.ScanId, path.Join(filepaths.MakeQuantLogDirName(dbItem.Id), logFile)))
}
// Now delete from DB
if _, err := wsHelpers.DeleteUserObject[protos.QuantDeleteResp](req.QuantId, protos.ObjectType_OT_QUANTIFICATION, dbCollections.QuantificationsName, hctx); err != nil {
return nil, err
}
// Delete all the files
errors := []string{}
for _, delFile := range toDelete {
err := hctx.Svcs.FS.DeleteObject(hctx.Svcs.Config.UsersBucket, delFile)
if err != nil {
errors = append(errors, fmt.Sprintf("s3://%v/%v: %v", hctx.Svcs.Config.UsersBucket, delFile, err))
}
}
if len(errors) > 0 {
// Print out all errors, but don't error out if something remains in S3
hctx.Svcs.Log.Errorf("Failed to delete files from S3 when deleting quant: %v. File errors:\n%v", req.QuantId, strings.Join(errors, "\n"))
}
// Notify of the change
hctx.Svcs.Notifier.SysNotifyQuantChanged(req.QuantId)
return &protos.QuantDeleteResp{}, nil
}
func HandleQuantPublishReq(req *protos.QuantPublishReq, hctx wsHelpers.HandlerContext) (*protos.QuantPublishResp, error) {
return nil, errors.New("HandleQuantPublishReq not implemented yet")
}