Add Gitbucket support.

This commit is contained in:
Captain ALM 2023-12-10 14:30:37 +00:00
parent 2e11c55981
commit f5f1625533
Signed by: alfred
GPG Key ID: 4E4ADD02609997B1
3 changed files with 72 additions and 43 deletions

View File

@ -3,19 +3,21 @@ package conf
import "golang.captainalm.com/GOPackageHeaderServer/outputMeta" import "golang.captainalm.com/GOPackageHeaderServer/outputMeta"
type ZoneYaml struct { type ZoneYaml struct {
Name string `yaml:"name"` Name string `yaml:"name"`
Domains []string `yaml:"domains"` Domains []string `yaml:"domains"`
CssURL string `yaml:"cssURL"` CssURL string `yaml:"cssURL"`
HavePageContents bool `yaml:"havePageContents"` HavePageContents bool `yaml:"havePageContents"`
BasePath string `yaml:"basePath"` BasePath string `yaml:"basePath"`
UsernameProvided bool `yaml:"usernameProvided"` //If set, the outputter will do /{user}/{repo}/ for repos rather than /{repo}/ ; Should really be named usernameProvidedByRequest UsernameProvided bool `yaml:"usernameProvided"` //If set, the outputter will do /{user}/{repo}/ for repos rather than /{repo}/ ; Should really be named usernameProvidedByRequest
Username string `yaml:"username"` Username string `yaml:"username"`
BasePrefixURL string `yaml:"basePrefixURL"` BasePrefixURL string `yaml:"basePrefixURL"`
SuffixDirectoryURL string `yaml:"suffixDirectoryURL"` SuffixDirectoryURL string `yaml:"suffixDirectoryURL"`
SuffixFileURL string `yaml:"suffixFileURL"` SuffixFileURL string `yaml:"suffixFileURL"`
RangeSupported bool `yaml:"rangeSupported"` RangeSupported bool `yaml:"rangeSupported"`
PathLengthLimit uint `yaml:"pathLengthLimit"` //The length of the path (Number of entries in the path) to return in the responses; (If 0: defaults to 1, if the username is not expected to be provided by the request, otherwise defaulting to 2) PathLengthLimit uint `yaml:"pathLengthLimit"` //The length of the path (Number of entries in the path) to return in the responses; (If 0: defaults to 1, if the username is not expected to be provided by the request, otherwise defaulting to 2)
CacheSettings CacheSettingsYaml `yaml:"cacheSettings"` SuffixImportURL string `yaml:"suffixImportURL"`
BasePrefixSourceURL string `yaml:"basePrefixSourceURL"`
CacheSettings CacheSettingsYaml `yaml:"cacheSettings"`
} }
func (zy ZoneYaml) GetPackageMetaTagOutputter() *outputMeta.PackageMetaTagOutputter { func (zy ZoneYaml) GetPackageMetaTagOutputter() *outputMeta.PackageMetaTagOutputter {
@ -32,11 +34,13 @@ func (zy ZoneYaml) GetPackageMetaTagOutputter() *outputMeta.PackageMetaTagOutput
} }
} }
return &outputMeta.PackageMetaTagOutputter{ return &outputMeta.PackageMetaTagOutputter{
BasePath: zy.BasePath, BasePath: zy.BasePath,
Username: theUsername, Username: theUsername,
BasePrefixURL: zy.BasePrefixURL, BasePrefixURL: zy.BasePrefixURL,
SuffixDirectoryURL: zy.SuffixDirectoryURL, SuffixDirectoryURL: zy.SuffixDirectoryURL,
SuffixFileURL: zy.SuffixFileURL, SuffixFileURL: zy.SuffixFileURL,
PathLengthLimit: pthLength, PathLengthLimit: pthLength,
SuffixImportURL: zy.SuffixImportURL,
BasePrefixSourceURL: zy.BasePrefixSourceURL,
} }
} }

View File

