Repo cleanup and updates
This commit is contained in:
parent
3a1063e40e
commit
99f8d7e2eb
72 changed files with 11857 additions and 16439 deletions
|
|
@ -1,4 +1,11 @@
|
|||
import { db, getWorkerUtils } from "@link-stack/bridge-common";
|
||||
import {
|
||||
db,
|
||||
getWorkerUtils,
|
||||
getMaxAttachmentSize,
|
||||
getMaxTotalAttachmentSize,
|
||||
MAX_ATTACHMENTS,
|
||||
buildSignalGroupName,
|
||||
} from "@link-stack/bridge-common";
|
||||
import { createLogger } from "@link-stack/logger";
|
||||
import * as signalApi from "@link-stack/signal-api";
|
||||
const { Configuration, MessagesApi, GroupsApi } = signalApi;
|
||||
|
|
@ -81,7 +88,7 @@ const sendSignalMessageTask = async ({
|
|||
// If sending to a phone number and auto-groups is enabled, create a group first
|
||||
if (enableAutoGroups && !isGroupId && to && conversationId) {
|
||||
try {
|
||||
const groupName = `DPN Support Request: ${conversationId}`;
|
||||
const groupName = buildSignalGroupName(conversationId);
|
||||
const createGroupResponse = await groupsClient.v1GroupsNumberPost({
|
||||
number: bot.phoneNumber,
|
||||
data: {
|
||||
|
|
@ -204,16 +211,54 @@ const sendSignalMessageTask = async ({
|
|||
);
|
||||
}
|
||||
|
||||
// Add attachments if provided
|
||||
// Add attachments if provided with size validation
|
||||
if (attachments && attachments.length > 0) {
|
||||
messageData.base64Attachments = attachments.map((att) => att.data);
|
||||
logger.debug(
|
||||
{
|
||||
attachmentCount: attachments.length,
|
||||
attachmentNames: attachments.map((att) => att.filename),
|
||||
},
|
||||
"Including attachments in message",
|
||||
);
|
||||
const MAX_ATTACHMENT_SIZE = getMaxAttachmentSize();
|
||||
const MAX_TOTAL_SIZE = getMaxTotalAttachmentSize();
|
||||
|
||||
if (attachments.length > MAX_ATTACHMENTS) {
|
||||
throw new Error(`Too many attachments: ${attachments.length} (max ${MAX_ATTACHMENTS})`);
|
||||
}
|
||||
|
||||
let totalSize = 0;
|
||||
const validatedAttachments = [];
|
||||
|
||||
for (const attachment of attachments) {
|
||||
// Calculate size from base64 string (rough estimate: length * 3/4)
|
||||
const estimatedSize = (attachment.data.length * 3) / 4;
|
||||
|
||||
if (estimatedSize > MAX_ATTACHMENT_SIZE) {
|
||||
logger.warn({
|
||||
filename: attachment.filename,
|
||||
size: estimatedSize,
|
||||
maxSize: MAX_ATTACHMENT_SIZE
|
||||
}, 'Attachment exceeds size limit, skipping');
|
||||
continue;
|
||||
}
|
||||
|
||||
totalSize += estimatedSize;
|
||||
if (totalSize > MAX_TOTAL_SIZE) {
|
||||
logger.warn({
|
||||
totalSize,
|
||||
maxTotalSize: MAX_TOTAL_SIZE
|
||||
}, 'Total attachment size exceeds limit, skipping remaining');
|
||||
break;
|
||||
}
|
||||
|
||||
validatedAttachments.push(attachment.data);
|
||||
}
|
||||
|
||||
if (validatedAttachments.length > 0) {
|
||||
messageData.base64Attachments = validatedAttachments;
|
||||
logger.debug(
|
||||
{
|
||||
attachmentCount: validatedAttachments.length,
|
||||
attachmentNames: attachments.slice(0, validatedAttachments.length).map((att) => att.filename),
|
||||
totalSizeBytes: totalSize
|
||||
},
|
||||
"Including attachments in message",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const response = await messagesClient.v2SendPost({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue