Skip to content

Commit

Permalink
use PackageRegistryHost
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Nov 7, 2024
1 parent 84ff353 commit 0d9547d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
16 changes: 5 additions & 11 deletions routers/web/user/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,12 @@ func ViewPackageVersion(ctx *context.Context) {
ctx.Data["IsPackagesPage"] = true
ctx.Data["PackageDescriptor"] = pd

curAppURL, _ := url.Parse(httplib.GuessCurrentAppURL(ctx))
packageRegistryHost := curAppURL.Host
ctx.Data["PackageRegistryHost"] = packageRegistryHost

switch pd.Package.Type {
case packages_model.TypeContainer:
registryAppURL, err := url.Parse(httplib.GuessCurrentAppURL(ctx))
if err != nil {
registryAppURL, _ = url.Parse(setting.AppURL)
}
ctx.Data["RegistryHost"] = registryAppURL.Host
case packages_model.TypeAlpine:
branches := make(container.Set[string])
repositories := make(container.Set[string])
Expand All @@ -209,12 +208,7 @@ func ViewPackageVersion(ctx *context.Context) {
ctx.Data["Repositories"] = util.Sorted(repositories.Values())
ctx.Data["Architectures"] = util.Sorted(architectures.Values())
case packages_model.TypeArch:
registryAppURL, err := url.Parse(httplib.GuessCurrentAppURL(ctx))
if err != nil {
registryAppURL, _ = url.Parse(setting.AppURL)
}
ctx.Data["RegistryHost"] = registryAppURL.Host
ctx.Data["SignMail"] = fmt.Sprintf("%s@noreply.%s", ctx.Package.Owner.Name, registryAppURL.Host)
ctx.Data["SignMail"] = fmt.Sprintf("%s@noreply.%s", ctx.Package.Owner.Name, packageRegistryHost)
groups := make(container.Set[string])
for _, f := range pd.Files {
for _, pp := range f.Properties {
Expand Down
2 changes: 1 addition & 1 deletion templates/package/content/arch.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pacman-key --lsign-key '{{$.SignMail}}'</code></pre>
{{end -}}{{- if gt $GroupSize 1 -}}
# {{ctx.Locale.Tr "packages.arch.pacman.repo.multi.item" .}}
{{end -}}
[{{$.PackageDescriptor.Owner.LowerName}}.{{$.RegistryHost}}]
[{{$.PackageDescriptor.Owner.LowerName}}.{{$.PackageRegistryHost}}]
SigLevel = Required
Server = <origin-url data-url="{{AppSubUrl}}/api/packages/{{$.PackageDescriptor.Owner.Name}}/arch/{{.}}/$arch"></origin-url>
{{end -}}
Expand Down
4 changes: 2 additions & 2 deletions templates/package/content/container.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<div class="field">
<label>{{svg "octicon-terminal"}} {{ctx.Locale.Tr "packages.container.pull"}}</label>
{{if eq .PackageDescriptor.Metadata.Type "helm"}}
<div class="markup"><pre class="code-block"><code>helm pull oci://{{.RegistryHost}}/{{.PackageDescriptor.Owner.LowerName}}/{{.PackageDescriptor.Package.LowerName}} --version {{.PackageDescriptor.Version.LowerVersion}}</code></pre></div>
<div class="markup"><pre class="code-block"><code>helm pull oci://{{.PackageRegistryHost}}/{{.PackageDescriptor.Owner.LowerName}}/{{.PackageDescriptor.Package.LowerName}} --version {{.PackageDescriptor.Version.LowerVersion}}</code></pre></div>
{{else}}
{{$separator := ":"}}
{{if not .PackageDescriptor.Metadata.IsTagged}}
{{$separator = "@"}}
{{end}}
<div class="markup"><pre class="code-block"><code>docker pull {{.RegistryHost}}/{{.PackageDescriptor.Owner.LowerName}}/{{.PackageDescriptor.Package.LowerName}}{{$separator}}{{.PackageDescriptor.Version.LowerVersion}}</code></pre></div>
<div class="markup"><pre class="code-block"><code>docker pull {{.PackageRegistryHost}}/{{.PackageDescriptor.Owner.LowerName}}/{{.PackageDescriptor.Package.LowerName}}{{$separator}}{{.PackageDescriptor.Version.LowerVersion}}</code></pre></div>
{{end}}
</div>
<div class="field">
Expand Down

0 comments on commit 0d9547d

Please sign in to comment.