@ -6,12 +6,14 @@ import (
) )
type PackageMetaTagOutputter struct { type PackageMetaTagOutputter struct {
BasePath string BasePath string
Username string //If set, the outputter will do /{repo}/ for repos rather than /{user}/{repo}/ Username string //If set, the outputter will do /{repo}/ for repos rather than /{user}/{repo}/
BasePrefixURL string BasePrefixURL string
SuffixDirectoryURL string SuffixDirectoryURL string
SuffixFileURL string SuffixFileURL string
PathLengthLimit uint //The number of path entries in the go import paths PathLengthLimit uint //The number of path entries in the go import paths
SuffixImportURL string
BasePrefixSourceURL string //If blank, use BasePrefixURL instead
} }
func (pkgMTO *PackageMetaTagOutputter) GetMetaTags(pathIn string) string { func (pkgMTO *PackageMetaTagOutputter) GetMetaTags(pathIn string) string {
@ -21,12 +23,12 @@ func (pkgMTO *PackageMetaTagOutputter) GetMetaTags(pathIn string) string {
func (pkgMTO *PackageMetaTagOutputter) GetMetaContentForGoImport(pathIn string) string { func (pkgMTO *PackageMetaTagOutputter) GetMetaContentForGoImport(pathIn string) string {
pathLoc := pkgMTO.GetPath(pathIn) pathLoc := pkgMTO.GetPath(pathIn)
return pkgMTO.getPrefix(pathLoc) + " git " + pkgMTO.getHomeURL(pathLoc) return pkgMTO.getPrefix(pathLoc) + " git " + pkgMTO.getHomeURL(pathLoc, false) + pkgMTO.SuffixImportURL
} }
func (pkgMTO *PackageMetaTagOutputter) GetMetaContentForGoSource(pathIn string) string { func (pkgMTO *PackageMetaTagOutputter) GetMetaContentForGoSource(pathIn string) string {
pathLoc := pkgMTO.GetPath(pathIn) pathLoc := pkgMTO.GetPath(pathIn)
return pkgMTO.getPrefix(pathLoc) + " " + pkgMTO.getHomeURL(pathLoc) + " " + return pkgMTO.getPrefix(pathLoc) + " " + pkgMTO.getHomeURL(pathLoc, true) + " " +
pkgMTO.getDirectoryURL(pathLoc) + " " + pkgMTO.getFileURL(pathLoc) pkgMTO.getDirectoryURL(pathLoc) + " " + pkgMTO.getFileURL(pathLoc)
} }
@ -53,6 +55,19 @@ func (pkgMTO *PackageMetaTagOutputter) assureBasePrefixURL() (failed bool) {
return false return false
} }
func (pkgMTO *PackageMetaTagOutputter) assureBasePrefixSourceURL() (failed bool) {
if pkgMTO.BasePrefixSourceURL == "" {
if pkgMTO.assureBasePrefixURL() {
return true
}
if pkgMTO.BasePrefixURL == "" {
return true
}
pkgMTO.BasePrefixSourceURL = pkgMTO.BasePrefixURL
}
return false
}
func (pkgMTO *PackageMetaTagOutputter) getPrefix(pathIn string) string { func (pkgMTO *PackageMetaTagOutputter) getPrefix(pathIn string) string {
if pkgMTO.BasePath == "" { if pkgMTO.BasePath == "" {
return "_" return "_"
@ -60,38 +75,48 @@ func (pkgMTO *PackageMetaTagOutputter) getPrefix(pathIn string) string {
return path.Join(pkgMTO.BasePath, pathIn) return path.Join(pkgMTO.BasePath, pathIn)
} }
func (pkgMTO *PackageMetaTagOutputter) getHomeURL(pathIn string) string { func (pkgMTO *PackageMetaTagOutputter) getHomeURL(pathIn string, isSource bool) string {
if pkgMTO.assureBasePrefixURL() { bpURL := ""
return "_" if isSource {
} if pkgMTO.assureBasePrefixSourceURL() {
return "_"
if pkgMTO.Username == "" { } else {
return pkgMTO.BasePrefixURL + "/" + strings.TrimLeft(path.Clean(pathIn), "/") bpURL = pkgMTO.BasePrefixSourceURL
}
} else { } else {
return pkgMTO.BasePrefixURL + "/" + strings.TrimLeft(path.Join(pkgMTO.Username, pathIn), "/") if pkgMTO.assureBasePrefixURL() {
return "_"
} else {
bpURL = pkgMTO.BasePrefixURL
}
}
if pkgMTO.Username == "" {
return bpURL + "/" + strings.TrimLeft(path.Clean(pathIn), "/")
} else {
return bpURL + "/" + strings.TrimLeft(path.Join(pkgMTO.Username, pathIn), "/")
} }
} }
func (pkgMTO *PackageMetaTagOutputter) getDirectoryURL(pathIn string) string { func (pkgMTO *PackageMetaTagOutputter) getDirectoryURL(pathIn string) string {
if pkgMTO.assureBasePrefixURL() || pkgMTO.SuffixDirectoryURL == "" { if pkgMTO.assureBasePrefixSourceURL() || pkgMTO.SuffixDirectoryURL == "" {
return "_" return "_"
} }
if pkgMTO.Username == "" { if pkgMTO.Username == "" {
return pkgMTO.BasePrefixURL + "/" + strings.TrimLeft(path.Join(pathIn, pkgMTO.SuffixDirectoryURL), "/") return pkgMTO.BasePrefixSourceURL + "/" + strings.TrimLeft(path.Join(pathIn, pkgMTO.SuffixDirectoryURL), "/")
} else { } else {
return pkgMTO.BasePrefixURL + "/" + strings.TrimLeft(path.Join(pkgMTO.Username, pathIn, pkgMTO.SuffixDirectoryURL), "/") return pkgMTO.BasePrefixSourceURL + "/" + strings.TrimLeft(path.Join(pkgMTO.Username, pathIn, pkgMTO.SuffixDirectoryURL), "/")
} }
} }
func (pkgMTO *PackageMetaTagOutputter) getFileURL(pathIn string) string { func (pkgMTO *PackageMetaTagOutputter) getFileURL(pathIn string) string {
if pkgMTO.assureBasePrefixURL() || pkgMTO.SuffixFileURL == "" { if pkgMTO.assureBasePrefixSourceURL() || pkgMTO.SuffixFileURL == "" {
return "_" return "_"
} }
if pkgMTO.Username == "" { if pkgMTO.Username == "" {
return pkgMTO.BasePrefixURL + "/" + strings.TrimLeft(path.Join(pathIn, pkgMTO.SuffixFileURL), "/") return pkgMTO.BasePrefixSourceURL + "/" + strings.TrimLeft(path.Join(pathIn, pkgMTO.SuffixFileURL), "/")
} else { } else {
return pkgMTO.BasePrefixURL + "/" + strings.TrimLeft(path.Join(pkgMTO.Username, pathIn, pkgMTO.SuffixFileURL), "/") return pkgMTO.BasePrefixSourceURL + "/" + strings.TrimLeft(path.Join(pkgMTO.Username, pathIn, pkgMTO.SuffixFileURL), "/")
} }
} }

View File

@ -20,8 +20,8 @@ func (htm handlerTemplateMarshal) GetGoSourceMetaContent() string {
func (htm handlerTemplateMarshal) GetLink() string { func (htm handlerTemplateMarshal) GetLink() string {
if htm.PageHandler.MetaOutput.Username == "" { if htm.PageHandler.MetaOutput.Username == "" {
return htm.PageHandler.MetaOutput.BasePrefixURL + "/" + strings.TrimLeft(path.Clean(htm.PageHandler.MetaOutput.GetPath(htm.RequestPath)), "/") return htm.PageHandler.MetaOutput.BasePrefixSourceURL + "/" + strings.TrimLeft(path.Clean(htm.PageHandler.MetaOutput.GetPath(htm.RequestPath)), "/")
} else { } else {
return htm.PageHandler.MetaOutput.BasePrefixURL + "/" + strings.TrimLeft(path.Join(htm.PageHandler.MetaOutput.Username, htm.PageHandler.MetaOutput.GetPath(htm.RequestPath)), "/") return htm.PageHandler.MetaOutput.BasePrefixSourceURL + "/" + strings.TrimLeft(path.Join(htm.PageHandler.MetaOutput.Username, htm.PageHandler.MetaOutput.GetPath(htm.RequestPath)), "/")
} }
} }