44// - Log telemetry
55module . exports = { serve }
66
7- const bodyParser = require ( 'body-parser' )
7+ // const bodyParser = require('body-parser')
88const cp = require ( 'child_process' )
99const express = require ( 'express' )
10- const expressRateLimit = require ( 'express-rate-limit' )
10+ // const expressRateLimit = require('express-rate-limit')
1111const fs = require ( 'fs' )
12- const multer = require ( 'multer' )
12+ // const multer = require('multer')
1313const path = require ( 'path' )
1414const semver = require ( 'semver' )
1515const URL = require ( 'url' ) . URL
@@ -27,8 +27,8 @@ const CRASH_REPORTS_PATH = path.join(config.logPath, 'crash-reports')
2727const SUMMARIZE_PATH = path . join ( __dirname , '..' , 'bin' , 'summarize-telemetry.js' )
2828
2929// Queue telemetry messages, log them to a file in order
30- let telemetryLines = [ ]
31- let isWritingTelemetry = false
30+ // const telemetryLines = []
31+ // const isWritingTelemetry = false
3232
3333// Attempt to create the needed log folders
3434try { fs . mkdirSync ( TELEMETRY_PATH , { recursive : true } ) } catch ( err ) { }
@@ -66,14 +66,14 @@ function serve (app) {
6666
6767// Log telemetry JSON summaries to a file, one per line
6868function serveTelemetryAPI ( app ) {
69- app . post ( '/desktop/telemetry' , bodyParser . json ( ) , function ( req , res ) {
70- const summary = req . body
71- summary . ip = req . ip
72- const summaryJSON = JSON . stringify ( summary )
73- telemetryLines . push ( summaryJSON )
74- writeTelemetryLines ( )
75- res . end ( )
76- } )
69+ // app.post('/desktop/telemetry', bodyParser.json(), function (req, res) {
70+ // const summary = req.body
71+ // summary.ip = req.ip
72+ // const summaryJSON = JSON.stringify(summary)
73+ // telemetryLines.push(summaryJSON)
74+ // writeTelemetryLines()
75+ // res.end()
76+ // })
7777
7878 app . use ( '/desktop/telemetry/' , [
7979 auth ( secret . credentials ) ,
@@ -82,21 +82,21 @@ function serveTelemetryAPI (app) {
8282 ] )
8383}
8484
85- function writeTelemetryLines ( ) {
86- if ( isWritingTelemetry ) return // Don't interleave writes
87- if ( telemetryLines . length === 0 ) return // Nothing to do
88-
89- const today = new Date ( ) . toISOString ( ) . substring ( 0 , 10 ) // YYYY-MM-DD
90- const telemetryPath = path . join ( TELEMETRY_PATH , today + '.log' )
91- const lines = telemetryLines . join ( '\n' ) + '\n'
92- telemetryLines = [ ]
93- isWritingTelemetry = true
94- fs . appendFile ( telemetryPath , lines , function ( err ) {
95- isWritingTelemetry = false
96- if ( err ) console . error ( 'Error saving telemetry: ' + err . message )
97- writeTelemetryLines ( )
98- } )
99- }
85+ // function writeTelemetryLines () {
86+ // if (isWritingTelemetry) return // Don't interleave writes
87+ // if (telemetryLines.length === 0) return // Nothing to do
88+
89+ // const today = new Date().toISOString().substring(0, 10) // YYYY-MM-DD
90+ // const telemetryPath = path.join(TELEMETRY_PATH, today + '.log')
91+ // const lines = telemetryLines.join('\n') + '\n'
92+ // telemetryLines = []
93+ // isWritingTelemetry = true
94+ // fs.appendFile(telemetryPath, lines, function (err) {
95+ // isWritingTelemetry = false
96+ // if (err) console.error('Error saving telemetry: ' + err.message)
97+ // writeTelemetryLines()
98+ // })
99+ // }
100100
101101// Summarize telemetry information: active users, monthly growth, most common errors, etc
102102function serveTelemetryDashboard ( req , res , next ) {
@@ -173,27 +173,27 @@ function serveTelemetryDashboard (req, res, next) {
173173
174174// Save electron process crash reports (from Crashpad), each in its own file
175175function serveCrashReportsAPI ( app ) {
176- const upload = multer ( { dest : CRASH_REPORTS_PATH } ) . single ( 'upload_file_minidump' )
177-
178- const apiLimiter = expressRateLimit ( {
179- windowMs : 24 * 60 * 60 * 1000 , // 1 day
180- max : 5
181- } )
182-
183- app . post ( '/desktop/crash-report' , apiLimiter , upload , function ( req , res ) {
184- if ( ! req . file ) return res . status ( 500 ) . end ( )
185-
186- req . body . filename = req . file . filename
187- const crashLog = JSON . stringify ( req . body , undefined , 2 )
188-
189- fs . writeFile ( req . file . path + '.json' , crashLog , function ( err ) {
190- if ( err ) {
191- console . error ( 'Error saving crash report: ' + err . message )
192- res . status ( 500 )
193- }
194- res . end ( )
195- } )
196- } )
176+ // const upload = multer({ dest: CRASH_REPORTS_PATH }).single('upload_file_minidump')
177+
178+ // const apiLimiter = expressRateLimit({
179+ // windowMs: 24 * 60 * 60 * 1000, // 1 day
180+ // max: 5
181+ // })
182+
183+ // app.post('/desktop/crash-report', apiLimiter, upload, function (req, res) {
184+ // if (!req.file) return res.status(500).end()
185+
186+ // req.body.filename = req.file.filename
187+ // const crashLog = JSON.stringify(req.body, undefined, 2)
188+
189+ // fs.writeFile(req.file.path + '.json', crashLog, function (err) {
190+ // if (err) {
191+ // console.error('Error saving crash report: ' + err.message)
192+ // res.status(500)
193+ // }
194+ // res.end()
195+ // })
196+ // })
197197}
198198
199199// This lets us send a message to all WebTorrent Desktop users
0 commit comments