|
|
@ -5,15 +5,11 @@ |
|
|
|
package nuget |
|
|
|
package nuget |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"bytes" |
|
|
|
|
|
|
|
"fmt" |
|
|
|
|
|
|
|
"sort" |
|
|
|
"sort" |
|
|
|
"time" |
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
|
packages_model "code.gitea.io/gitea/models/packages" |
|
|
|
packages_model "code.gitea.io/gitea/models/packages" |
|
|
|
nuget_module "code.gitea.io/gitea/modules/packages/nuget" |
|
|
|
nuget_module "code.gitea.io/gitea/modules/packages/nuget" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/go-version" |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// ServiceIndexResponse https://docs.microsoft.com/en-us/nuget/api/service-index#resources
|
|
|
|
// ServiceIndexResponse https://docs.microsoft.com/en-us/nuget/api/service-index#resources
|
|
|
@ -113,8 +109,8 @@ func createRegistrationIndexResponse(l *linkBuilder, pds []*packages_model.Packa |
|
|
|
{ |
|
|
|
{ |
|
|
|
RegistrationPageURL: l.GetRegistrationIndexURL(pds[0].Package.Name), |
|
|
|
RegistrationPageURL: l.GetRegistrationIndexURL(pds[0].Package.Name), |
|
|
|
Count: len(pds), |
|
|
|
Count: len(pds), |
|
|
|
Lower: normalizeVersion(pds[0].SemVer), |
|
|
|
Lower: pds[0].Version.Version, |
|
|
|
Upper: normalizeVersion(pds[len(pds)-1].SemVer), |
|
|
|
Upper: pds[len(pds)-1].Version.Version, |
|
|
|
Items: items, |
|
|
|
Items: items, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
@ -191,7 +187,7 @@ type PackageVersionsResponse struct { |
|
|
|
func createPackageVersionsResponse(pds []*packages_model.PackageDescriptor) *PackageVersionsResponse { |
|
|
|
func createPackageVersionsResponse(pds []*packages_model.PackageDescriptor) *PackageVersionsResponse { |
|
|
|
versions := make([]string, 0, len(pds)) |
|
|
|
versions := make([]string, 0, len(pds)) |
|
|
|
for _, pd := range pds { |
|
|
|
for _, pd := range pds { |
|
|
|
versions = append(versions, normalizeVersion(pd.SemVer)) |
|
|
|
versions = append(versions, pd.Version.Version) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return &PackageVersionsResponse{ |
|
|
|
return &PackageVersionsResponse{ |
|
|
@ -266,15 +262,3 @@ func createSearchResult(l *linkBuilder, pds []*packages_model.PackageDescriptor) |
|
|
|
RegistrationIndexURL: l.GetRegistrationIndexURL(latest.Package.Name), |
|
|
|
RegistrationIndexURL: l.GetRegistrationIndexURL(latest.Package.Name), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// normalizeVersion removes the metadata
|
|
|
|
|
|
|
|
func normalizeVersion(v *version.Version) string { |
|
|
|
|
|
|
|
var buf bytes.Buffer |
|
|
|
|
|
|
|
segments := v.Segments64() |
|
|
|
|
|
|
|
fmt.Fprintf(&buf, "%d.%d.%d", segments[0], segments[1], segments[2]) |
|
|
|
|
|
|
|
pre := v.Prerelease() |
|
|
|
|
|
|
|
if pre != "" { |
|
|
|
|
|
|
|
fmt.Fprintf(&buf, "-%s", pre) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return buf.String() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|