Skip to content

Commit

Permalink
fix bug where next param was missing when sortby was specified (#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Varner authored Jan 19, 2024
1 parent 2bb014a commit 6d41ad8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [3.5.0] - 2024-01-19

### Fixed

- When using sortby, next links were incorrect.

## [3.4.0] - 2023-12-15

### Changed
Expand Down Expand Up @@ -422,6 +428,7 @@ Initial release, forked from [sat-api](https://github.com/sat-utils/sat-api/tree
Compliant with STAC 0.9.0

<!-- [Unreleased]: https://github.com/stac-utils/stac-api/compare/v3.3.0...main -->
[3.5.0]: https://github.com/stac-utils/stac-api/compare/v3.4.0...v3.5.0
[3.4.0]: https://github.com/stac-utils/stac-api/compare/v3.3.0...v3.4.0
[3.3.0]: https://github.com/stac-utils/stac-api/compare/v3.2.0...v3.3.0
[3.2.0]: https://github.com/stac-utils/stac-api/compare/v3.1.0...v3.2.0
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"displayName": "stac-server",
"description": "A STAC API running on stac-server",
"version": "3.4.0",
"version": "3.5.0",
"repository": "https://github.com/stac-utils/stac-server",
"author": "Alireza Jazayeri, Matthew Hanson, Sean Harkins, Phil Varner",
"license": "MIT",
Expand Down
36 changes: 19 additions & 17 deletions src/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,27 +549,29 @@ const buildPaginationLinks = function (limit, parameters, bbox, intersects, endp

const lastItem = items[items.length - 1]

const nextKeys = sortby ? Object.keys(sortby) : ['properties.datetime', 'id', 'collection']
const nextKeys = sortby ? sortby.map((x) => x.field)
: ['properties.datetime', 'id', 'collection']

const next = nextKeys.map((k) => getNested(lastItem, k)).join(',')

const nextParams = pickBy(assign(parameters, { bbox, intersects, limit, next }))

const link = {
rel: 'next',
title: 'Next page of Items',
method: httpMethod,
type: 'application/geo+json'
}
if (httpMethod === 'GET') {
const nextQueryParameters = dictToURI(nextParams)
link.href = `${endpoint}?${nextQueryParameters}`
} else if (httpMethod === 'POST') {
link.href = endpoint
link.merge = false
link.body = nextParams
if (next) {
const link = {
rel: 'next',
title: 'Next page of Items',
method: httpMethod,
type: 'application/geo+json'
}
const nextParams = pickBy(assign(parameters, { bbox, intersects, limit, next }))
if (httpMethod === 'GET') {
const nextQueryParameters = dictToURI(nextParams)
link.href = `${endpoint}?${nextQueryParameters}`
} else if (httpMethod === 'POST') {
link.href = endpoint
link.merge = false
link.body = nextParams
}
return [link]
}
return [link]
}
return []
}
Expand Down

0 comments on commit 6d41ad8

Please sign in to comment.