move logic to provider utils

This commit is contained in:
Ben Irvin 2023-03-29 09:30:49 +02:00
parent 9bea9793ad
commit 84a8b1a419
3 changed files with 10 additions and 6 deletions

View File

@ -10,6 +10,7 @@ import type { client, server } from '../../../../types/remote/protocol';
import type { ILocalStrapiDestinationProviderOptions } from '../local-destination';
import { TRANSFER_PATH } from '../../remote/constants';
import { ProviderTransferError, ProviderValidationError } from '../../../errors/providers';
import { trimTrailingSlash } from '../../../utils/providers';
interface ITransferTokenAuth {
type: 'token';
@ -210,9 +211,8 @@ class RemoteStrapiDestinationProvider implements IDestinationProvider {
});
}
const wsProtocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
const wsUrl = `${wsProtocol}//${url.host}${url.pathname.replace(
/\/$/,
''
const wsUrl = `${wsProtocol}//${url.host}${trimTrailingSlash(
url.pathname
)}${TRANSFER_PATH}/push`;
// No auth defined, trying public access for transfer

View File

@ -16,6 +16,7 @@ import {
ProviderTransferError,
ProviderValidationError,
} from '../../../errors/providers';
import { trimTrailingSlash } from '../../../utils/providers';
import { TRANSFER_PATH } from '../../remote/constants';
import { ILocalStrapiSourceProviderOptions } from '../local-source';
import { createDispatcher } from '../utils';
@ -227,9 +228,8 @@ class RemoteStrapiSourceProvider implements ISourceProvider {
let ws: WebSocket;
this.assertValidProtocol(url);
const wsProtocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
const wsUrl = `${wsProtocol}//${url.host}${url.pathname.replace(
/\/$/,
''
const wsUrl = `${wsProtocol}//${url.host}${trimTrailingSlash(
url.pathname
)}${TRANSFER_PATH}/pull`;
// No auth defined, trying public access for transfer

View File

@ -10,3 +10,7 @@ export const assertValidStrapi: ValidStrapiAssertion = (strapi?: unknown, msg =
throw new ProviderInitializationError(`${msg}. Strapi instance not found.`);
}
};
export const trimTrailingSlash = (input: string): string => {
return input.replace(/\/$/, '');
};