From 5c4da640c8f4f6b7e3beb14c926b40f6063f7ca0 Mon Sep 17 00:00:00 2001 From: MICHAEL JACKSON Date: Fri, 4 Aug 2017 21:59:59 -0700 Subject: [PATCH] Use same URL parsing function for log processing --- server/IngestLogsWorker.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/server/IngestLogsWorker.js b/server/IngestLogsWorker.js index 8065f74..79ae4af 100644 --- a/server/IngestLogsWorker.js +++ b/server/IngestLogsWorker.js @@ -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