mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
refactor: store cache
This commit is contained in:
@@ -26,6 +26,7 @@ import (
|
||||
"github.com/usememos/memos/plugin/storage/s3"
|
||||
v1pb "github.com/usememos/memos/proto/gen/api/v1"
|
||||
storepb "github.com/usememos/memos/proto/gen/store"
|
||||
"github.com/usememos/memos/server/profile"
|
||||
"github.com/usememos/memos/store"
|
||||
)
|
||||
|
||||
@@ -71,7 +72,7 @@ func (s *APIV1Service) CreateResource(ctx context.Context, request *v1pb.CreateR
|
||||
}
|
||||
create.Size = int64(size)
|
||||
create.Blob = request.Resource.Content
|
||||
if err := SaveResourceBlob(ctx, s.Store, create); err != nil {
|
||||
if err := SaveResourceBlob(ctx, s.Profile, s.Store, create); err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to save resource blob: %v", err)
|
||||
}
|
||||
|
||||
@@ -286,8 +287,8 @@ func (s *APIV1Service) convertResourceFromStore(ctx context.Context, resource *s
|
||||
}
|
||||
|
||||
// SaveResourceBlob save the blob of resource based on the storage config.
|
||||
func SaveResourceBlob(ctx context.Context, s *store.Store, create *store.Resource) error {
|
||||
workspaceStorageSetting, err := s.GetWorkspaceStorageSetting(ctx)
|
||||
func SaveResourceBlob(ctx context.Context, profile *profile.Profile, stores *store.Store, create *store.Resource) error {
|
||||
workspaceStorageSetting, err := stores.GetWorkspaceStorageSetting(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Failed to find workspace storage setting")
|
||||
}
|
||||
@@ -308,7 +309,7 @@ func SaveResourceBlob(ctx context.Context, s *store.Store, create *store.Resourc
|
||||
// Ensure the directory exists.
|
||||
osPath := filepath.FromSlash(internalPath)
|
||||
if !filepath.IsAbs(osPath) {
|
||||
osPath = filepath.Join(s.Profile.Data, osPath)
|
||||
osPath = filepath.Join(profile.Data, osPath)
|
||||
}
|
||||
dir := filepath.Dir(osPath)
|
||||
if err = os.MkdirAll(dir, os.ModePerm); err != nil {
|
||||
|
Reference in New Issue
Block a user