From 1184ec6caea090aba800f37aa4ea379e2580e938 Mon Sep 17 00:00:00 2001 From: Acha Bill Date: Wed, 15 Jan 2025 14:15:36 -0500 Subject: [PATCH] fix: upload and download --- pkg/bee/api/api.go | 6 ++++++ pkg/bee/api/dirs.go | 7 +++++++ pkg/check/manifest/manifest.go | 10 +++++----- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/pkg/bee/api/api.go b/pkg/bee/api/api.go index d990bd49..265a8491 100644 --- a/pkg/bee/api/api.go +++ b/pkg/bee/api/api.go @@ -34,6 +34,8 @@ const ( swarmSocSignatureHeader = "Swarm-Soc-Signature" swarmFeedIndexHeader = "Swarm-Feed-Index" swarmFeedIndexNextHeader = "Swarm-Feed-Index-Next" + swarmIndexDocumentHeader = "Swarm-Index-Document" + swarmErrorDocumentHeader = "Swarm-Error-Document" ) var userAgent = "beekeeper/" + beekeeper.Version @@ -340,6 +342,10 @@ type UploadOptions struct { BatchID string Direct bool ActHistoryAddress swarm.Address + + // Dirs + IndexDocument string + ErrorDocument string } type DownloadOptions struct { diff --git a/pkg/bee/api/dirs.go b/pkg/bee/api/dirs.go index 502e7a3c..22f5f002 100644 --- a/pkg/bee/api/dirs.go +++ b/pkg/bee/api/dirs.go @@ -30,6 +30,13 @@ func (s *DirsService) Upload(ctx context.Context, data io.Reader, size int64, o header.Set("swarm-collection", "True") header.Set(postageStampBatchHeader, o.BatchID) + if o.IndexDocument != "" { + header.Set(swarmIndexDocumentHeader, o.IndexDocument) + } + if o.ErrorDocument != "" { + header.Set(swarmErrorDocumentHeader, o.ErrorDocument) + } + err = s.client.requestWithHeader(ctx, http.MethodPost, "/"+apiVersion+"/bzz", header, data, &resp) return diff --git a/pkg/check/manifest/manifest.go b/pkg/check/manifest/manifest.go index 81ccd8b8..a0cafc99 100644 --- a/pkg/check/manifest/manifest.go +++ b/pkg/check/manifest/manifest.go @@ -162,7 +162,7 @@ func (c *Check) checkWithSubDirs(ctx context.Context, rnd *rand.Rand, o Options, return err } tarFile := bee.NewBufferFile("", tarReader) - if err := upClient.UploadCollection(ctx, &tarFile, api.UploadOptions{BatchID: batchID}); err != nil { + if err := upClient.UploadCollection(ctx, &tarFile, api.UploadOptions{BatchID: batchID, IndexDocument: "index.html"}); err != nil { return err } c.logger.Infof("collection uploaded: %s", tarFile.Address()) @@ -181,18 +181,18 @@ func (c *Check) checkWithSubDirs(ctx context.Context, rnd *rand.Rand, o Options, return err } - // update index.html file - tmp, err := generateFilesWithPaths(rnd, []string{"index.html"}, int(o.MaxPathnameLength)) + // update website files + files, err = generateFilesWithPaths(rnd, paths, int(o.MaxPathnameLength)) if err != nil { return err } - files[0] = tmp[0] + tarReader, err = tarFiles(files) if err != nil { return err } tarFile = bee.NewBufferFile("", tarReader) - if err := upClient.UploadCollection(ctx, &tarFile, api.UploadOptions{BatchID: batchID, Direct: true}); err != nil { + if err := upClient.UploadCollection(ctx, &tarFile, api.UploadOptions{BatchID: batchID, IndexDocument: "index.html"}); err != nil { return err } time.Sleep(3 * time.Second)