mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-25 06:16:58 +00:00
wip
This commit is contained in:
parent
4f2c94c7d9
commit
ec7fcca0f5
8 changed files with 96 additions and 128 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/valyala/fasthttp"
|
||||
|
@ -12,11 +13,21 @@ import (
|
|||
"codeberg.org/codeberg/pages/server/shared"
|
||||
)
|
||||
|
||||
const giteaAPIRepos = "/api/v1/repos/"
|
||||
|
||||
type Client struct {
|
||||
giteaRoot string
|
||||
giteaAPIToken string
|
||||
}
|
||||
|
||||
type FileResponse struct {
|
||||
Exists bool
|
||||
MimeType string
|
||||
Body []byte
|
||||
}
|
||||
|
||||
func (f FileResponse) IsEmpty() bool { return len(f.Body) != 0 }
|
||||
|
||||
func NewClient(giteaRoot, giteaAPIToken string) *Client {
|
||||
return &Client{
|
||||
giteaRoot: giteaRoot,
|
||||
|
@ -24,8 +35,6 @@ func NewClient(giteaRoot, giteaAPIToken string) *Client {
|
|||
}
|
||||
}
|
||||
|
||||
const giteaAPIRepos = "/api/v1/repos/"
|
||||
|
||||
// TODOs:
|
||||
// * own client to store token & giteaRoot
|
||||
// * handle 404 -> page will show 500 atm
|
||||
|
@ -46,6 +55,19 @@ func (client *Client) GiteaRawContent(targetOwner, targetRepo, ref, resource str
|
|||
return res.Body(), nil
|
||||
}
|
||||
|
||||
func (client *Client) ServeRawContent(uri string) (*fasthttp.Response, error) {
|
||||
fastClient := shared.GetFastHTTPClient(10 * time.Second)
|
||||
|
||||
req := fasthttp.AcquireRequest()
|
||||
req.SetRequestURI(path.Join(client.giteaRoot, giteaAPIRepos, uri))
|
||||
req.Header.Set(fasthttp.HeaderAuthorization, client.giteaAPIToken)
|
||||
|
||||
resp := fasthttp.AcquireResponse()
|
||||
resp.SetBodyStream(&strings.Reader{}, -1)
|
||||
|
||||
return resp, fastClient.Do(req, resp)
|
||||
}
|
||||
|
||||
func (client *Client) GiteaGetRepoBranchTimestamp(repoOwner, repoName, branchName string) (time.Time, error) {
|
||||
fastClient := shared.GetFastHTTPClient(5 * time.Second)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue