mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-01-19 08:57:55 +00:00
next
This commit is contained in:
parent
14e2366f8e
commit
b2b22872a2
1 changed files with 3 additions and 13 deletions
|
@ -3,7 +3,6 @@
|
||||||
package gitea
|
package gitea
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"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) {
|
func (client *Client) GiteaRawContent(targetOwner, targetRepo, ref, resource string) ([]byte, error) {
|
||||||
// var apiURL string
|
rawBytes, resp, err := client.sdkClient.GetFile(targetOwner, targetRepo, ref, resource, client.supportLFS)
|
||||||
// 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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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) {
|
func (client *Client) ServeRawContent(targetOwner, targetRepo, ref, resource string) (io.ReadCloser, error) {
|
||||||
// TODO: add func that return io.ReadCloser or io.ReadSeekCloser?
|
reader, resp, err := client.sdkClient.GetFileReader(targetOwner, targetRepo, ref, resource, client.supportLFS)
|
||||||
rawBytes, resp, err := client.sdkClient.GetFile(targetOwner, targetRepo, ref, resource)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
switch resp.StatusCode {
|
switch resp.StatusCode {
|
||||||
case http.StatusOK:
|
case http.StatusOK:
|
||||||
return io.NopCloser(bytes.NewReader(rawBytes)), nil
|
return reader, nil
|
||||||
case http.StatusNotFound:
|
case http.StatusNotFound:
|
||||||
return nil, ErrorNotFound
|
return nil, ErrorNotFound
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in a new issue