This commit is contained in:
6543 2022-07-27 14:57:17 +02:00
parent 14e2366f8e
commit b2b22872a2
No known key found for this signature in database
GPG key ID: C99B82E40B027BAE

View file

@ -3,7 +3,6 @@
package gitea
import (
"bytes"
"fmt"
"io"
"net/http"
@ -38,15 +37,7 @@ func NewClient(giteaRoot, giteaAPIToken string, fileResponseCache cache.SetGetKe
}
func (client *Client) GiteaRawContent(targetOwner, targetRepo, ref, resource string) ([]byte, error) {
// var apiURL string
// if client.supportLFS {
// apiURL = joinURL(client.giteaRoot, giteaAPIRepos, targetOwner, targetRepo, "media", resource+"?ref="+url.QueryEscape(ref))
// } else {
// apiURL = joinURL(client.giteaRoot, giteaAPIRepos, targetOwner, targetRepo, "raw", resource+"?ref="+url.QueryEscape(ref))
// }
// TODO: sdk client support media api!!!
rawBytes, resp, err := client.sdkClient.GetFile(targetOwner, targetRepo, ref, resource)
rawBytes, resp, err := client.sdkClient.GetFile(targetOwner, targetRepo, ref, resource, client.supportLFS)
if err != nil {
return nil, err
}
@ -62,15 +53,14 @@ func (client *Client) GiteaRawContent(targetOwner, targetRepo, ref, resource str
}
func (client *Client) ServeRawContent(targetOwner, targetRepo, ref, resource string) (io.ReadCloser, error) {
// TODO: add func that return io.ReadCloser or io.ReadSeekCloser?
rawBytes, resp, err := client.sdkClient.GetFile(targetOwner, targetRepo, ref, resource)
reader, resp, err := client.sdkClient.GetFileReader(targetOwner, targetRepo, ref, resource, client.supportLFS)
if err != nil {
return nil, err
}
switch resp.StatusCode {
case http.StatusOK:
return io.NopCloser(bytes.NewReader(rawBytes)), nil
return reader, nil
case http.StatusNotFound:
return nil, ErrorNotFound
default: