This commit is contained in:
6543 2022-07-27 15:48:48 +02:00
parent a8afb372dd
commit 33298aa8ff
No known key found for this signature in database
GPG key ID: C99B82E40B027BAE
3 changed files with 37 additions and 15 deletions

View file

@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"net/http"
"strings"
"time"
@ -43,7 +42,7 @@ type Options struct {
}
// Upstream requests a file from the Gitea API at GiteaRoot and writes it to the request context.
func (o *Options) Upstream(ctx *http.Response, giteaClient *gitea.Client) (final bool) {
func (o *Options) Upstream(ctx *fasthttp.RequestCtx, giteaClient *gitea.Client) (final bool) {
log := log.With().Strs("upstream", []string{o.TargetOwner, o.TargetRepo, o.TargetBranch, o.TargetPath}).Logger()
// Check if the branch exists and when it was modified
@ -74,14 +73,11 @@ func (o *Options) Upstream(ctx *http.Response, giteaClient *gitea.Client) (final
// Make a GET request to the upstream URL
uri := o.generateUri()
var res *fasthttp.Response
var cachedResponse gitea.FileResponse
var err error
if cachedValue, ok := fileResponseCache.Get(uri + "?timestamp=" + o.timestamp()); ok && !cachedValue.(gitea.FileResponse).IsEmpty() {
cachedResponse = cachedValue.(gitea.FileResponse)
} else {
res, err = giteaClient.ServeRawContent(o.generateUriClientArgs())
}
// if cachedValue, ok := fileResponseCache.Get(uri + "?timestamp=" + o.timestamp()); ok && !cachedValue.(gitea.FileResponse).IsEmpty() {
// cachedResponse = cachedValue.(gitea.FileResponse)
// } else {
res, err := giteaClient.ServeRawContent(o.generateUriClientArgs())
log.Debug().Msg("acquisition")
// Handle errors