Skip to content

Commit fdfad3f

Browse files
committed
feat: support file storage
1 parent 36d0cf8 commit fdfad3f

File tree

27 files changed

+563
-715
lines changed

27 files changed

+563
-715
lines changed

configs/example-for-single-node.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ password = "librarian"
1616
no_ssl = true
1717

1818
[s3]
19+
driver = "minio"
1920
end_point = "127.0.0.1:9000"
2021
access_key = "librarian"
2122
secret_key = "librarian"

configs/example-for-testing.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ timeout = "60s"
1010
driver = "memory"
1111

1212
[s3]
13+
driver = "file"
1314

1415
[auth]
1516
password_salt = "test"

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ require (
3535
github.com/redis/go-redis/v9 v9.7.3
3636
github.com/samber/lo v1.49.1
3737
github.com/sony/sonyflake v1.2.0
38+
github.com/spf13/afero v1.2.1
3839
github.com/tuihub/protos v0.5.0
3940
go.opentelemetry.io/otel v1.34.0
4041
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.10.0

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,7 @@ github.com/sony/gobreaker v1.0.0 h1:feX5fGGXSl3dYd4aHZItw+FpHLvvoaqkawKjVNiFMNQ=
668668
github.com/sony/gobreaker v1.0.0/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY=
669669
github.com/sony/sonyflake v1.2.0 h1:Pfr3A+ejSg+0SPqpoAmQgEtNDAhc2G1SUYk205qVMLQ=
670670
github.com/sony/sonyflake v1.2.0/go.mod h1:LORtCywH/cq10ZbyfhKrHYgAUGH7mOBa76enV9txy/Y=
671+
github.com/spf13/afero v1.2.1 h1:qgMbHoJbPbw579P+1zVY+6n4nIFuIchaIjzZ/I/Yq8M=
671672
github.com/spf13/afero v1.2.1/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
672673
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
673674
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=

internal/biz/bizbinah/binah.go

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package bizbinah
22

33
import (
4-
"context"
5-
"io"
6-
"time"
7-
4+
"github.com/tuihub/librarian/internal/data"
85
"github.com/tuihub/librarian/internal/lib/libauth"
96
"github.com/tuihub/librarian/internal/model/modelbinah"
107

@@ -17,27 +14,13 @@ var ProviderSet = wire.NewSet(
1714
)
1815

1916
type Binah struct {
20-
repo BinahRepo
17+
repo *data.BinahRepo
2118
callback *modelbinah.ControlBlock
2219
auth *libauth.Auth
2320
}
2421

25-
type BinahRepo interface {
26-
FeatureEnabled() bool
27-
PutObject(context.Context, io.Reader, Bucket, string) error
28-
PresignedGetObject(context.Context, Bucket, string, time.Duration) (string, error)
29-
PresignedPutObject(context.Context, Bucket, string, time.Duration) (string, error)
30-
}
31-
32-
type Bucket int
33-
34-
const (
35-
BucketUnspecified Bucket = iota
36-
BucketDefault
37-
)
38-
3922
func NewBinah(
40-
repo BinahRepo,
23+
repo *data.BinahRepo,
4124
callback *modelbinah.ControlBlock,
4225
auth *libauth.Auth,
4326
) *Binah {

internal/biz/bizbinah/presigned.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"strconv"
66

7+
"github.com/tuihub/librarian/internal/data"
78
"github.com/tuihub/librarian/internal/lib/libtime"
89
pb "github.com/tuihub/protos/pkg/librarian/sephirah/v1"
910

@@ -15,7 +16,7 @@ func (b *Binah) PresignedUploadFile(ctx context.Context) (string, *errors.Error)
1516
if err != nil {
1617
return "", pb.ErrorErrorReasonUnspecified("%s", err.Error())
1718
}
18-
res, err := b.repo.PresignedPutObject(ctx, BucketDefault, strconv.FormatInt(int64(metadata.ID), 10), libtime.Day)
19+
res, err := b.repo.PresignedPutObject(ctx, data.BucketDefault, strconv.FormatInt(int64(metadata.ID), 10), libtime.Day)
1920
if err != nil {
2021
return "", pb.ErrorErrorReasonUnspecified("%s", err.Error())
2122
}
@@ -43,7 +44,7 @@ func (b *Binah) PresignedDownloadFile(ctx context.Context) (string, *errors.Erro
4344
if err != nil {
4445
return "", pb.ErrorErrorReasonUnspecified("%s", err.Error())
4546
}
46-
res, err := b.repo.PresignedGetObject(ctx, BucketDefault, strconv.FormatInt(int64(metadata.ID), 10), libtime.Day)
47+
res, err := b.repo.PresignedGetObject(ctx, data.BucketDefault, strconv.FormatInt(int64(metadata.ID), 10), libtime.Day)
4748
if err != nil {
4849
return "", pb.ErrorErrorReasonUnspecified("%s", err.Error())
4950
}

internal/biz/bizbinah/simple.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"strconv"
88

9+
"github.com/tuihub/librarian/internal/data"
910
"github.com/tuihub/librarian/internal/model"
1011
"github.com/tuihub/librarian/internal/model/modelbinah"
1112
pb "github.com/tuihub/protos/pkg/librarian/sephirah/v1"
@@ -16,7 +17,7 @@ import (
1617

1718
type SimpleUploadFile struct {
1819
id model.InternalID
19-
repo BinahRepo
20+
repo *data.BinahRepo
2021
callback modelbinah.CallbackFunc
2122
file *os.File
2223
Writer io.Writer
@@ -53,5 +54,5 @@ func (f *SimpleUploadFile) Finish(ctx context.Context) error {
5354
if err != nil {
5455
return err
5556
}
56-
return f.repo.PutObject(ctx, f.file, BucketDefault, strconv.FormatInt(int64(f.id), 10))
57+
return f.repo.PutObject(ctx, f.file, data.BucketDefault, strconv.FormatInt(int64(f.id), 10))
5758
}

internal/biz/bizchesed/chesed.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"strconv"
66
"sync"
77

8-
"github.com/tuihub/librarian/internal/biz/bizbinah"
98
"github.com/tuihub/librarian/internal/biz/bizutils"
109
"github.com/tuihub/librarian/internal/data"
1110
"github.com/tuihub/librarian/internal/lib/libauth"
@@ -32,7 +31,7 @@ var ProviderSet = wire.NewSet(
3231

3332
type Chesed struct {
3433
repo *data.ChesedRepo
35-
b bizbinah.BinahRepo
34+
b *data.BinahRepo
3635
id *libidgenerator.IDGenerator
3736
search libsearch.Search
3837
porter porter.LibrarianPorterServiceClient
@@ -45,7 +44,7 @@ type Chesed struct {
4544

4645
func NewChesed(
4746
repo *data.ChesedRepo,
48-
b bizbinah.BinahRepo,
47+
b *data.BinahRepo,
4948
id *libidgenerator.IDGenerator,
5049
search libsearch.Search,
5150
cron *libcron.Cron,
@@ -150,7 +149,7 @@ func (c *Chesed) ScanImage(ctx context.Context) error {
150149
return nil
151150
}
152151
for _, image := range images {
153-
data, err := c.b.PresignedGetObject(ctx, bizbinah.BucketDefault, strconv.FormatInt(int64(image.ID), 10), libtime.Day)
152+
data, err := c.b.PresignedGetObject(ctx, data.BucketDefault, strconv.FormatInt(int64(image.ID), 10), libtime.Day)
154153
if err != nil {
155154
return err
156155
}

internal/biz/bizgebura/app.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"github.com/tuihub/librarian/internal/model"
1010
"github.com/tuihub/librarian/internal/model/modelgebura"
1111
pb "github.com/tuihub/protos/pkg/librarian/sephirah/v1"
12+
13+
"github.com/samber/lo"
1214
)
1315

1416
func (g *Gebura) CreateApp(
@@ -41,7 +43,7 @@ func (g *Gebura) UpdateApp(ctx context.Context, a *modelgebura.App) error {
4143
if err != nil {
4244
return pb.ErrorErrorReasonUnspecified("%s", err.Error())
4345
}
44-
if old.BoundStoreAppID != 0 && !a.StopStoreManage {
46+
if old.BoundStoreAppID != nil && !lo.FromPtrOr(a.StopStoreManage, false) {
4547
return pb.ErrorErrorReasonBadRequest("under store manage")
4648
}
4749
err = g.repo.UpdateApp(ctx, claims.UserID, a)

0 commit comments

Comments
 (0)