2021-07-08 11:20:13 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								'use strict' ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-09-27 10:01:46 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  _  =  require ( 'lodash' ) ;  
						 
					
						
							
								
									
										
										
										
											2021-07-08 11:20:13 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-09-28 16:54:07 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								module . exports  =  async  ( {  strapi  } )  =>  {  
						 
					
						
							
								
									
										
										
										
											2021-08-19 16:49:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  // set plugin store
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-13 12:03:12 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  const  configurator  =  strapi . store ( {  type :  'plugin' ,  name :  'upload' ,  key :  'settings'  } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-19 16:49:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-19 22:27:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  strapi . plugin ( 'upload' ) . provider  =  createProvider ( strapi . config . get ( 'plugin.upload' ,  { } ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-19 16:49:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  // if provider config does not exist set one by default
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const  config  =  await  configurator . get ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  if  ( ! config )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    await  configurator . set ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      value :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        sizeOptimization :  true , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        responsiveDimensions :  true , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        autoOrientation :  false , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  await  registerPermissionActions ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-09-27 10:01:46 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  createProvider  =  config  =>  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const  {  providerOptions ,  actionOptions  =  { }  }  =  config ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const  providerName  =  _ . toLower ( config . provider ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  let  provider ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  let  modulePath ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-19 16:49:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  try  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-27 10:01:46 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    modulePath  =  require . resolve ( ` @strapi/provider-upload- ${ providerName } ` ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }  catch  ( error )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( error . code  ===  'MODULE_NOT_FOUND' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      modulePath  =  providerName ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-27 10:36:21 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      throw  error ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-27 10:01:46 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-19 16:49:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-09-27 10:01:46 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  try  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    provider  =  require ( modulePath ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-19 16:49:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  }  catch  ( err )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-08 18:41:59 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    throw  new  Error ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      ` Could not load upload provider " ${ providerName } ". \n ${ err . message } \n ${ err . stack } ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-19 16:49:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-27 10:01:46 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const  providerInstance  =  provider . init ( providerOptions ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-15 18:51:52 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  if  ( ! providerInstance . delete )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-25 16:18:57 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    throw  new  Error ( ` The upload provider " ${ providerName } " doesn't implement the delete method. ` ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-15 18:51:52 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  if  ( ! providerInstance . upload  &&  ! providerInstance . uploadStream )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    throw  new  Error ( 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-25 16:18:57 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      ` The upload provider " ${ providerName } " doesn't implement the uploadStream nor the upload method. ` 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-15 18:51:52 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  if  ( ! providerInstance . uploadStream )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    process . emitWarning ( 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-25 16:18:57 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      ` The upload provider " ${ providerName } " doesn't implement the uploadStream function. Strapi will fallback on the upload method. Some performance issues may occur. ` 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-15 18:51:52 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const  wrappedProvider  =  _ . mapValues ( providerInstance ,  ( method ,  methodName )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  async  function ( file ,  options  =  actionOptions [ methodName ] )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      return  providerInstance [ methodName ] ( file ,  options ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-27 10:01:46 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-15 18:51:52 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  return  Object . assign ( Object . create ( baseProvider ) ,  wrappedProvider ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-19 16:49:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const  baseProvider  =  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  extend ( obj )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Object . assign ( this ,  obj ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const  registerPermissionActions  =  async  ( )  =>  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const  actions  =  [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      section :  'plugins' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      displayName :  'Access the Media Library' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      uid :  'read' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      pluginName :  'upload' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      section :  'plugins' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      displayName :  'Create (upload)' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      uid :  'assets.create' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      subCategory :  'assets' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      pluginName :  'upload' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      section :  'plugins' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      displayName :  'Update (crop, details, replace) + delete' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      uid :  'assets.update' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      subCategory :  'assets' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      pluginName :  'upload' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      section :  'plugins' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      displayName :  'Download' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      uid :  'assets.download' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      subCategory :  'assets' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      pluginName :  'upload' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      section :  'plugins' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      displayName :  'Copy link' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      uid :  'assets.copy-link' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      subCategory :  'assets' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      pluginName :  'upload' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      section :  'settings' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      displayName :  'Access the Media Library settings page' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      uid :  'settings.read' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      category :  'media library' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      pluginName :  'upload' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  await  strapi . admin . services . permission . actionProvider . registerMany ( actions ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;