<commit_before>import _ from 'lodash'
import url from 'url'

export default function(spec) {
  const {collection} = spec
  let {itemsPerPage} = spec

  itemsPerPage = itemsPerPage || 10

  async function links(req, res) {
    const cnt = await collection.count()
    const base = req.protocol + '://' + req.get('host')
    const self = url.parse(base + req.originalUrl, true)
    const page = req.query.page || 1

    self.search = undefined
    self.query.page = page
    const o = {self: url.format(self)}

    if (_.isArray(res.body)) {
      const next = url.parse(base + req.originalUrl, true)
      next.search = undefined
      next.query.page = page + 1

      const last = url.parse(base + req.originalUrl, true)
      last.search = undefined
      last.query.page = Math.max(1, Math.ceil(cnt / itemsPerPage))

      if (url.format(next) < url.format(last)) {
        o.next = url.format(next)
      }

      if (url.format(last) !== o.self) {
        o.last = url.format(last)
      }
    }

    return o
  }

  async function struct(req, res) {
    const o = {}
    const l = await links(req, res)
<commit_msg>fix: cast page query param to Number<commit_after>import _ from 'lodash'
import url from 'url'

export default function(spec) {
  const {collection} = spec
  let {itemsPerPage} = spec

  itemsPerPage = itemsPerPage || 10

  async function links(req, res) {
    const cnt = await collection.count()
    const base = req.protocol + '://' + req.get('host')
    const self = url.parse(base + req.originalUrl, true)
    const page = Number(req.query.page || 1)

    self.search = undefined
    self.query.page = page
    const o = {self: url.format(self)}

    if (_.isArray(res.body)) {
      const next = url.parse(base + req.originalUrl, true)
      next.search = undefined
      next.query.page = page + 1

      const last = url.parse(base + req.originalUrl, true)
      last.search = undefined
      last.query.page = Math.max(1, Math.ceil(cnt / itemsPerPage))

      if (url.format(next) < url.format(last)) {
        o.next = url.format(next)
      }

      if (url.format(last) !== o.self) {
        o.last = url.format(last)
      }
    }

    return o
  }

  async function struct(req, res) {
    const o = {}
    const l = await links(req, res)

{'fraction_non_alphanumeric': 0.13330400351957766, 'fraction_numerical': 0.004399472063352398, 'mean_word_length': 2.51468315301391, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '775101', 'n_tokens_mistral': 761, 'n_tokens_neox': 736, 'n_words': 194}