|
|
@ -16,6 +16,7 @@ import ( |
|
|
|
"code.gitea.io/gitea/modules/git" |
|
|
|
"code.gitea.io/gitea/modules/git" |
|
|
|
"code.gitea.io/gitea/modules/setting" |
|
|
|
"code.gitea.io/gitea/modules/setting" |
|
|
|
api "code.gitea.io/gitea/modules/structs" |
|
|
|
api "code.gitea.io/gitea/modules/structs" |
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/util" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// ContentType repo content type
|
|
|
|
// ContentType repo content type
|
|
|
@ -159,7 +160,7 @@ func GetContents(ctx context.Context, repo *repo_model.Repository, treePath, ref |
|
|
|
return nil, fmt.Errorf("no commit found for the ref [ref: %s]", ref) |
|
|
|
return nil, fmt.Errorf("no commit found for the ref [ref: %s]", ref) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
selfURL, err := url.Parse(fmt.Sprintf("%s/contents/%s?ref=%s", repo.APIURL(), treePath, origRef)) |
|
|
|
selfURL, err := url.Parse(repo.APIURL() + "/contents/" + util.PathEscapeSegments(treePath) + "?ref=" + url.QueryEscape(origRef)) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
@ -218,7 +219,7 @@ func GetContents(ctx context.Context, repo *repo_model.Repository, treePath, ref |
|
|
|
} |
|
|
|
} |
|
|
|
// Handle links
|
|
|
|
// Handle links
|
|
|
|
if entry.IsRegular() || entry.IsLink() { |
|
|
|
if entry.IsRegular() || entry.IsLink() { |
|
|
|
downloadURL, err := url.Parse(fmt.Sprintf("%s/raw/%s/%s/%s", repo.HTMLURL(), refType, ref, treePath)) |
|
|
|
downloadURL, err := url.Parse(repo.HTMLURL() + "/raw/" + url.PathEscape(string(refType)) + "/" + util.PathEscapeSegments(ref) + "/" + util.PathEscapeSegments(treePath)) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
@ -226,7 +227,7 @@ func GetContents(ctx context.Context, repo *repo_model.Repository, treePath, ref |
|
|
|
contentsResponse.DownloadURL = &downloadURLString |
|
|
|
contentsResponse.DownloadURL = &downloadURLString |
|
|
|
} |
|
|
|
} |
|
|
|
if !entry.IsSubModule() { |
|
|
|
if !entry.IsSubModule() { |
|
|
|
htmlURL, err := url.Parse(fmt.Sprintf("%s/src/%s/%s/%s", repo.HTMLURL(), refType, ref, treePath)) |
|
|
|
htmlURL, err := url.Parse(repo.HTMLURL() + "/src/" + url.PathEscape(string(refType)) + "/" + util.PathEscapeSegments(ref) + "/" + util.PathEscapeSegments(treePath)) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
@ -234,7 +235,7 @@ func GetContents(ctx context.Context, repo *repo_model.Repository, treePath, ref |
|
|
|
contentsResponse.HTMLURL = &htmlURLString |
|
|
|
contentsResponse.HTMLURL = &htmlURLString |
|
|
|
contentsResponse.Links.HTMLURL = &htmlURLString |
|
|
|
contentsResponse.Links.HTMLURL = &htmlURLString |
|
|
|
|
|
|
|
|
|
|
|
gitURL, err := url.Parse(fmt.Sprintf("%s/git/blobs/%s", repo.APIURL(), entry.ID.String())) |
|
|
|
gitURL, err := url.Parse(repo.APIURL() + "/git/blobs/" + url.PathEscape(entry.ID.String())) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|