propro-utils 1.4.98 → 1.4.99

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 +29 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "propro-utils",
3
- "version": "1.4.98",
3
+ "version": "1.4.99",
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,29 @@ 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
+ res.status(response.status).json(response.data);
311
+ } catch (error) {
312
+ this.handleProxyError(error, res);
313
+ }
314
+ });
303
315
  };
304
316
 
305
317
  pathRequiresAccessToken = path => {
@@ -321,7 +333,10 @@ class AuthMiddleware {
321
333
 
322
334
  const formData = new FormData();
323
335
  if (req.file) {
324
- formData.append('file', req.file.buffer, file.originalname);
336
+ formData.append('file', req.file.buffer, {
337
+ filename: req.file.originalname,
338
+ contentType: req.file.mimetype,
339
+ });
325
340
  }
326
341
 
327
342
  let headers = {
@@ -340,17 +355,19 @@ class AuthMiddleware {
340
355
 
341
356
  console.log('formattedAuthUrl:', formattedAuthUrl);
342
357
  console.log('req.method:', req.method);
343
- console.log('file:', file);
358
+ console.log('file:', req.file);
344
359
  console.log('formData:', formData);
345
360
  console.log('headers:', headers);
346
361
 
347
- const data = file ? formData : req.body;
362
+ const data = req.file ? formData : req.body;
348
363
 
349
364
  return axios({
350
365
  method: req.method,
351
366
  url: `${formattedAuthUrl}${path}`,
352
367
  data: data,
353
368
  headers: headers,
369
+ maxContentLength: Infinity,
370
+ maxBodyLength: Infinity,
354
371
  });
355
372
  };
356
373