Move device type detection to client side

We don't need the server to tell us our user agent--we can get it
ourselves through navigator.userAgent and parse it on the frontend.

I've replaced device-detector-js with Bowser because device-detector-js
is really slow, freezing for up to 500ms to parse a single user agent.
This commit is contained in:
valadaptive
2023-12-14 18:37:17 -05:00
parent 8cfc8ebe66
commit 66953ceba3
5 changed files with 25 additions and 48 deletions

View File

@@ -27,7 +27,6 @@ const responseTime = require('response-time');
// net related library imports
const net = require('net');
const dns = require('dns');
const DeviceDetector = require('device-detector-js');
const fetch = require('node-fetch').default;
const ipaddr = require('ipaddr.js');
const ipMatching = require('ip-matching');
@@ -293,12 +292,6 @@ app.use(multer({ dest: UPLOADS_PATH, limits: { fieldSize: 10 * 1024 * 1024 } }).
app.get('/', function (request, response) {
response.sendFile(process.cwd() + '/public/index.html');
});
app.get('/deviceinfo', function (request, response) {
const userAgent = request.header('user-agent');
const deviceDetector = new DeviceDetector();
const deviceInfo = deviceDetector.parse(userAgent || '');
return response.send(deviceInfo);
});
app.get('/version', async function (_, response) {
const data = await getVersion();
response.send(data);