@ryuu-reinzz/haruka-lib 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/main/socket.js +36 -36
  2. package/package.json +1 -1
package/main/socket.js CHANGED
@@ -187,7 +187,7 @@ export default function addProperty(socket, baileys) {
187
187
  bottom_sheet = false,
188
188
  bottom_name = ""
189
189
  } = content;
190
-
190
+
191
191
 
192
192
  if (!Array.isArray(buttons) || buttons.length === 0) {
193
193
  throw new Error("buttons must be a non-empty array");
@@ -281,47 +281,47 @@ export default function addProperty(socket, baileys) {
281
281
  videoMessage: preparedMedia.videoMessage,
282
282
  };
283
283
  } else if (document) {
284
- const mediaInput = {
285
- document: {}
286
- };
284
+ const mediaInput = {};
287
285
 
288
286
  if (Buffer.isBuffer(document)) {
289
- mediaInput.document = document;
290
- } else if (typeof document === "object" && document.url) {
291
287
  mediaInput.document = {
292
- url: document.url
288
+ buffer: document
293
289
  };
294
290
  } else if (typeof document === "string") {
291
+ if (/^https?:\/\//i.test(document)) {
292
+ mediaInput.document = {
293
+ url: document
294
+ };
295
+ } else {
296
+ mediaInput.document = {
297
+ buffer: fs.readFileSync(document)
298
+ };
299
+ }
300
+ } else if (typeof document === "object" && document.url) {
295
301
  mediaInput.document = {
296
- url: document
302
+ url: document.url
297
303
  };
304
+ } else {
305
+ throw new Error("Invalid document input");
298
306
  }
299
307
 
300
308
  if (fileName) {
301
- if (typeof mediaInput.document === "object") {
302
- mediaInput.document.fileName = fileName;
303
- }
309
+ mediaInput.document.fileName = fileName;
304
310
  }
305
311
 
306
312
  if (mimetype) {
307
- if (typeof mediaInput.document === "object") {
308
- mediaInput.document.mimetype = mimetype;
309
- }
313
+ mediaInput.document.mimetype = mimetype;
310
314
  }
311
315
 
312
316
  if (jpegThumbnail) {
313
- if (typeof mediaInput.document === "object") {
314
- if (Buffer.isBuffer(jpegThumbnail)) {
315
- mediaInput.document.jpegThumbnail = jpegThumbnail;
316
- } else if (typeof jpegThumbnail === "string") {
317
- try {
318
- const response = await fetch(jpegThumbnail);
319
- const arrayBuffer = await response.arrayBuffer();
320
- mediaInput.document.jpegThumbnail = Buffer.from(arrayBuffer);
321
- } catch {
322
- //
323
- }
324
- }
317
+ if (Buffer.isBuffer(jpegThumbnail)) {
318
+ mediaInput.document.jpegThumbnail = jpegThumbnail;
319
+ } else if (typeof jpegThumbnail === "string") {
320
+ try {
321
+ const response = await fetch(jpegThumbnail);
322
+ const arrayBuffer = await response.arrayBuffer();
323
+ mediaInput.document.jpegThumbnail = Buffer.from(arrayBuffer);
324
+ } catch {}
325
325
  }
326
326
  }
327
327
 
@@ -331,7 +331,7 @@ export default function addProperty(socket, baileys) {
331
331
 
332
332
  messageContent.header = {
333
333
  title: title || "",
334
- hasMediaAttachment: hasMediaAttachment || true,
334
+ hasMediaAttachment: true,
335
335
  documentMessage: preparedMedia.documentMessage,
336
336
  };
337
337
  } else if (location && typeof location === "object") {
@@ -413,17 +413,17 @@ export default function addProperty(socket, baileys) {
413
413
  messageContent.nativeFlowMessage = {
414
414
  buttons: processedButtons,
415
415
  };
416
-
416
+
417
417
  if (bottom_sheet) {
418
- messageContent.nativeFlowMessage.messageParamsJson = JSON.stringify({
419
- bottom_sheet: {
420
- in_thread_buttons_limit: 1,
421
- divider_indices: [1, 2],
422
- list_title: bottom_name,
423
- button_title: bottom_name
424
- }
418
+ messageContent.nativeFlowMessage.messageParamsJson = JSON.stringify({
419
+ bottom_sheet: {
420
+ in_thread_buttons_limit: 1,
421
+ divider_indices: [1, 2],
422
+ list_title: bottom_name,
423
+ button_title: bottom_name
424
+ }
425
425
  });
426
- }
426
+ }
427
427
 
428
428
  if (contextInfo.externalAdReply && typeof contextInfo.externalAdReply === "object") {
429
429
  messageContent.contextInfo = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ryuu-reinzz/haruka-lib",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Library extra for bot WhatsApp",
5
5
  "main": "main/index.js",
6
6
  "type": "module",