mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 09:09:36 +02:00
Extract functions from AuthenticationController to SessionManager GitOrigin-RevId: 86870ce03a762e1a837dcf493759e8851e759883
39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
const metrics = require('@overleaf/metrics')
|
|
const AnalyticsManager = require('./AnalyticsManager')
|
|
const SessionManager = require('../Authentication/SessionManager')
|
|
const GeoIpLookup = require('../../infrastructure/GeoIpLookup')
|
|
const Features = require('../../infrastructure/Features')
|
|
|
|
module.exports = {
|
|
updateEditingSession(req, res, next) {
|
|
if (!Features.hasFeature('analytics')) {
|
|
return res.sendStatus(202)
|
|
}
|
|
const userId = SessionManager.getLoggedInUserId(req.session)
|
|
const { projectId } = req.params
|
|
let countryCode = null
|
|
|
|
if (userId) {
|
|
GeoIpLookup.getDetails(req.ip, function (err, geoDetails) {
|
|
if (err) {
|
|
metrics.inc('analytics_geo_ip_lookup_errors')
|
|
} else if (geoDetails && geoDetails.country_code) {
|
|
countryCode = geoDetails.country_code
|
|
}
|
|
AnalyticsManager.updateEditingSession(userId, projectId, countryCode)
|
|
})
|
|
}
|
|
res.sendStatus(202)
|
|
},
|
|
|
|
recordEvent(req, res, next) {
|
|
if (!Features.hasFeature('analytics')) {
|
|
return res.sendStatus(202)
|
|
}
|
|
const userId =
|
|
SessionManager.getLoggedInUserId(req.session) || req.sessionID
|
|
AnalyticsManager.recordEvent(userId, req.params.event, req.body)
|
|
res.sendStatus(202)
|
|
},
|
|
}
|