2023-03-09 17:36:19 +01:00

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');
};