Skip to content

Commit

Permalink
fix: upload and download
Browse files Browse the repository at this point in the history
  • Loading branch information
acha-bill committed Jan 15, 2025
1 parent c7f7bbf commit 1184ec6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
6 changes: 6 additions & 0 deletions pkg/bee/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -340,6 +342,10 @@ type UploadOptions struct {
BatchID string
Direct bool
ActHistoryAddress swarm.Address

// Dirs
IndexDocument string
ErrorDocument string
}

type DownloadOptions struct {
Expand Down
7 changes: 7 additions & 0 deletions pkg/bee/api/dirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions pkg/check/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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)
Expand Down

0 comments on commit 1184ec6

Please sign in to comment.