mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: update resource storage type comment
This commit is contained in:
@@ -26,8 +26,11 @@ type ResourceStorageType int32
|
||||
|
||||
const (
|
||||
ResourceStorageType_RESOURCE_STORAGE_TYPE_UNSPECIFIED ResourceStorageType = 0
|
||||
// Resource is stored locally. AKA, local file system.
|
||||
ResourceStorageType_LOCAL ResourceStorageType = 1
|
||||
// Resource is stored in S3.
|
||||
ResourceStorageType_S3 ResourceStorageType = 2
|
||||
// Resource is stored in an external storage. The reference is a URL.
|
||||
ResourceStorageType_EXTERNAL ResourceStorageType = 3
|
||||
)
|
||||
|
||||
|
@@ -9,8 +9,11 @@ option go_package = "gen/store";
|
||||
|
||||
enum ResourceStorageType {
|
||||
RESOURCE_STORAGE_TYPE_UNSPECIFIED = 0;
|
||||
// Resource is stored locally. AKA, local file system.
|
||||
LOCAL = 1;
|
||||
// Resource is stored in S3.
|
||||
S3 = 2;
|
||||
// Resource is stored in an external storage. The reference is a URL.
|
||||
EXTERNAL = 3;
|
||||
}
|
||||
|
||||
|
@@ -129,17 +129,14 @@ func (s *APIV1Service) GetResource(ctx context.Context, request *v1pb.GetResourc
|
||||
}
|
||||
|
||||
func (s *APIV1Service) GetResourceBinary(ctx context.Context, request *v1pb.GetResourceBinaryRequest) (*httpbody.HttpBody, error) {
|
||||
resourceFind := &store.FindResource{
|
||||
GetBlob: true,
|
||||
}
|
||||
if request.Name != "" {
|
||||
resourceUID, err := ExtractResourceUIDFromName(request.Name)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.InvalidArgument, "invalid resource id: %v", err)
|
||||
}
|
||||
resourceFind.UID = &resourceUID
|
||||
}
|
||||
resource, err := s.Store.GetResource(ctx, resourceFind)
|
||||
resource, err := s.Store.GetResource(ctx, &store.FindResource{
|
||||
GetBlob: true,
|
||||
UID: &resourceUID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to get resource: %v", err)
|
||||
}
|
||||
@@ -366,7 +363,7 @@ func SaveResourceBlob(ctx context.Context, s *store.Store, create *store.Resourc
|
||||
}
|
||||
|
||||
func (s *APIV1Service) GetResourceBlob(resource *store.Resource) ([]byte, error) {
|
||||
blob := resource.Blob
|
||||
// For local storage, read the file from the local disk.
|
||||
if resource.StorageType == storepb.ResourceStorageType_LOCAL {
|
||||
resourcePath := filepath.FromSlash(resource.Reference)
|
||||
if !filepath.IsAbs(resourcePath) {
|
||||
@@ -381,12 +378,14 @@ func (s *APIV1Service) GetResourceBlob(resource *store.Resource) ([]byte, error)
|
||||
return nil, errors.Wrap(err, "failed to open the file")
|
||||
}
|
||||
defer file.Close()
|
||||
blob, err = io.ReadAll(file)
|
||||
blob, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to read the file")
|
||||
}
|
||||
}
|
||||
return blob, nil
|
||||
}
|
||||
// For database storage, return the blob from the database.
|
||||
return resource.Blob, nil
|
||||
}
|
||||
|
||||
const (
|
||||
|
Reference in New Issue
Block a user