nishiki-bail 1.1.21 → 1.1.23
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.
package/lib/Defaults/index.js
CHANGED
|
@@ -93,6 +93,13 @@ export const MEDIA_PATH_MAP = {
|
|
|
93
93
|
'md-msg-hist': '/mms/md-app-state',
|
|
94
94
|
'biz-cover-photo': '/pps/biz-cover-photo'
|
|
95
95
|
};
|
|
96
|
+
export const NEWSLETTER_MEDIA_PATH_MAP = {
|
|
97
|
+
image: '/newsletter/newsletter-image',
|
|
98
|
+
video: '/newsletter/newsletter-video',
|
|
99
|
+
document: '/newsletter/newsletter-document',
|
|
100
|
+
audio: '/newsletter/newsletter-audio',
|
|
101
|
+
sticker: '/newsletter/newsletter-sticker'
|
|
102
|
+
};
|
|
96
103
|
export const MEDIA_HKDF_KEY_MAPPING = {
|
|
97
104
|
audio: 'Audio',
|
|
98
105
|
document: 'Document',
|
|
@@ -8,7 +8,7 @@ import { join } from 'path';
|
|
|
8
8
|
import { Readable, Transform } from 'stream';
|
|
9
9
|
import { URL } from 'url';
|
|
10
10
|
import { proto } from '../../WAProto/index.js';
|
|
11
|
-
import { DEFAULT_ORIGIN, MEDIA_HKDF_KEY_MAPPING, MEDIA_PATH_MAP } from '../Defaults/index.js';
|
|
11
|
+
import { DEFAULT_ORIGIN, MEDIA_HKDF_KEY_MAPPING, MEDIA_PATH_MAP, NEWSLETTER_MEDIA_PATH_MAP } from '../Defaults/index.js';
|
|
12
12
|
import { getBinaryNodeChild, getBinaryNodeChildBuffer, jidNormalizedUser } from '../WABinary/index.js';
|
|
13
13
|
import { aesDecryptGCM, aesEncryptGCM, hkdf } from './crypto.js';
|
|
14
14
|
import { generateMessageIDV2 } from './generics.js';
|
|
@@ -641,7 +641,7 @@ const uploadMedia = async (params, logger) => {
|
|
|
641
641
|
}
|
|
642
642
|
};
|
|
643
643
|
export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options }, refreshMediaConn) => {
|
|
644
|
-
return async (filePath, { mediaType, fileEncSha256B64, timeoutMs }) => {
|
|
644
|
+
return async (filePath, { mediaType, fileEncSha256B64, timeoutMs, newsletter }) => {
|
|
645
645
|
// send a query JSON to obtain the url & auth token to upload our media
|
|
646
646
|
let uploadInfo = await refreshMediaConn(false);
|
|
647
647
|
let urls;
|
|
@@ -662,7 +662,9 @@ export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, opt
|
|
|
662
662
|
for (const { hostname } of hosts) {
|
|
663
663
|
logger.debug(`uploading to "${hostname}"`);
|
|
664
664
|
const auth = encodeURIComponent(uploadInfo.auth);
|
|
665
|
-
const
|
|
665
|
+
const mediaPath = (newsletter && NEWSLETTER_MEDIA_PATH_MAP[mediaType]) || MEDIA_PATH_MAP[mediaType];
|
|
666
|
+
const serverThumbnail = newsletter ? '&server_thumb_gen=1' : '';
|
|
667
|
+
const url = `https://${hostname}${mediaPath}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}${serverThumbnail}`;
|
|
666
668
|
let result;
|
|
667
669
|
try {
|
|
668
670
|
result = await uploadMedia({
|
|
@@ -674,11 +676,13 @@ export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, opt
|
|
|
674
676
|
}, logger);
|
|
675
677
|
if (result?.url || result?.direct_path) {
|
|
676
678
|
urls = {
|
|
677
|
-
mediaUrl: result.url,
|
|
679
|
+
mediaUrl: result.url || result.direct_path,
|
|
678
680
|
directPath: result.direct_path,
|
|
679
681
|
meta_hmac: result.meta_hmac,
|
|
680
682
|
fbid: result.fbid,
|
|
681
|
-
ts: result.ts
|
|
683
|
+
ts: result.ts,
|
|
684
|
+
thumbnailDirectPath: result.thumbnail_info?.thumbnail_direct_path,
|
|
685
|
+
thumbnailSha256: result.thumbnail_info?.thumbnail_sha256
|
|
682
686
|
};
|
|
683
687
|
break;
|
|
684
688
|
}
|
package/lib/Utils/messages.js
CHANGED
|
@@ -101,19 +101,22 @@ export const prepareWAMessageMedia = async (message, options) => {
|
|
|
101
101
|
logger?.info({ key: cacheableKey }, 'Preparing raw media for newsletter');
|
|
102
102
|
const { filePath, fileSha256, fileLength } = await getRawMediaUploadData(uploadData.media, options.mediaTypeOverride || mediaType, logger);
|
|
103
103
|
const fileSha256B64 = fileSha256.toString('base64');
|
|
104
|
-
const { mediaUrl, directPath } = await options.upload(filePath, {
|
|
104
|
+
const { mediaUrl, directPath, thumbnailDirectPath, thumbnailSha256 } = await options.upload(filePath, {
|
|
105
105
|
fileEncSha256B64: fileSha256B64,
|
|
106
106
|
mediaType: mediaType,
|
|
107
|
-
timeoutMs: options.mediaUploadTimeoutMs
|
|
107
|
+
timeoutMs: options.mediaUploadTimeoutMs,
|
|
108
|
+
newsletter: isNewsletter
|
|
108
109
|
});
|
|
109
110
|
await fs.unlink(filePath);
|
|
110
111
|
const obj = WAProto.Message.fromObject({
|
|
111
112
|
// todo: add more support here
|
|
112
113
|
[`${mediaType}Message`]: MessageTypeProto[mediaType].fromObject({
|
|
113
|
-
url: mediaUrl,
|
|
114
|
+
url: mediaUrl || directPath,
|
|
114
115
|
directPath,
|
|
115
116
|
fileSha256,
|
|
116
117
|
fileLength,
|
|
118
|
+
thumbnailDirectPath,
|
|
119
|
+
thumbnailSha256,
|
|
117
120
|
...uploadData,
|
|
118
121
|
media: undefined
|
|
119
122
|
})
|