Skip to content

Commit

Permalink
Add getPackages for generating sitemap (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpolidori authored Mar 9, 2023
1 parent 8bfc91a commit 6941bee
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions lib/dms.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ class DmsModel {
}

async getJsonResponse(params, action) {
let url

let query = querystring.stringify(params)
if (params !== {}) {

let query = querystring.stringify(params)

url = new URL(resolve(this.api, action + '?' + query))
} else {
url = new URL(resolve(this.api, action))
}

let url = new URL(resolve(this.api, action + '?' + query))
let response = await fetch(url, {
headers: { 'User-Agent': 'frontend-v2/latest (internal API call from frontend app)' }
})
Expand Down Expand Up @@ -50,6 +57,18 @@ class DmsModel {
return response.result
}

async getPackages(context, limit = 1000, offset = 0) {
const action = 'package_search'
const params = {
rows: limit,
start: offset
}

const response = await this.getJsonResponse(params, action)

return response.result.results
}

async getPackage(name, includeViewsAndSchema = true) {
const action = 'package_show'
const params = {
Expand Down

0 comments on commit 6941bee

Please sign in to comment.