mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-30 01:53:34 +02:00
57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
package upstream
|
|
|
|
import (
|
|
"mime"
|
|
"path"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"codeberg.org/codeberg/pages/server/gitea"
|
|
)
|
|
|
|
// GetBranchTimestamp finds the default branch (if branch is "") and returns the last modification time of the branch
|
|
// (or nil if the branch doesn't exist)
|
|
func GetBranchTimestamp(giteaClient *gitea.Client, owner, repo, branch string) *gitea.BranchTimestamp {
|
|
if len(branch) == 0 {
|
|
// Get default branch
|
|
defaultBranch, err := giteaClient.GiteaGetRepoDefaultBranch(owner, repo)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
branch = defaultBranch
|
|
}
|
|
|
|
timestamp, err := giteaClient.GiteaGetRepoBranchTimestamp(owner, repo, branch)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
return timestamp
|
|
}
|
|
|
|
func (o *Options) getMimeTypeByExtension() string {
|
|
if o.ForbiddenMimeTypes == nil {
|
|
o.ForbiddenMimeTypes = make(map[string]bool)
|
|
}
|
|
mimeType := mime.TypeByExtension(path.Ext(o.TargetPath))
|
|
mimeTypeSplit := strings.SplitN(mimeType, ";", 2)
|
|
if o.ForbiddenMimeTypes[mimeTypeSplit[0]] || mimeType == "" {
|
|
if o.DefaultMimeType != "" {
|
|
mimeType = o.DefaultMimeType
|
|
} else {
|
|
mimeType = "application/octet-stream"
|
|
}
|
|
}
|
|
return mimeType
|
|
}
|
|
|
|
func (o *Options) generateUri() string {
|
|
return path.Join(o.TargetOwner, o.TargetRepo, "raw", o.TargetBranch, o.TargetPath)
|
|
}
|
|
|
|
func (o *Options) generateUriClientArgs() (targetOwner, targetRepo, ref, resource string) {
|
|
return o.TargetOwner, o.TargetRepo, o.TargetBranch, o.TargetPath
|
|
}
|
|
|
|
func (o *Options) timestamp() string {
|
|
return strconv.FormatInt(o.BranchTimestamp.Unix(), 10)
|
|
}
|