chore: update default storage back to database

This commit is contained in:
Steven
2023-10-05 13:36:33 +08:00
parent 077bf95425
commit 34ae9b0687
7 changed files with 23 additions and 12 deletions

View File

@ -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 {

View File

@ -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)

View File

@ -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,
}

View File

@ -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,
}
}