Use same URL parsing function for log processing

This commit is contained in:
MICHAEL JACKSON 2017-08-04 21:59:59 -07:00
parent 6b3b279ca3
commit 5c4da640c8
1 changed files with 5 additions and 5 deletions

View File

@ -6,6 +6,9 @@ const ndjson = require('ndjson')
const redis = require('redis')
const startOfDay = require('date-fns/start_of_day')
const addDays = require('date-fns/add_days')
const {
parsePackageURL
} = require('./middleware/PackageUtils')
const {
createDayKey,
createHourKey
@ -71,12 +74,9 @@ const toSeconds = (millis) =>
const stringifySeconds = (seconds) =>
new Date(seconds * 1000).toISOString()
// TODO: Copied from express-unpkg, use the same function
const URLFormat = /^\/((?:@[^\/@]+\/)?[^\/@]+)(?:@([^\/]+))?(\/.*)?$/
const getPackageName = (pathname) => {
const match = URLFormat.exec(pathname)
return match && match[1]
const parsed = parsePackageURL(pathname)
return parsed && parsed.packageName
}
const oneSecond = 1000