Skip to content

Commit

Permalink
feat(nuget/v3): Added support for new source query parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
lluiscab committed Dec 15, 2023
1 parent cee41f5 commit 1f6de9b
Showing 1 changed file with 36 additions and 12 deletions.
48 changes: 36 additions & 12 deletions services/nuget/nuget-v3-service-family.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Joi from 'joi'
import RouteBuilder from '../route-builder.js'
import { BaseJsonService, NotFound } from '../index.js'
import { optionalUrl } from '../validators.js'
import {
renderVersionBadge,
renderDownloadBadge,
Expand Down Expand Up @@ -89,6 +90,10 @@ async function fetch(
})
}

const queryParamSchema = Joi.object({
source: optionalUrl,
}).required()

/*
* Create a version and download service for a NuGet v2 API. Return an object
* containing both services.
Expand All @@ -113,13 +118,24 @@ function createServiceFamily({
apiBaseUrl,
withFeed = true,
}) {
/**
* Extract source parameters
*/

function unpackParams({ source = apiBaseUrl }) {
return { source: `${source}/v3` }
}

class NugetVersionService extends BaseJsonService {
static category = 'version'

static route = buildRoute({ serviceBaseUrl, withTenant, withFeed })
.push('(v|vpre)', 'which')
.push('(.+?)', 'packageName')
.toObject()
static route = {
...buildRoute({ serviceBaseUrl, withTenant, withFeed })
.push('(v|vpre)', 'which')
.push('(.+?)', 'packageName')
.toObject(),
queryParamSchema,
}

static examples = []

Expand All @@ -146,11 +162,14 @@ function createServiceFamily({
}
}

async handle({ tenant, feed, which, packageName }) {
async handle({ tenant, feed, which, packageName }, queryParams) {
const includePrereleases = which === 'vpre'

const { source } = unpackParams(queryParams)

const baseUrl = apiUrl({
withTenant,
apiBaseUrl,
apiBaseUrl: source,
apiDomain,
tenant,
withFeed,
Expand All @@ -165,10 +184,13 @@ function createServiceFamily({
class NugetDownloadService extends BaseJsonService {
static category = 'downloads'

static route = buildRoute({ serviceBaseUrl, withTenant, withFeed })
.push('dt')
.push('(.+?)', 'packageName')
.toObject()
static route = {
...buildRoute({ serviceBaseUrl, withTenant, withFeed })
.push('dt')
.push('(.+?)', 'packageName')
.toObject(),
queryParamSchema,
}

static examples = []

Expand All @@ -190,10 +212,12 @@ function createServiceFamily({
}
}

async handle({ tenant, feed, which, packageName }) {
async handle({ tenant, feed, which, packageName }, queryParams) {
const { source } = unpackParams(queryParams)

const baseUrl = apiUrl({
withTenant,
apiBaseUrl,
apiBaseUrl: source,
apiDomain,
tenant,
withFeed,
Expand Down

0 comments on commit 1f6de9b

Please sign in to comment.