diff --git a/api/v1/resource.go b/api/v1/resource.go index 3d551640..b2f4f9a6 100644 --- a/api/v1/resource.go +++ b/api/v1/resource.go @@ -567,7 +567,7 @@ func SaveResourceBlob(ctx context.Context, s *store.Store, create *store.Resourc return errors.Wrap(err, "Failed to find SystemSettingStorageServiceIDName") } - storageServiceID := LocalStorage + storageServiceID := DefaultStorage if systemSettingStorageServiceID != nil { err = json.Unmarshal([]byte(systemSettingStorageServiceID.Value), &storageServiceID) if err != nil { diff --git a/api/v1/storage.go b/api/v1/storage.go index e3c8180f..8301eae3 100644 --- a/api/v1/storage.go +++ b/api/v1/storage.go @@ -13,10 +13,11 @@ import ( const ( // LocalStorage means the storage service is local file system. - // Default storage service is local file system. LocalStorage int32 = -1 // DatabaseStorage means the storage service is database. DatabaseStorage int32 = 0 + // Default storage service is database. + DefaultStorage int32 = DatabaseStorage ) type StorageType string @@ -212,7 +213,7 @@ func (s *APIV1Service) DeleteStorage(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find storage").SetInternal(err) } if systemSetting != nil { - storageServiceID := LocalStorage + storageServiceID := DefaultStorage err = json.Unmarshal([]byte(systemSetting.Value), &storageServiceID) if err != nil { return echo.NewHTTPError(http.StatusInternalServerError, "Failed to unmarshal storage service id").SetInternal(err) diff --git a/api/v1/system.go b/api/v1/system.go index 0c0cb7a3..adbb438e 100644 --- a/api/v1/system.go +++ b/api/v1/system.go @@ -89,7 +89,7 @@ func (s *APIV1Service) GetSystemStatus(c echo.Context) error { Appearance: "system", ExternalURL: "", }, - StorageServiceID: LocalStorage, + StorageServiceID: DefaultStorage, LocalStoragePath: "assets/{timestamp}_{filename}", MemoDisplayWithUpdatedTs: false, } diff --git a/api/v2/resource_service.go b/api/v2/resource_service.go index 3c550767..209dede4 100644 --- a/api/v2/resource_service.go +++ b/api/v2/resource_service.go @@ -39,7 +39,7 @@ func (s *ResourceService) ListResources(ctx context.Context, _ *apiv2pb.ListReso response := &apiv2pb.ListResourcesResponse{} for _, resource := range resources { - response.Resources = append(response.Resources, convertResourceFromStore(resource)) + response.Resources = append(response.Resources, s.convertResourceFromStore(ctx, resource)) } return response, nil } @@ -63,7 +63,7 @@ func (s *ResourceService) UpdateResource(ctx context.Context, request *apiv2pb.U return nil, status.Errorf(codes.Internal, "failed to update resource: %v", err) } return &apiv2pb.UpdateResourceResponse{ - Resource: convertResourceFromStore(resource), + Resource: s.convertResourceFromStore(ctx, resource), }, nil } @@ -90,7 +90,17 @@ func (s *ResourceService) DeleteResource(ctx context.Context, request *apiv2pb.D return &apiv2pb.DeleteResourceResponse{}, nil } -func convertResourceFromStore(resource *store.Resource) *apiv2pb.Resource { +func (s *ResourceService) convertResourceFromStore(ctx context.Context, resource *store.Resource) *apiv2pb.Resource { + var memoID *int32 + if resource.MemoID != nil { + memo, _ := s.Store.GetMemo(ctx, &store.FindMemo{ + ID: resource.MemoID, + }) + if memo != nil { + memoID = &memo.ID + } + } + return &apiv2pb.Resource{ Id: resource.ID, CreatedTs: timestamppb.New(time.Unix(resource.CreatedTs, 0)), @@ -98,6 +108,6 @@ func convertResourceFromStore(resource *store.Resource) *apiv2pb.Resource { ExternalLink: resource.ExternalLink, Type: resource.Type, Size: resource.Size, - MemoId: resource.MemoID, + MemoId: memoID, } } diff --git a/web/src/components/Settings/StorageSection.tsx b/web/src/components/Settings/StorageSection.tsx index 7119c0e7..6944ad5f 100644 --- a/web/src/components/Settings/StorageSection.tsx +++ b/web/src/components/Settings/StorageSection.tsx @@ -66,13 +66,13 @@ const StorageSection = () => { handleActiveStorageServiceChanged(Number(event.target.value)); }} > -