GetFile: Use "ref" in-query if posible #491
|
@ -116,9 +116,12 @@ type FileDeleteResponse struct {
|
|||
}
|
||||
|
||||
// GetFile downloads a file of repository, ref can be branch/tag/commit.
|
||||
// e.g.: ref -> master, tree -> macaron.go(no leading slash)
|
||||
func (c *Client) GetFile(user, repo, ref, tree string) ([]byte, *Response, error) {
|
||||
return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/raw/%s/%s", user, repo, ref, tree), nil, nil)
|
||||
// e.g.: ref -> master, tree -> README.md (no leading slash)
|
||||
func (c *Client) GetFile(owner, repo, ref, tree string) ([]byte, *Response, error) {
|
||||
if c.checkServerVersionGreaterThanOrEqual(version1_14_0) != nil {
|
||||
return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/raw/%s/%s", owner, repo, ref, tree), nil, nil)
|
||||
}
|
||||
return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/raw/%s?ref=%s", owner, repo, tree, ref), nil, nil)
|
||||
6543 marked this conversation as resolved
Outdated
|
||||
}
|
||||
6543 marked this conversation as resolved
Outdated
zeripath
commented
tree needs to be e.g. from Gitea modules/util
as does ref and tree on line 123 tree needs to be `util.PathEscapeSegments` or something like it.
e.g. from Gitea modules/util
```
// PathEscapeSegments escapes segments of a path while not escaping forward slash
func PathEscapeSegments(path string) string {
slice := strings.Split(path, "/")
for index := range slice {
slice[index] = url.PathEscape(slice[index])
}
escapedPath := strings.Join(slice, "/")
return escapedPath
}
```
as does ref and tree on line 123
6543
commented
this is a more genneral issue witch I like to catch with #273 since we need this not only for this function... this is a more genneral issue witch I like to catch with #273 since we need this not only for this function...
|
||||
|
||||
// GetContents get the metadata and contents of a file in a repository
|
||||
|
|
Loading…
Reference in New Issue
Block a user
tree and ref should both be escaped properly.
ref is simple as it's url.QueryEscape but tree needs escaping using the partial pathescape.