Skip to content

Commit 28e2549

Browse files
debug: add logging to blob deletion.
1 parent a2ccce7 commit 28e2549

4 files changed

Lines changed: 27 additions & 1 deletion

File tree

internal/bud02/delete.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"context"
55
"errors"
66

7+
"go.uber.org/zap"
8+
79
"github.com/sebdeveloper6952/blossom-server/internal/core"
810
)
911

@@ -13,28 +15,43 @@ func DeleteBlob(
1315
pubkey string,
1416
hash string,
1517
authHash string,
18+
log *zap.Logger,
1619
) error {
1720
var (
1821
blobs = services.Blob()
1922
)
23+
24+
log.Debug("delete blob request", zap.String("pubkey", pubkey), zap.String("hash", hash))
25+
2026
blobDescriptor, err := blobs.GetFromHash(ctx, hash)
2127
if err != nil {
28+
log.Debug("blob not found", zap.String("hash", hash), zap.Error(err))
2229
return core.ErrBlobNotFound
2330
}
2431

2532
// only the owner can delete the file
2633
if blobDescriptor.Pubkey != pubkey {
34+
log.Debug("delete unauthorized: pubkey mismatch",
35+
zap.String("owner", blobDescriptor.Pubkey),
36+
zap.String("requester", pubkey),
37+
)
2738
return errors.New("unauthorized")
2839
}
2940

3041
// verify both hashes are the same
3142
if hash != authHash {
43+
log.Debug("delete unauthorized: hash mismatch",
44+
zap.String("hash", hash),
45+
zap.String("authHash", authHash),
46+
)
3247
return errors.New("unauthorized")
3348
}
3449

3550
if err := blobs.DeleteFromHash(ctx, hash); err != nil {
51+
log.Error("failed to delete blob", zap.String("hash", hash), zap.Error(err))
3652
return err
3753
}
3854

55+
log.Debug("blob deleted", zap.String("hash", hash))
3956
return nil
4057
}

internal/bud02/delete_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88

99
_ "github.com/mattn/go-sqlite3"
1010
"github.com/nbd-wtf/go-nostr"
11+
"go.uber.org/zap"
12+
1113
"github.com/sebdeveloper6952/blossom-server/db"
1214
"github.com/sebdeveloper6952/blossom-server/internal/core"
1315
"github.com/sebdeveloper6952/blossom-server/internal/pkg/config"
@@ -73,6 +75,7 @@ func TestDeleteBlob(t *testing.T) {
7375
pk,
7476
authHash,
7577
authHash,
78+
zap.NewNop(),
7679
)
7780
assert.NoError(t, err, "delete should succeed")
7881

@@ -138,6 +141,7 @@ func TestDeleteBlobNotOwner(t *testing.T) {
138141
otherPk,
139142
authHash,
140143
authHash,
144+
zap.NewNop(),
141145
)
142146
assert.Error(t, err, "delete by non-owner should fail")
143147
}
@@ -184,6 +188,7 @@ func TestDeleteBlobNotFound(t *testing.T) {
184188
pk,
185189
"nonexistenthash",
186190
"nonexistenthash",
191+
zap.NewNop(),
187192
)
188193
assert.ErrorIs(t, err, core.ErrBlobNotFound, "should return blob not found error")
189194
}

internal/httpapi/bud02_controller.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"strconv"
99

1010
"github.com/gin-gonic/gin"
11+
"go.uber.org/zap"
12+
1113
bud02 "github.com/sebdeveloper6952/blossom-server/internal/bud02"
1214
"github.com/sebdeveloper6952/blossom-server/internal/core"
1315
)
@@ -103,6 +105,7 @@ func listBlobs(
103105

104106
func deleteBlob(
105107
services core.Services,
108+
log *zap.Logger,
106109
) gin.HandlerFunc {
107110
return func(ctx *gin.Context) {
108111
if err := bud02.DeleteBlob(
@@ -111,6 +114,7 @@ func deleteBlob(
111114
ctx.GetString("pk"),
112115
ctx.Param("path"),
113116
ctx.GetString("x"),
117+
log,
114118
); err != nil {
115119
ctx.AbortWithStatusJSON(
116120
http.StatusBadRequest,

internal/httpapi/routes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func SetupRoutes(
7979
r.DELETE(
8080
"/:path",
8181
nostrAuthMiddleware("delete", log),
82-
deleteBlob(services),
82+
deleteBlob(services, log),
8383
)
8484

8585
// server stats

0 commit comments

Comments
 (0)