From 7cef5190c1c8f8045d92b4b6c727e16fbae8ab42 Mon Sep 17 00:00:00 2001 From: Victor Elias Date: Thu, 23 May 2024 12:46:15 +0100 Subject: [PATCH] task: Fix usages of api.AssetSpec.Storage field, now a ptr Sometimes I hate go verbosity --- task/runner.go | 3 ++- task/upload.go | 13 +++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/task/runner.go b/task/runner.go index c4e6781..16f9bfa 100644 --- a/task/runner.go +++ b/task/runner.go @@ -661,7 +661,8 @@ func deleteAsset(asset *api.Asset, r *runner, ctx context.Context) error { glog.Infof("Deleted %v files from asset=%v", totalDeleted, asset.ID) - if ipfs := asset.AssetSpec.Storage.IPFS; ipfs != nil { + if storage := asset.AssetSpec.Storage; storage != nil && storage.IPFS != nil { + ipfs := storage.IPFS err = r.UnpinFromIpfs(ctx, ipfs.CID, "cid") if err != nil { glog.Errorf("Error unpinning from IPFS %v", ipfs.CID) diff --git a/task/upload.go b/task/upload.go index 712dd54..14745dc 100644 --- a/task/upload.go +++ b/task/upload.go @@ -475,6 +475,11 @@ func processCatalystCallback(tctx *TaskContext, callback *clients.CatalystCallba }) } case OutputNameIPFSSourceMP4: + if assetSpec.Storage == nil { + assetSpec.Storage = &api.AssetStorage{IPFS: &api.AssetIPFS{}} + } else if assetSpec.Storage.IPFS == nil { + assetSpec.Storage.IPFS = &api.AssetIPFS{} + } assetSpec.Storage.IPFS.CID = output.Manifest default: return nil, fmt.Errorf("unknown output name=%q for output=%+v", outName, output) @@ -552,8 +557,8 @@ func complementCatalystPipeline(tctx *TaskContext, assetSpec api.AssetSpec) (*da } defer contents.Close() - ipfsSpec := tctx.OutputAsset.Storage.IPFS - ipfsRequired := ipfsSpec != nil && ipfsSpec.Spec != nil + storage := tctx.OutputAsset.Storage + ipfsRequired := storage != nil && storage.IPFS != nil && storage.IPFS.Spec != nil if !ipfsRequired && catalystCopiedSource { glog.Infof("Skipping file download") return &data.UploadTaskOutput{AssetSpec: assetSpec}, nil @@ -591,7 +596,7 @@ func complementCatalystPipeline(tctx *TaskContext, assetSpec api.AssetSpec) (*da } if ipfsRequired { - ipfs := *ipfsSpec + ipfs := *storage.IPFS if !FlagCatalystSupportsIPFS { // TODO: Remove this branch once we have reliable catalyst IPFS support var ( @@ -724,7 +729,7 @@ func uploadTaskOutputLocations(tctx *TaskContext) ([]OutputName, []clients.Outpu return nil, nil, err } // Add Pinata output location - if FlagCatalystSupportsIPFS && tctx.OutputAsset.Storage.IPFS != nil { + if FlagCatalystSupportsIPFS && tctx.OutputAsset.Storage != nil && tctx.OutputAsset.Storage.IPFS != nil { // TODO: This interface is likely going to change so that pinata is just a // `object_store` output outputNames, outputLocations =