diff --git a/server/gitea/client.go b/server/gitea/client.go index 0cf6e6c..5633bf2 100644 --- a/server/gitea/client.go +++ b/server/gitea/client.go @@ -49,6 +49,7 @@ const ( type Client struct { sdkClient *gitea.Client + sdkFileClient *gitea.Client responseCache cache.ICache giteaRoot string @@ -68,8 +69,6 @@ func NewClient(cfg config.ForgeConfig, respCache cache.ICache) (*Client, error) } giteaRoot := strings.TrimSuffix(rootURL.String(), "/") - stdClient := http.Client{Timeout: 10 * time.Second} - forbiddenMimeTypes := make(map[string]bool, len(cfg.ForbiddenMimeTypes)) for _, mimeType := range cfg.ForbiddenMimeTypes { forbiddenMimeTypes[mimeType] = true @@ -80,15 +79,26 @@ func NewClient(cfg config.ForgeConfig, respCache cache.ICache) (*Client, error) defaultMimeType = "application/octet-stream" } - sdk, err := gitea.NewClient( + sdkClient, err := gitea.NewClient( giteaRoot, - gitea.SetHTTPClient(&stdClient), + gitea.SetHTTPClient(&http.Client{Timeout: 10 * time.Second}), + gitea.SetToken(cfg.Token), + gitea.SetUserAgent("pages-server/"+version.Version), + ) + if err != nil { + return nil, err + } + + sdkFileClient, err := gitea.NewClient( + giteaRoot, + gitea.SetHTTPClient(&http.Client{Timeout: 1 * time.Hour}), gitea.SetToken(cfg.Token), gitea.SetUserAgent("pages-server/"+version.Version), ) return &Client{ - sdkClient: sdk, + sdkClient: sdkClient, + sdkFileClient: sdkFileClient, responseCache: respCache, giteaRoot: giteaRoot, @@ -154,7 +164,7 @@ func (client *Client) ServeRawContent(ctx *context.Context, targetOwner, targetR } log.Trace().Msg("file not in cache") // not in cache, open reader via gitea api - reader, resp, err := client.sdkClient.GetFileReader(targetOwner, targetRepo, ref, resource, client.supportLFS) + reader, resp, err := client.sdkFileClient.GetFileReader(targetOwner, targetRepo, ref, resource, client.supportLFS) if resp != nil { switch resp.StatusCode { case http.StatusOK: