propro-utils 1.4.98 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +2 -1
  2. package/src/server/index.js +30 -17
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "propro-utils",
3
- "version": "1.4.98",
3
+ "version": "1.5.1",
4
4
  "description": "Auth middleware for propro-auth",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -45,6 +45,7 @@
45
45
  "jest": "^29.7.0",
46
46
  "jest-mock-axios": "^4.7.3",
47
47
  "jsonwebtoken": "^9.0.2",
48
+ "multer": "^1.4.5-lts.1",
48
49
  "nodemailer": "^6.9.7",
49
50
  "nodemailer-mailgun-transport": "^2.1.5",
50
51
  "querystring": "^0.2.1",
@@ -12,6 +12,8 @@ const authValidation = require('../../middlewares/access_token');
12
12
  const axios = require('axios');
13
13
  const { Router, query } = require('express');
14
14
  const FormData = require('form-data');
15
+ const multer = require('multer');
16
+ const upload = multer().single('file');
15
17
 
16
18
  /**
17
19
  * Middleware for handling authentication and authorization.
@@ -287,19 +289,31 @@ class AuthMiddleware {
287
289
  };
288
290
 
289
291
  handleAvatarUpdate = async (req, res) => {
290
- try {
292
+ upload(req, res, async err => {
293
+ if (err instanceof multer.MulterError) {
294
+ return res.status(400).json({ error: 'File upload error' });
295
+ } else if (err) {
296
+ return res
297
+ .status(500)
298
+ .json({ error: 'Server error during file upload' });
299
+ }
300
+
291
301
  if (!req.file) {
292
302
  return res.status(400).json({ error: 'No file uploaded' });
293
303
  }
294
304
 
295
- const response = await this.proxyToAuthServer(
296
- req,
297
- '/api/v1/accounts/avatar'
298
- );
299
- res.status(response.status).json(response.data);
300
- } catch (error) {
301
- this.handleProxyError(error, res);
302
- }
305
+ try {
306
+ const response = await this.proxyToAuthServer(
307
+ req,
308
+ '/api/v1/accounts/avatar'
309
+ );
310
+
311
+ res.cookie('account', response.data);
312
+ res.status(response.status).json(response.data);
313
+ } catch (error) {
314
+ this.handleProxyError(error, res);
315
+ }
316
+ });
303
317
  };
304
318
 
305
319
  pathRequiresAccessToken = path => {
@@ -321,7 +335,10 @@ class AuthMiddleware {
321
335
 
322
336
  const formData = new FormData();
323
337
  if (req.file) {
324
- formData.append('file', req.file.buffer, file.originalname);
338
+ formData.append('file', req.file.buffer, {
339
+ filename: req.file.originalname,
340
+ contentType: req.file.mimetype,
341
+ });
325
342
  }
326
343
 
327
344
  let headers = {
@@ -338,19 +355,15 @@ class AuthMiddleware {
338
355
  formattedAuthUrl = `${formattedAuthUrl}&clientId=${this.options.clientId}&redirectUri=${this.options.redirectUri}`;
339
356
  }
340
357
 
341
- console.log('formattedAuthUrl:', formattedAuthUrl);
342
- console.log('req.method:', req.method);
343
- console.log('file:', file);
344
- console.log('formData:', formData);
345
- console.log('headers:', headers);
346
-
347
- const data = file ? formData : req.body;
358
+ const data = req.file ? formData : req.body;
348
359
 
349
360
  return axios({
350
361
  method: req.method,
351
362
  url: `${formattedAuthUrl}${path}`,
352
363
  data: data,
353
364
  headers: headers,
365
+ maxContentLength: Infinity,
366
+ maxBodyLength: Infinity,
354
367
  });
355
368
  };
356
369