mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 08:52:26 +00:00
Fix build
This commit is contained in:
parent
c4cd8b1e15
commit
5120ae454d
@ -7,6 +7,7 @@ import type { IHandlerOptions, TransferMethod } from './types';
|
|||||||
import { ProviderTransferError } from '../../../errors/providers';
|
import { ProviderTransferError } from '../../../errors/providers';
|
||||||
|
|
||||||
type WSCallback = (client: WebSocket, request: IncomingMessage) => void;
|
type WSCallback = (client: WebSocket, request: IncomingMessage) => void;
|
||||||
|
type BufferLike = Parameters<WebSocket['send']>[0];
|
||||||
|
|
||||||
const VALID_TRANSFER_COMMANDS = ['init', 'end', 'status'] as const;
|
const VALID_TRANSFER_COMMANDS = ['init', 'end', 'status'] as const;
|
||||||
|
|
||||||
@ -85,7 +86,7 @@ export interface Handler {
|
|||||||
/**
|
/**
|
||||||
* It sends a message to the client
|
* It sends a message to the client
|
||||||
*/
|
*/
|
||||||
send<T = unknown>(message: T, cb?: (err?: Error) => void): void;
|
send<T extends BufferLike>(message: T, cb?: (err?: Error) => void): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* It sends a message to the client and waits for a confirmation
|
* It sends a message to the client and waits for a confirmation
|
||||||
@ -185,7 +186,7 @@ export const handlerFactory =
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const payload = {
|
const payload = JSON.stringify({
|
||||||
uuid,
|
uuid,
|
||||||
data: data ?? null,
|
data: data ?? null,
|
||||||
error: e
|
error: e
|
||||||
@ -194,29 +195,21 @@ export const handlerFactory =
|
|||||||
message: e?.message,
|
message: e?.message,
|
||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
};
|
});
|
||||||
|
|
||||||
this.send(payload, (error) => (error ? reject(error) : resolve()));
|
this.send(payload, (error) => (error ? reject(error) : resolve()));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
send(message, cb) {
|
send(message, cb) {
|
||||||
let payload;
|
ws.send(message, cb);
|
||||||
|
|
||||||
try {
|
|
||||||
payload = JSON.stringify(message);
|
|
||||||
} catch {
|
|
||||||
payload = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
ws.send(payload, cb);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
confirm(message) {
|
confirm(message) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const uuid = randomUUID();
|
const uuid = randomUUID();
|
||||||
|
|
||||||
const payload = { uuid, data: message };
|
const payload = JSON.stringify({ uuid, data: message });
|
||||||
|
|
||||||
this.send(payload, (error) => {
|
this.send(payload, (error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user