Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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
6 changes: 3 additions & 3 deletions 6 package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion 2 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"swagger-ui-express": "^4.1.6",
"ts-node": "^9.1.1",
"typescript": "^4.2.4",
"ws": "^7.4.5",
"ws": "^7.4.6",
"yamljs": "^0.3.0"
},
"devDependencies": {
Expand Down
14 changes: 8 additions & 6 deletions 14 src/handlers/blobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,20 @@ export const storeBlob = async (file: IFile, filePath: string) => {
});
};

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

export const deliverBlob = async ({ blobPath, recipient, recipientURL }: 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 @@ -96,14 +96,16 @@ export const deliverBlob = async ({ blobPath, recipient, recipientURL }: BlobTas
eventEmitter.emit('event', {
type: 'blob-delivered',
path: blobPath,
recipient
recipient,
requestID
} as IBlobDeliveredEvent);
log.trace(`Blob delivered`);
} catch (err) {
eventEmitter.emit('event', {
type: 'blob-failed',
path: blobPath,
recipient
recipient,
requestID
} as IBlobFailedEvent);
log.error(`Failed to deliver blob ${err}`);
}
Expand Down
14 changes: 8 additions & 6 deletions 14 src/handlers/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ let messageQueue: MessageTask[] = [];
let sending = false;
export const eventEmitter = new EventEmitter();

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

export const deliverMessage = async ({ message, recipient, recipientURL }: 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 @@ -57,14 +57,16 @@ export const deliverMessage = async ({ message, recipient, recipientURL }: Messa
eventEmitter.emit('event', {
type: 'message-delivered',
message,
recipient
recipient,
requestID
} as IMessageDeliveredEvent);
log.trace(`Message delivered`);
} catch(err) {
eventEmitter.emit('event', {
type: 'message-failed',
message,
recipient
recipient,
requestID
} as IMessageFailedEvent);
log.error(`Failed to deliver message ${err}`);
}
Expand Down
3 changes: 3 additions & 0 deletions 3 src/lib/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface IMessageFailedEvent {
type: 'message-failed'
recipient: string
message: string
requestID?: string
}

export interface IBlobReceivedEvent {
Expand Down Expand Up @@ -90,12 +91,14 @@ export interface ICommitEvent {
}

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

export type BlobTask = {
requestID?: string
blobPath: string
recipient: string
recipientURL: string
Expand Down
12 changes: 10 additions & 2 deletions 12 src/routers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ router.post('/messages', async (req, res, next) => {
if (recipientURL === undefined) {
throw new RequestError(`Unknown recipient`, 400);
}
messagesHandler.sendMessage(req.body.message, req.body.recipient, recipientURL);
let requestID: string | undefined = undefined;
if(typeof req.body.requestID === 'string') {
requestID = req.body.requestID;
}
messagesHandler.sendMessage(req.body.message, req.body.recipient, recipientURL, requestID);
res.send({ status: 'submitted' });
} catch (err) {
next(err);
Expand Down Expand Up @@ -169,7 +173,11 @@ router.post('/transfers', async (req, res, next) => {
if (recipientURL === undefined) {
throw new RequestError(`Unknown recipient`, 400);
}
blobsHandler.sendBlob(req.body.path, req.body.recipient, recipientURL);
let requestID: string | undefined = undefined;
if(typeof req.body.requestID === 'string') {
requestID = req.body.requestID;
}
blobsHandler.sendBlob(req.body.path, req.body.recipient, recipientURL, requestID);
res.send({ status: 'submitted' });
} catch (err) {
next(err);
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.