mirror of
				https://github.com/strapi/strapi.git
				synced 2025-11-04 03:43:34 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			30 lines
		
	
	
		
			770 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			30 lines
		
	
	
		
			770 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
'use strict';
 | 
						|
 | 
						|
const { getService } = require('../utils');
 | 
						|
 | 
						|
module.exports = () => async (ctx, next) => {
 | 
						|
  const transferUtils = getService('transfer').utils;
 | 
						|
 | 
						|
  const { hasValidTokenSalt, isDataTransferEnabled, isDisabledFromEnv } = transferUtils;
 | 
						|
 | 
						|
  if (isDataTransferEnabled()) {
 | 
						|
    return next();
 | 
						|
  }
 | 
						|
 | 
						|
  if (!hasValidTokenSalt()) {
 | 
						|
    return ctx.notImplemented(
 | 
						|
      'The server configuration for data transfer is invalid. Please contact your server administrator.',
 | 
						|
      {
 | 
						|
        code: 'INVALID_TOKEN_SALT',
 | 
						|
      }
 | 
						|
    );
 | 
						|
  }
 | 
						|
 | 
						|
  if (isDisabledFromEnv()) {
 | 
						|
    return ctx.notFound();
 | 
						|
  }
 | 
						|
 | 
						|
  // This should never happen as long as we're handling individual scenarios above
 | 
						|
  throw new Error('Unexpected error while trying to access a data transfer route');
 | 
						|
};
 |