replaced fxa-geodb with load balancer header
Co-authored-by: timvisee <tim@visee.me>
This commit is contained in:
parent
4b1b7cb821
commit
b5ef1785ab
8 changed files with 84 additions and 141 deletions
|
@ -3,10 +3,6 @@ const fetch = require('node-fetch');
|
|||
const config = require('./config');
|
||||
const pkg = require('../package.json');
|
||||
|
||||
const geoip = config.ip_db
|
||||
? require('fxa-geodb')({ dbPath: config.ip_db })
|
||||
: () => ({});
|
||||
|
||||
const HOUR = 1000 * 60 * 60;
|
||||
|
||||
function truncateToHour(timestamp) {
|
||||
|
@ -24,20 +20,11 @@ function userId(fileId, ownerId) {
|
|||
return hash.digest('hex').substring(32);
|
||||
}
|
||||
|
||||
function location(ip) {
|
||||
try {
|
||||
return geoip(ip);
|
||||
} catch (e) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
function statUploadEvent(data) {
|
||||
const loc = location(data.ip);
|
||||
const event = {
|
||||
session_id: -1,
|
||||
country: loc.country,
|
||||
region: loc.state,
|
||||
country: data.country,
|
||||
region: data.state,
|
||||
user_id: userId(data.id, data.owner),
|
||||
app_version: pkg.version,
|
||||
time: truncateToHour(Date.now()),
|
||||
|
@ -57,11 +44,10 @@ function statUploadEvent(data) {
|
|||
}
|
||||
|
||||
function statDownloadEvent(data) {
|
||||
const loc = location(data.ip);
|
||||
const event = {
|
||||
session_id: -1,
|
||||
country: loc.country,
|
||||
region: loc.state,
|
||||
country: data.country,
|
||||
region: data.state,
|
||||
user_id: userId(data.id, data.owner),
|
||||
app_version: pkg.version,
|
||||
time: truncateToHour(Date.now()),
|
||||
|
@ -77,11 +63,10 @@ function statDownloadEvent(data) {
|
|||
}
|
||||
|
||||
function statDeleteEvent(data) {
|
||||
const loc = location(data.ip);
|
||||
const event = {
|
||||
session_id: -1,
|
||||
country: loc.country,
|
||||
region: loc.state,
|
||||
country: data.country,
|
||||
region: data.state,
|
||||
user_id: userId(data.id, data.owner),
|
||||
app_version: pkg.version,
|
||||
time: truncateToHour(Date.now()),
|
||||
|
@ -96,8 +81,16 @@ function statDeleteEvent(data) {
|
|||
return sendBatch([event]);
|
||||
}
|
||||
|
||||
function clientEvent(event, ua, language, session_id, deltaT, platform, ip) {
|
||||
const loc = location(ip);
|
||||
function clientEvent(
|
||||
event,
|
||||
ua,
|
||||
language,
|
||||
session_id,
|
||||
deltaT,
|
||||
platform,
|
||||
country,
|
||||
state
|
||||
) {
|
||||
const ep = event.event_properties || {};
|
||||
const up = event.user_properties || {};
|
||||
const event_properties = {
|
||||
|
@ -133,7 +126,7 @@ function clientEvent(event, ua, language, session_id, deltaT, platform, ip) {
|
|||
};
|
||||
return {
|
||||
app_version: pkg.version,
|
||||
country: loc.country,
|
||||
country: country,
|
||||
device_id: event.device_id,
|
||||
event_properties,
|
||||
event_type: event.event_type,
|
||||
|
@ -141,7 +134,7 @@ function clientEvent(event, ua, language, session_id, deltaT, platform, ip) {
|
|||
os_name: ua.os.name,
|
||||
os_version: ua.os.version,
|
||||
platform,
|
||||
region: loc.state,
|
||||
region: state,
|
||||
session_id,
|
||||
time: event.time + deltaT,
|
||||
user_id: event.user_id,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue