| 
									
										
										
										
											2022-01-04 19:21:05 +01:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const { isFunction } = require('lodash/fp'); | 
					
						
							| 
									
										
										
										
											2023-02-08 15:57:14 +01:00
										 |  |  | const { | 
					
						
							|  |  |  |   file: { streamToBuffer }, | 
					
						
							|  |  |  | } = require('@strapi/utils'); | 
					
						
							| 
									
										
										
										
											2022-01-04 19:21:05 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | module.exports = ({ strapi }) => ({ | 
					
						
							| 
									
										
										
										
											2022-09-20 15:23:45 +02:00
										 |  |  |   async checkFileSize(file) { | 
					
						
							| 
									
										
										
										
											2022-09-16 11:13:07 +02:00
										 |  |  |     const { sizeLimit } = strapi.config.get('plugin.upload', {}); | 
					
						
							|  |  |  |     await strapi.plugin('upload').provider.checkFileSize(file, { sizeLimit }); | 
					
						
							| 
									
										
										
										
											2022-09-20 15:23:45 +02:00
										 |  |  |   }, | 
					
						
							|  |  |  |   async upload(file) { | 
					
						
							| 
									
										
										
										
											2022-01-04 19:21:05 +01:00
										 |  |  |     if (isFunction(strapi.plugin('upload').provider.uploadStream)) { | 
					
						
							|  |  |  |       file.stream = file.getStream(); | 
					
						
							|  |  |  |       await strapi.plugin('upload').provider.uploadStream(file); | 
					
						
							|  |  |  |       delete file.stream; | 
					
						
							| 
									
										
										
										
											2024-04-17 16:27:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       if ('filepath' in file) { | 
					
						
							|  |  |  |         delete file.filepath; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2022-01-04 19:21:05 +01:00
										 |  |  |     } else { | 
					
						
							|  |  |  |       file.buffer = await streamToBuffer(file.getStream()); | 
					
						
							|  |  |  |       await strapi.plugin('upload').provider.upload(file); | 
					
						
							|  |  |  |       delete file.buffer; | 
					
						
							| 
									
										
										
										
											2024-04-17 16:27:48 +02:00
										 |  |  |       if ('filepath' in file) { | 
					
						
							|  |  |  |         delete file.filepath; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2022-01-04 19:21:05 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | }); |