diff --git a/sitesd/sites/sites.go b/sitesd/sites/sites.go index 2bd7b100e..00bd20ab8 100644 --- a/sitesd/sites/sites.go +++ b/sitesd/sites/sites.go @@ -12,8 +12,8 @@ import ( "path/filepath" "strings" + lexutil "github.com/bluesky-social/indigo/lex/util" indigoxrpc "github.com/bluesky-social/indigo/xrpc" - "tangled.org/core/api/tangled" "tangled.org/core/appview/models" "tangled.org/core/sitesd/cloudflare" "tangled.org/core/sitesd/config" @@ -37,7 +37,7 @@ func Deploy( } defer os.RemoveAll(tmpDir) - if err := extractArchive(ctx, config, f, branch, tmpDir); err != nil { + if err := extractArchive(ctx, f, branch, tmpDir); err != nil { return fmt.Errorf("extracting archive: %w", err) } @@ -98,20 +98,26 @@ func collectFiles(deployRoot string) (map[string][]byte, error) { return files, nil } -func extractArchive(ctx context.Context, config *config.Config, f *models.Repo, branch, destDir string) error { - scheme := "https" - if config.Core.Dev { - scheme = "http" - } - knotHost := fmt.Sprintf("%s://%s", scheme, f.Knot) +const archiveNSID = "org.tangled.git.getArchive" - xrpcc := &indigoxrpc.Client{Host: knotHost} - data, err := tangled.RepoArchive(ctx, xrpcc, "tar.gz", "", branch, f.RepoIdentifier()) - if err != nil { +// the archive prefix is stripped again on extract, so its name doesn't matter +const archivePrefix = "site/" + +func extractArchive(ctx context.Context, f *models.Repo, branch, destDir string) error { + // plain http to a dev knot only reaches caddy's redirect, so always ask over https + xrpcc := &indigoxrpc.Client{Host: "https://" + f.Knot} + params := map[string]any{ + "repo": f.RepoDid, + "ref": branch, + "format": "tar.gz", + "prefix": archivePrefix, + } + var data bytes.Buffer + if err := xrpcc.LexDo(ctx, lexutil.Query, "", archiveNSID, params, nil, &data); err != nil { return fmt.Errorf("fetching archive: %w", err) } - return extractTarGz(bytes.NewReader(data), destDir) + return extractTarGz(&data, destDir) } // strip git archive prefix, rejecting paths outside the destination