Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ This will make it possible for the organizations to establish MTLS communication
| Type | Description | Additional properties
|-----------------|------------------------------------------------------------|-----------------------
|blob-received | Emitted to the recipient when a blob has been transferred | sender, path, hash
|blob-delivered | Emitted to the sender when a blob has been delivered | recipient, path, requestID (optional)
|blob-failed | Emitted to the sender when a blob could not be delivered | recipient, path, requestID (optional)
|blob-delivered | Emitted to the sender when a blob has been delivered | recipient, path, requestId (optional)
|blob-failed | Emitted to the sender when a blob could not be delivered | recipient, path, requestId (optional)
|message-received | Emitted to the recipient when a message has been sent | sender, message
|message-delivered| Emitted to the sender when a message has been delivered | recipient, message, requestID (optional)
|message-failed | Emitted to the sender when a message could not be delivered| recipient, message, requestID (optional)
|message-delivered| Emitted to the sender when a message has been delivered | recipient, message, requestId (optional)
|message-failed | Emitted to the sender when a message could not be delivered| recipient, message, requestId (optional)

- After receiving a websocket message, a commit must be sent in order to receive the next one:
```
Expand Down
12 changes: 6 additions & 6 deletions src/handlers/blobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,20 @@ export const storeBlob = async (file: IFile, filePath: string) => {
return await upsertMetadata(filePath, blobHash, blobSize);
};

export const sendBlob = async (blobPath: string, recipient: string, recipientURL: string, requestID: string | undefined) => {
export const sendBlob = async (blobPath: string, recipient: string, recipientURL: string, requestId: string | undefined) => {
if (sending) {
blobQueue.push({ blobPath, recipient, recipientURL, requestID });
blobQueue.push({ blobPath, recipient, recipientURL, requestId });
} else {
sending = true;
blobQueue.push({ blobPath, recipient, recipientURL, requestID });
blobQueue.push({ blobPath, recipient, recipientURL, requestId });
while (blobQueue.length > 0) {
await deliverBlob(blobQueue.shift()!);
}
sending = false;
}
};

export const deliverBlob = async ({ blobPath, recipient, recipientURL, requestID }: BlobTask) => {
export const deliverBlob = async ({ blobPath, recipient, recipientURL, requestId }: BlobTask) => {
const resolvedFilePath = path.join(utils.constants.DATA_DIRECTORY, utils.constants.BLOBS_SUBDIRECTORY, blobPath);
if (!(await utils.fileExists(resolvedFilePath))) {
throw new RequestError('Blob not found', 404);
Expand All @@ -105,7 +105,7 @@ export const deliverBlob = async ({ blobPath, recipient, recipientURL, requestID
type: 'blob-delivered',
path: blobPath,
recipient,
requestID
requestId
} as IBlobDeliveredEvent);
log.trace(`Blob delivered`);
} catch (err: any) {
Expand All @@ -114,7 +114,7 @@ export const deliverBlob = async ({ blobPath, recipient, recipientURL, requestID
type: 'blob-failed',
path: blobPath,
recipient,
requestID,
requestId,
error: err.message,
} as IBlobFailedEvent);
log.error(`Failed to deliver blob ${err}`);
Expand Down
12 changes: 6 additions & 6 deletions src/handlers/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ let messageQueue: MessageTask[] = [];
let sending = false;
export const eventEmitter = new EventEmitter();

export const sendMessage = async (message: string, recipient: string, recipientURL: string, requestID: string | undefined) => {
export const sendMessage = async (message: string, recipient: string, recipientURL: string, requestId: string | undefined) => {
if (sending) {
messageQueue.push({ message, recipient, recipientURL, requestID });
messageQueue.push({ message, recipient, recipientURL, requestId });
} else {
sending = true;
messageQueue.push({ message, recipient, recipientURL, requestID });
messageQueue.push({ message, recipient, recipientURL, requestId });
while (messageQueue.length > 0) {
await deliverMessage(messageQueue.shift()!);
}
sending = false;
}
};

export const deliverMessage = async ({ message, recipient, recipientURL, requestID }: MessageTask) => {
export const deliverMessage = async ({ message, recipient, recipientURL, requestId }: MessageTask) => {
const httpsAgent = new https.Agent({ cert, key, ca });
const formData = new FormData();
formData.append('message', message);
Expand All @@ -60,7 +60,7 @@ export const deliverMessage = async ({ message, recipient, recipientURL, request
type: 'message-delivered',
message,
recipient,
requestID
requestId
} as IMessageDeliveredEvent);
log.trace(`Message delivered`);
} catch(err: any) {
Expand All @@ -69,7 +69,7 @@ export const deliverMessage = async ({ message, recipient, recipientURL, request
type: 'message-failed',
message,
recipient,
requestID,
requestId,
error: err.message,
} as IMessageFailedEvent);
log.error(`Failed to deliver message ${err}`);
Expand Down
6 changes: 3 additions & 3 deletions src/lib/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export interface IMessageFailedEvent {
type: 'message-failed'
recipient: string
message: string
requestID?: string
requestId?: string
}

export interface IBlobReceivedEvent {
Expand Down Expand Up @@ -106,14 +106,14 @@ export interface ICommitEvent {
}

export type MessageTask = {
requestID?: string
requestId?: string
message: string
recipient: string
recipientURL: string
}

export type BlobTask = {
requestID?: string
requestId?: string
blobPath: string
recipient: string
recipientURL: string
Expand Down
20 changes: 10 additions & 10 deletions src/routers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ router.post('/messages', async (req, res, next) => {
if (recipientURL === undefined) {
throw new RequestError(`Unknown recipient`, 400);
}
let requestID = uuidV4();
if(typeof req.body.requestID === 'string') {
requestID = req.body.requestID;
let requestId = uuidV4();
if(typeof req.body.requestId === 'string') {
requestId = req.body.requestId;
}
messagesHandler.sendMessage(req.body.message, req.body.recipient, recipientURL, requestID);
res.send({ requestID });
messagesHandler.sendMessage(req.body.message, req.body.recipient, recipientURL, requestId);
res.send({ requestId });
} catch (err) {
next(err);
}
Expand Down Expand Up @@ -211,12 +211,12 @@ router.post('/transfers', async (req, res, next) => {
if (recipientURL === undefined) {
throw new RequestError(`Unknown recipient`, 400);
}
let requestID = uuidV4();
if(typeof req.body.requestID === 'string') {
requestID = req.body.requestID;
let requestId = uuidV4();
if(typeof req.body.requestId === 'string') {
requestId = req.body.requestId;
}
blobsHandler.sendBlob(req.body.path, req.body.recipient, recipientURL, requestID);
res.send({ requestID });
blobsHandler.sendBlob(req.body.path, req.body.recipient, recipientURL, requestId);
res.send({ requestId });
} catch (err) {
next(err);
}
Expand Down
8 changes: 4 additions & 4 deletions src/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@
type: string
recipient:
type: string
requestID:
requestId:
type: string
BlobHash:
type: object
Expand All @@ -375,14 +375,14 @@
type: string
recipient:
type: string
requestID:
requestId:
type: string
Submitted:
type: object
required:
- requestID
- requestId
properties:
requestID:
requestId:
type: string
Error:
type: object
Expand Down