From a4afda0ecc4e8d5f547f74119bf50e8c9fdbc8db Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Fri, 9 Feb 2024 15:55:04 -0500 Subject: [PATCH] feat: add proof download s5 protocol file discovery --- protocols/s5/s5.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/protocols/s5/s5.go b/protocols/s5/s5.go index f467292..f64d0b4 100644 --- a/protocols/s5/s5.go +++ b/protocols/s5/s5.go @@ -232,7 +232,7 @@ func (s S5ProviderStore) Provide(hash *encoding.Multihash, kind []types.StorageL case types.StorageLocationTypeArchive: return s5storage.NewStorageLocation(int(types.StorageLocationTypeArchive), []string{}, calculateExpiry(24*time.Hour)), nil case types.StorageLocationTypeFile, types.StorageLocationTypeFull: - return s5storage.NewStorageLocation(int(types.StorageLocationTypeFull), []string{generateDownloadUrl(hash, s.config, s.logger)}, calculateExpiry(24*time.Hour)), nil + return s5storage.NewStorageLocation(int(types.StorageLocationTypeFull), []string{generateDownloadUrl(hash, s.config, s.logger), generateProofUrl(hash, s.config, s.logger)}, calculateExpiry(24*time.Hour)), nil } } @@ -257,3 +257,14 @@ func generateDownloadUrl(hash *encoding.Multihash, config *viper.Viper, logger * return fmt.Sprintf("https://s5.%s/s5/download/%s", domain, hashStr) } + +func generateProofUrl(hash *encoding.Multihash, config *viper.Viper, logger *zap.Logger) string { + domain := config.GetString("core.domain") + + hashStr, err := hash.ToBase64Url() + if err != nil { + logger.Error("error encoding hash", zap.Error(err)) + } + + return fmt.Sprintf("https://s5.%s/s5/download/%s.obao", domain, hashStr) +}