• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mozilla / blurts-server / #13258

pending completion
#13258

push

circleci

Vinnl
Update filter results when clearing search field

On the public breach list, the search input that filters the list
of breaches would respond to `keyup` events specifically, rather
than anything that might change the input. Thus, if (e.g. in Chrome
or Safari) a browser adds a "Clear input" icon to the field and the
user clicks that, the field gets emptied, but the list of breaches
are still narrowed down to the previous input.

282 of 1663 branches covered (16.96%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

959 of 4511 relevant lines covered (21.26%)

1.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/ip-location-service.js
1
'use strict'
2

3
const path = require('path')
×
4
const reader = require('@maxmind/geoip2-node').Reader
×
5
const AppConstants = require('./app-constants')
×
6

7
let locationDb, timestamp
8

9
async function openLocationDb () {
10
  if (locationDb && isFresh()) return console.warn('Location database already open.')
×
11

12
  try {
×
13
    const dbPath = path.join(AppConstants.GEOIP_GEOLITE2_PATH, AppConstants.GEOIP_GEOLITE2_CITY_FILENAME)
×
14
    locationDb = await reader.open(dbPath)
×
15
  } catch (e) {
16
    return console.warn('Could not open location database:', e.message)
×
17
  }
18

19
  timestamp = Date.now()
×
20
  return true
×
21
}
22

23
async function readLocationData (ip, locales) {
24
  let locationArr
25

26
  if (!isFresh()) await openLocationDb()
×
27

28
  try {
×
29
    const data = locationDb.city(ip)
×
30
    const countryName = data.country?.names[locales.find(locale => data.country?.names[locale])] // find valid locale key and return its value
×
31
    const cityName = data.city?.names[locales.find(locale => data.city?.names[locale])]
×
32
    const subdivisionName = data.subdivisions?.[0].isoCode
×
33
    const subdivisionFiltered = /[A-z]{2,}/.test(subdivisionName) ? subdivisionName : null // return strings that are 2 or more letters, or null (avoid unfamiliar subdivisions like `E` or `09`)
×
34

35
    locationArr = [cityName, subdivisionFiltered, countryName].filter(str => str) // [city name, state code, country code] with non-null items.
×
36
  } catch (e) {
37
    return console.warn('Could not read location from database:', e.message)
×
38
  }
39

40
  return {
×
41
    shortLocation: locationArr.slice(0, 2).join(', '), // shows the first two location values from the ones available
42
    fullLocation: locationArr.join(', ') // shows up to three location values from the ones available
43
  }
44
}
45

46
function isFresh () {
47
  if (Date.now() - timestamp < 259200000) return true // 1000ms * 60s * 60m * 24h * 3 elapsed time is less than 24hrs
×
48
  return false
×
49
}
50

51
module.exports = {
×
52
  openLocationDb,
53
  readLocationData
54
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc