mirror of
https://codeberg.org/git-pages/git-pages.git
synced 2026-05-14 03:01:48 +00:00
Record git repo URL in manifest for archive uploads with forge auth.
Resolves: https://codeberg.org/git-pages/git-pages/issues/165
This commit is contained in:
@@ -119,6 +119,13 @@ type Authorization struct {
|
||||
forgeUser *ForgeUser
|
||||
}
|
||||
|
||||
func (auth *Authorization) ForgeRepoURL() string {
|
||||
if auth.forgeUser != nil && len(auth.repoURLs) == 1 {
|
||||
return auth.repoURLs[0]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func authorizeDNSChallenge(r *http.Request) (*Authorization, error) {
|
||||
host, err := GetHost(r)
|
||||
if err != nil {
|
||||
|
||||
@@ -437,7 +437,7 @@ func Main(versionInfo string) {
|
||||
}
|
||||
|
||||
webRoot := webRootArg(*updateSite)
|
||||
result = UpdateFromArchive(ctx, webRoot, contentType, file)
|
||||
result = UpdateFromArchive(ctx, webRoot, "", contentType, file)
|
||||
} else {
|
||||
branch := "pages"
|
||||
if sourceURL.Fragment != "" {
|
||||
|
||||
@@ -523,19 +523,22 @@ func putPage(w http.ResponseWriter, r *http.Request) error {
|
||||
result = UpdateFromRepository(ctx, webRoot, repoURL, branch)
|
||||
|
||||
default:
|
||||
if auth, err := AuthorizeUpdateFromArchive(r); err != nil {
|
||||
auth, err := AuthorizeUpdateFromArchive(r)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if auth.forgeUser != nil {
|
||||
GetPrincipal(r.Context()).ForgeUser = auth.forgeUser
|
||||
}
|
||||
|
||||
repoURL := auth.ForgeRepoURL()
|
||||
|
||||
if checkDryRun(w, r) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// request body contains archive
|
||||
reader := http.MaxBytesReader(w, r.Body, int64(config.Limits.MaxSiteSize.Bytes()))
|
||||
result = UpdateFromArchive(ctx, webRoot, contentType, reader)
|
||||
result = UpdateFromArchive(ctx, webRoot, repoURL, contentType, reader)
|
||||
}
|
||||
|
||||
return reportUpdateResult(w, r, result)
|
||||
|
||||
@@ -128,6 +128,7 @@ var errArchiveFormat = errors.New("unsupported archive format")
|
||||
func UpdateFromArchive(
|
||||
ctx context.Context,
|
||||
webRoot string,
|
||||
repoURL string,
|
||||
contentType string,
|
||||
reader io.Reader,
|
||||
) (result UpdateResult) {
|
||||
@@ -162,6 +163,10 @@ func UpdateFromArchive(
|
||||
logc.Printf(ctx, "update %s err: %s", webRoot, err)
|
||||
result = UpdateResult{UpdateError, nil, err}
|
||||
} else {
|
||||
if repoURL != "" {
|
||||
newManifest.RepoUrl = &repoURL
|
||||
}
|
||||
|
||||
result = Update(ctx, webRoot, oldManifest, newManifest, ModifyManifestOptions{})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user