yt-dlp support
This commit is contained in:
186
node_modules/whatsapp-web.js/src/util/Constants.js
generated
vendored
Normal file
186
node_modules/whatsapp-web.js/src/util/Constants.js
generated
vendored
Normal file
@@ -0,0 +1,186 @@
|
||||
'use strict';
|
||||
|
||||
exports.WhatsWebURL = 'https://web.whatsapp.com/';
|
||||
|
||||
exports.DefaultOptions = {
|
||||
puppeteer: {
|
||||
headless: true,
|
||||
defaultViewport: null
|
||||
},
|
||||
webVersion: '2.3000.1017054665',
|
||||
webVersionCache: {
|
||||
type: 'local',
|
||||
},
|
||||
authTimeoutMs: 0,
|
||||
qrMaxRetries: 0,
|
||||
takeoverOnConflict: false,
|
||||
takeoverTimeoutMs: 0,
|
||||
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36',
|
||||
ffmpegPath: 'ffmpeg',
|
||||
bypassCSP: false,
|
||||
proxyAuthentication: undefined,
|
||||
pairWithPhoneNumber: {
|
||||
phoneNumber: '',
|
||||
showNotification: true,
|
||||
intervalMs: 180000,
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Client status
|
||||
* @readonly
|
||||
* @enum {number}
|
||||
*/
|
||||
exports.Status = {
|
||||
INITIALIZING: 0,
|
||||
AUTHENTICATING: 1,
|
||||
READY: 3
|
||||
};
|
||||
|
||||
/**
|
||||
* Events that can be emitted by the client
|
||||
* @readonly
|
||||
* @enum {string}
|
||||
*/
|
||||
exports.Events = {
|
||||
AUTHENTICATED: 'authenticated',
|
||||
AUTHENTICATION_FAILURE: 'auth_failure',
|
||||
READY: 'ready',
|
||||
CHAT_REMOVED: 'chat_removed',
|
||||
CHAT_ARCHIVED: 'chat_archived',
|
||||
MESSAGE_RECEIVED: 'message',
|
||||
MESSAGE_CIPHERTEXT: 'message_ciphertext',
|
||||
MESSAGE_CREATE: 'message_create',
|
||||
MESSAGE_REVOKED_EVERYONE: 'message_revoke_everyone',
|
||||
MESSAGE_REVOKED_ME: 'message_revoke_me',
|
||||
MESSAGE_ACK: 'message_ack',
|
||||
MESSAGE_EDIT: 'message_edit',
|
||||
UNREAD_COUNT: 'unread_count',
|
||||
MESSAGE_REACTION: 'message_reaction',
|
||||
MEDIA_UPLOADED: 'media_uploaded',
|
||||
CONTACT_CHANGED: 'contact_changed',
|
||||
GROUP_JOIN: 'group_join',
|
||||
GROUP_LEAVE: 'group_leave',
|
||||
GROUP_ADMIN_CHANGED: 'group_admin_changed',
|
||||
GROUP_MEMBERSHIP_REQUEST: 'group_membership_request',
|
||||
GROUP_UPDATE: 'group_update',
|
||||
QR_RECEIVED: 'qr',
|
||||
CODE_RECEIVED: 'code',
|
||||
LOADING_SCREEN: 'loading_screen',
|
||||
DISCONNECTED: 'disconnected',
|
||||
STATE_CHANGED: 'change_state',
|
||||
BATTERY_CHANGED: 'change_battery',
|
||||
INCOMING_CALL: 'call',
|
||||
REMOTE_SESSION_SAVED: 'remote_session_saved',
|
||||
VOTE_UPDATE: 'vote_update'
|
||||
};
|
||||
|
||||
/**
|
||||
* Message types
|
||||
* @readonly
|
||||
* @enum {string}
|
||||
*/
|
||||
exports.MessageTypes = {
|
||||
TEXT: 'chat',
|
||||
AUDIO: 'audio',
|
||||
VOICE: 'ptt',
|
||||
IMAGE: 'image',
|
||||
ALBUM: 'album',
|
||||
VIDEO: 'video',
|
||||
DOCUMENT: 'document',
|
||||
STICKER: 'sticker',
|
||||
LOCATION: 'location',
|
||||
CONTACT_CARD: 'vcard',
|
||||
CONTACT_CARD_MULTI: 'multi_vcard',
|
||||
ORDER: 'order',
|
||||
REVOKED: 'revoked',
|
||||
PRODUCT: 'product',
|
||||
UNKNOWN: 'unknown',
|
||||
GROUP_INVITE: 'groups_v4_invite',
|
||||
LIST: 'list',
|
||||
LIST_RESPONSE: 'list_response',
|
||||
BUTTONS_RESPONSE: 'buttons_response',
|
||||
PAYMENT: 'payment',
|
||||
BROADCAST_NOTIFICATION: 'broadcast_notification',
|
||||
CALL_LOG: 'call_log',
|
||||
CIPHERTEXT: 'ciphertext',
|
||||
DEBUG: 'debug',
|
||||
E2E_NOTIFICATION: 'e2e_notification',
|
||||
GP2: 'gp2',
|
||||
GROUP_NOTIFICATION: 'group_notification',
|
||||
HSM: 'hsm',
|
||||
INTERACTIVE: 'interactive',
|
||||
NATIVE_FLOW: 'native_flow',
|
||||
NOTIFICATION: 'notification',
|
||||
NOTIFICATION_TEMPLATE: 'notification_template',
|
||||
OVERSIZED: 'oversized',
|
||||
PROTOCOL: 'protocol',
|
||||
REACTION: 'reaction',
|
||||
TEMPLATE_BUTTON_REPLY: 'template_button_reply',
|
||||
POLL_CREATION: 'poll_creation',
|
||||
SCHEDULED_EVENT_CREATION: 'scheduled_event_creation',
|
||||
};
|
||||
|
||||
/**
|
||||
* Group notification types
|
||||
* @readonly
|
||||
* @enum {string}
|
||||
*/
|
||||
exports.GroupNotificationTypes = {
|
||||
ADD: 'add',
|
||||
INVITE: 'invite',
|
||||
REMOVE: 'remove',
|
||||
LEAVE: 'leave',
|
||||
PROMOTE: 'promote',
|
||||
DEMOTE: 'demote',
|
||||
SUBJECT: 'subject',
|
||||
DESCRIPTION: 'description',
|
||||
PICTURE: 'picture',
|
||||
ANNOUNCE: 'announce',
|
||||
RESTRICT: 'restrict',
|
||||
};
|
||||
|
||||
/**
|
||||
* Chat types
|
||||
* @readonly
|
||||
* @enum {string}
|
||||
*/
|
||||
exports.ChatTypes = {
|
||||
SOLO: 'solo',
|
||||
GROUP: 'group',
|
||||
UNKNOWN: 'unknown'
|
||||
};
|
||||
|
||||
/**
|
||||
* WhatsApp state
|
||||
* @readonly
|
||||
* @enum {string}
|
||||
*/
|
||||
exports.WAState = {
|
||||
CONFLICT: 'CONFLICT',
|
||||
CONNECTED: 'CONNECTED',
|
||||
DEPRECATED_VERSION: 'DEPRECATED_VERSION',
|
||||
OPENING: 'OPENING',
|
||||
PAIRING: 'PAIRING',
|
||||
PROXYBLOCK: 'PROXYBLOCK',
|
||||
SMB_TOS_BLOCK: 'SMB_TOS_BLOCK',
|
||||
TIMEOUT: 'TIMEOUT',
|
||||
TOS_BLOCK: 'TOS_BLOCK',
|
||||
UNLAUNCHED: 'UNLAUNCHED',
|
||||
UNPAIRED: 'UNPAIRED',
|
||||
UNPAIRED_IDLE: 'UNPAIRED_IDLE'
|
||||
};
|
||||
|
||||
/**
|
||||
* Message ACK
|
||||
* @readonly
|
||||
* @enum {number}
|
||||
*/
|
||||
exports.MessageAck = {
|
||||
ACK_ERROR: -1,
|
||||
ACK_PENDING: 0,
|
||||
ACK_SERVER: 1,
|
||||
ACK_DEVICE: 2,
|
||||
ACK_READ: 3,
|
||||
ACK_PLAYED: 4,
|
||||
};
|
||||
17
node_modules/whatsapp-web.js/src/util/Injected/AuthStore/AuthStore.js
generated
vendored
Normal file
17
node_modules/whatsapp-web.js/src/util/Injected/AuthStore/AuthStore.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
exports.ExposeAuthStore = () => {
|
||||
window.AuthStore = {};
|
||||
window.AuthStore.AppState = window.require('WAWebSocketModel').Socket;
|
||||
window.AuthStore.Cmd = window.require('WAWebCmd').Cmd;
|
||||
window.AuthStore.Conn = window.require('WAWebConnModel').Conn;
|
||||
window.AuthStore.OfflineMessageHandler = window.require('WAWebOfflineHandler').OfflineMessageHandler;
|
||||
window.AuthStore.PairingCodeLinkUtils = window.require('WAWebAltDeviceLinkingApi');
|
||||
window.AuthStore.Base64Tools = window.require('WABase64');
|
||||
window.AuthStore.RegistrationUtils = {
|
||||
...window.require('WAWebCompanionRegClientUtils'),
|
||||
...window.require('WAWebAdvSignatureApi'),
|
||||
...window.require('WAWebUserPrefsInfoStore'),
|
||||
...window.require('WAWebSignalStoreApi'),
|
||||
};
|
||||
};
|
||||
22
node_modules/whatsapp-web.js/src/util/Injected/AuthStore/LegacyAuthStore.js
generated
vendored
Normal file
22
node_modules/whatsapp-web.js/src/util/Injected/AuthStore/LegacyAuthStore.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
//TODO: To be removed by version 2.3000.x hard release
|
||||
|
||||
exports.ExposeLegacyAuthStore = (moduleRaidStr) => {
|
||||
eval('var moduleRaid = ' + moduleRaidStr);
|
||||
// eslint-disable-next-line no-undef
|
||||
window.mR = moduleRaid();
|
||||
window.AuthStore = {};
|
||||
window.AuthStore.AppState = window.mR.findModule('Socket')[0].Socket;
|
||||
window.AuthStore.Cmd = window.mR.findModule('Cmd')[0].Cmd;
|
||||
window.AuthStore.Conn = window.mR.findModule('Conn')[0].Conn;
|
||||
window.AuthStore.OfflineMessageHandler = window.mR.findModule('OfflineMessageHandler')[0].OfflineMessageHandler;
|
||||
window.AuthStore.PairingCodeLinkUtils = window.mR.findModule('initializeAltDeviceLinking')[0];
|
||||
window.AuthStore.Base64Tools = window.mR.findModule('encodeB64')[0];
|
||||
window.AuthStore.RegistrationUtils = {
|
||||
...window.mR.findModule('getCompanionWebClientFromBrowser')[0],
|
||||
...window.mR.findModule('verifyKeyIndexListAccountSignature')[0],
|
||||
...window.mR.findModule('waNoiseInfo')[0],
|
||||
...window.mR.findModule('waSignalStore')[0],
|
||||
};
|
||||
};
|
||||
146
node_modules/whatsapp-web.js/src/util/Injected/LegacyStore.js
generated
vendored
Normal file
146
node_modules/whatsapp-web.js/src/util/Injected/LegacyStore.js
generated
vendored
Normal file
@@ -0,0 +1,146 @@
|
||||
'use strict';
|
||||
|
||||
//TODO: To be removed by version 2.3000.x hard release
|
||||
|
||||
// Exposes the internal Store to the WhatsApp Web client
|
||||
exports.ExposeLegacyStore = () => {
|
||||
window.Store = Object.assign({}, window.mR.findModule(m => m.default && m.default.Chat)[0].default);
|
||||
window.Store.AppState = window.mR.findModule('Socket')[0].Socket;
|
||||
window.Store.Conn = window.mR.findModule('Conn')[0].Conn;
|
||||
window.Store.BlockContact = window.mR.findModule('blockContact')[0];
|
||||
window.Store.Call = window.mR.findModule((module) => module.default && module.default.Call)[0].default.Call;
|
||||
window.Store.Cmd = window.mR.findModule('Cmd')[0].Cmd;
|
||||
window.Store.CryptoLib = window.mR.findModule('decryptE2EMedia')[0];
|
||||
window.Store.DownloadManager = window.mR.findModule('downloadManager')[0].downloadManager;
|
||||
window.Store.GroupMetadata = window.mR.findModule('GroupMetadata')[0].default.GroupMetadata;
|
||||
window.Store.GroupQueryAndUpdate = window.mR.findModule('queryAndUpdateGroupMetadataById')[0].queryAndUpdateGroupMetadataById;
|
||||
window.Store.Label = window.mR.findModule('LabelCollection')[0].LabelCollection;
|
||||
window.Store.MediaPrep = window.mR.findModule('prepRawMedia')[0];
|
||||
window.Store.MediaObject = window.mR.findModule('getOrCreateMediaObject')[0];
|
||||
window.Store.NumberInfo = window.mR.findModule('formattedPhoneNumber')[0];
|
||||
window.Store.MediaTypes = window.mR.findModule('msgToMediaType')[0];
|
||||
window.Store.MediaUpload = window.mR.findModule('uploadMedia')[0];
|
||||
window.Store.MsgKey = window.mR.findModule((module) => module.default && module.default.fromString)[0].default;
|
||||
window.Store.OpaqueData = window.mR.findModule(module => module.default && module.default.createFromData)[0].default;
|
||||
window.Store.QueryProduct = window.mR.findModule('queryProduct')[0];
|
||||
window.Store.QueryOrder = window.mR.findModule('queryOrder')[0];
|
||||
window.Store.SendClear = window.mR.findModule('sendClear')[0];
|
||||
window.Store.SendDelete = window.mR.findModule('sendDelete')[0];
|
||||
window.Store.SendMessage = window.mR.findModule('addAndSendMsgToChat')[0];
|
||||
window.Store.EditMessage = window.mR.findModule('addAndSendMessageEdit')[0];
|
||||
window.Store.SendSeen = window.mR.findModule('sendSeen')[0];
|
||||
window.Store.User = window.mR.findModule('getMaybeMeUser')[0];
|
||||
window.Store.ContactMethods = window.mR.findModule('getUserid')[0];
|
||||
window.Store.UploadUtils = window.mR.findModule((module) => (module.default && module.default.encryptAndUpload) ? module.default : null)[0].default;
|
||||
window.Store.UserConstructor = window.mR.findModule((module) => (module.default && module.default.prototype && module.default.prototype.isServer && module.default.prototype.isUser) ? module.default : null)[0].default;
|
||||
window.Store.Validators = window.mR.findModule('findLinks')[0];
|
||||
window.Store.VCard = window.mR.findModule('vcardFromContactModel')[0];
|
||||
window.Store.WidFactory = window.mR.findModule('createWid')[0];
|
||||
window.Store.ProfilePic = window.mR.findModule('profilePicResync')[0];
|
||||
window.Store.PresenceUtils = window.mR.findModule('sendPresenceAvailable')[0];
|
||||
window.Store.ChatState = window.mR.findModule('sendChatStateComposing')[0];
|
||||
window.Store.findCommonGroups = window.mR.findModule('findCommonGroups')[0].findCommonGroups;
|
||||
window.Store.StatusUtils = window.mR.findModule('setMyStatus')[0];
|
||||
window.Store.ConversationMsgs = window.mR.findModule('loadEarlierMsgs')[0];
|
||||
window.Store.sendReactionToMsg = window.mR.findModule('sendReactionToMsg')[0].sendReactionToMsg;
|
||||
window.Store.createOrUpdateReactionsModule = window.mR.findModule('createOrUpdateReactions')[0];
|
||||
window.Store.EphemeralFields = window.mR.findModule('getEphemeralFields')[0];
|
||||
window.Store.MsgActionChecks = window.mR.findModule('canSenderRevokeMsg')[0];
|
||||
window.Store.QuotedMsg = window.mR.findModule('getQuotedMsgObj')[0];
|
||||
window.Store.LinkPreview = window.mR.findModule('getLinkPreview')[0];
|
||||
window.Store.Socket = window.mR.findModule('deprecatedSendIq')[0];
|
||||
window.Store.SocketWap = window.mR.findModule('wap')[0];
|
||||
window.Store.SearchContext = window.mR.findModule('getSearchContext')[0].getSearchContext;
|
||||
window.Store.DrawerManager = window.mR.findModule('DrawerManager')[0].DrawerManager;
|
||||
window.Store.LidUtils = window.mR.findModule('getCurrentLid')[0];
|
||||
window.Store.WidToJid = window.mR.findModule('widToUserJid')[0];
|
||||
window.Store.JidToWid = window.mR.findModule('userJidToUserWid')[0];
|
||||
window.Store.getMsgInfo = (window.mR.findModule('sendQueryMsgInfo')[0] || {}).sendQueryMsgInfo || window.mR.findModule('queryMsgInfo')[0].queryMsgInfo;
|
||||
window.Store.pinUnpinMsg = window.mR.findModule('sendPinInChatMsg')[0].sendPinInChatMsg;
|
||||
|
||||
/* eslint-disable no-undef, no-cond-assign */
|
||||
window.Store.QueryExist = ((m = window.mR.findModule('queryExists')[0]) ? m.queryExists : window.mR.findModule('queryExist')[0].queryWidExists);
|
||||
window.Store.ReplyUtils = (m = window.mR.findModule('canReplyMsg')).length > 0 && m[0];
|
||||
/* eslint-enable no-undef, no-cond-assign */
|
||||
|
||||
window.Store.Settings = {
|
||||
...window.mR.findModule('ChatlistPanelState')[0],
|
||||
setPushname: window.mR.findModule((m) => m.setPushname && !m.ChatlistPanelState)[0].setPushname
|
||||
};
|
||||
window.Store.StickerTools = {
|
||||
...window.mR.findModule('toWebpSticker')[0],
|
||||
...window.mR.findModule('addWebpMetadata')[0]
|
||||
};
|
||||
window.Store.GroupUtils = {
|
||||
...window.mR.findModule('createGroup')[0],
|
||||
...window.mR.findModule('setGroupDescription')[0],
|
||||
...window.mR.findModule('sendExitGroup')[0],
|
||||
...window.mR.findModule('sendSetPicture')[0]
|
||||
};
|
||||
window.Store.GroupParticipants = {
|
||||
...window.mR.findModule('promoteParticipants')[0],
|
||||
...window.mR.findModule('sendAddParticipantsRPC')[0]
|
||||
};
|
||||
window.Store.GroupInvite = {
|
||||
...window.mR.findModule('resetGroupInviteCode')[0],
|
||||
...window.mR.findModule('queryGroupInvite')[0]
|
||||
};
|
||||
window.Store.GroupInviteV4 = {
|
||||
...window.mR.findModule('queryGroupInviteV4')[0],
|
||||
...window.mR.findModule('sendGroupInviteMessage')[0]
|
||||
};
|
||||
window.Store.MembershipRequestUtils = {
|
||||
...window.mR.findModule('getMembershipApprovalRequests')[0],
|
||||
...window.mR.findModule('sendMembershipRequestsActionRPC')[0]
|
||||
};
|
||||
|
||||
if (!window.Store.Chat._find) {
|
||||
window.Store.Chat._find = e => {
|
||||
const target = window.Store.Chat.get(e);
|
||||
return target ? Promise.resolve(target) : Promise.resolve({
|
||||
id: e
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
if ((m = window.mR.findModule('ChatCollection')[0]) && m.ChatCollection && typeof m.ChatCollection.findImpl === 'undefined' && typeof m.ChatCollection._find !== 'undefined') m.ChatCollection.findImpl = m.ChatCollection._find;
|
||||
|
||||
const _isMDBackend = window.mR.findModule('isMDBackend');
|
||||
if(_isMDBackend && _isMDBackend[0] && _isMDBackend[0].isMDBackend) {
|
||||
window.Store.MDBackend = _isMDBackend[0].isMDBackend();
|
||||
} else {
|
||||
window.Store.MDBackend = true;
|
||||
}
|
||||
|
||||
const _features = window.mR.findModule('FEATURE_CHANGE_EVENT')[0];
|
||||
if(_features) {
|
||||
window.Store.Features = _features.LegacyPhoneFeatures;
|
||||
}
|
||||
|
||||
/**
|
||||
* Target options object description
|
||||
* @typedef {Object} TargetOptions
|
||||
* @property {string|number} module The name or a key of the target module to search
|
||||
* @property {number} index The index value of the target module
|
||||
* @property {string} function The function name to get from a module
|
||||
*/
|
||||
|
||||
/**
|
||||
* Function to modify functions
|
||||
* @param {TargetOptions} target Options specifying the target function to search for modifying
|
||||
* @param {Function} callback Modified function
|
||||
*/
|
||||
window.injectToFunction = (target, callback) => {
|
||||
const module = typeof target.module === 'string'
|
||||
? window.mR.findModule(target.module)
|
||||
: window.mR.modules[target.module];
|
||||
const originalFunction = module[target.index][target.function];
|
||||
const modifiedFunction = (...args) => callback(originalFunction, ...args);
|
||||
module[target.index][target.function] = modifiedFunction;
|
||||
};
|
||||
|
||||
window.injectToFunction({ module: 'mediaTypeFromProtobuf', index: 0, function: 'mediaTypeFromProtobuf' }, (func, ...args) => { const [proto] = args; return proto.locationMessage ? null : func(...args); });
|
||||
|
||||
window.injectToFunction({ module: 'typeAttributeFromProtobuf', index: 0, function: 'typeAttributeFromProtobuf' }, (func, ...args) => { const [proto] = args; return proto.locationMessage || proto.groupInviteMessage ? 'text' : func(...args); });
|
||||
};
|
||||
265
node_modules/whatsapp-web.js/src/util/Injected/Store.js
generated
vendored
Normal file
265
node_modules/whatsapp-web.js/src/util/Injected/Store.js
generated
vendored
Normal file
@@ -0,0 +1,265 @@
|
||||
'use strict';
|
||||
|
||||
exports.ExposeStore = () => {
|
||||
/**
|
||||
* Helper function that compares between two WWeb versions. Its purpose is to help the developer to choose the correct code implementation depending on the comparison value and the WWeb version.
|
||||
* @param {string} lOperand The left operand for the WWeb version string to compare with
|
||||
* @param {string} operator The comparison operator
|
||||
* @param {string} rOperand The right operand for the WWeb version string to compare with
|
||||
* @returns {boolean} Boolean value that indicates the result of the comparison
|
||||
*/
|
||||
window.compareWwebVersions = (lOperand, operator, rOperand) => {
|
||||
if (!['>', '>=', '<', '<=', '='].includes(operator)) {
|
||||
throw new class _ extends Error {
|
||||
constructor(m) { super(m); this.name = 'CompareWwebVersionsError'; }
|
||||
}('Invalid comparison operator is provided');
|
||||
|
||||
}
|
||||
if (typeof lOperand !== 'string' || typeof rOperand !== 'string') {
|
||||
throw new class _ extends Error {
|
||||
constructor(m) { super(m); this.name = 'CompareWwebVersionsError'; }
|
||||
}('A non-string WWeb version type is provided');
|
||||
}
|
||||
|
||||
lOperand = lOperand.replace(/-beta$/, '');
|
||||
rOperand = rOperand.replace(/-beta$/, '');
|
||||
|
||||
while (lOperand.length !== rOperand.length) {
|
||||
lOperand.length > rOperand.length
|
||||
? rOperand = rOperand.concat('0')
|
||||
: lOperand = lOperand.concat('0');
|
||||
}
|
||||
|
||||
lOperand = Number(lOperand.replace(/\./g, ''));
|
||||
rOperand = Number(rOperand.replace(/\./g, ''));
|
||||
|
||||
return (
|
||||
operator === '>' ? lOperand > rOperand :
|
||||
operator === '>=' ? lOperand >= rOperand :
|
||||
operator === '<' ? lOperand < rOperand :
|
||||
operator === '<=' ? lOperand <= rOperand :
|
||||
operator === '=' ? lOperand === rOperand :
|
||||
false
|
||||
);
|
||||
};
|
||||
|
||||
window.Store = Object.assign({}, window.require('WAWebCollections'));
|
||||
window.Store.AppState = window.require('WAWebSocketModel').Socket;
|
||||
window.Store.BlockContact = window.require('WAWebBlockContactAction');
|
||||
window.Store.Conn = window.require('WAWebConnModel').Conn;
|
||||
window.Store.Cmd = window.require('WAWebCmd').Cmd;
|
||||
window.Store.DownloadManager = window.require('WAWebDownloadManager').downloadManager;
|
||||
window.Store.GroupQueryAndUpdate = window.require('WAWebGroupQueryJob').queryAndUpdateGroupMetadataById;
|
||||
window.Store.MediaPrep = window.require('WAWebPrepRawMedia');
|
||||
window.Store.MediaObject = window.require('WAWebMediaStorage');
|
||||
window.Store.MediaTypes = window.require('WAWebMmsMediaTypes');
|
||||
window.Store.MediaUpload = {
|
||||
...window.require('WAWebMediaMmsV4Upload'),
|
||||
...window.require('WAWebStartMediaUploadQpl')
|
||||
};
|
||||
window.Store.MediaUpdate = window.require('WAWebMediaUpdateMsg');
|
||||
window.Store.MsgKey = window.require('WAWebMsgKey');
|
||||
window.Store.OpaqueData = window.require('WAWebMediaOpaqueData');
|
||||
window.Store.QueryProduct = window.require('WAWebBizProductCatalogBridge');
|
||||
window.Store.QueryOrder = window.require('WAWebBizOrderBridge');
|
||||
window.Store.SendClear = window.require('WAWebChatClearBridge');
|
||||
window.Store.SendDelete = window.require('WAWebDeleteChatAction');
|
||||
window.Store.SendMessage = window.require('WAWebSendMsgChatAction');
|
||||
window.Store.EditMessage = window.require('WAWebSendMessageEditAction');
|
||||
window.Store.MediaDataUtils = window.require('WAWebMediaDataUtils');
|
||||
window.Store.BlobCache = window.require('WAWebMediaInMemoryBlobCache');
|
||||
window.Store.SendSeen = window.require('WAWebUpdateUnreadChatAction');
|
||||
window.Store.User = window.require('WAWebUserPrefsMeUser');
|
||||
window.Store.ContactMethods = {
|
||||
...window.require('WAWebContactGetters'),
|
||||
...window.require('WAWebFrontendContactGetters')
|
||||
};
|
||||
window.Store.UserConstructor = window.require('WAWebWid');
|
||||
window.Store.Validators = window.require('WALinkify');
|
||||
window.Store.WidFactory = window.require('WAWebWidFactory');
|
||||
window.Store.ProfilePic = window.require('WAWebContactProfilePicThumbBridge');
|
||||
window.Store.PresenceUtils = window.require('WAWebPresenceChatAction');
|
||||
window.Store.ChatState = window.require('WAWebChatStateBridge');
|
||||
window.Store.findCommonGroups = window.require('WAWebFindCommonGroupsContactAction').findCommonGroups;
|
||||
window.Store.ConversationMsgs = window.require('WAWebChatLoadMessages');
|
||||
window.Store.sendReactionToMsg = window.require('WAWebSendReactionMsgAction').sendReactionToMsg;
|
||||
window.Store.createOrUpdateReactionsModule = window.require('WAWebDBCreateOrUpdateReactions');
|
||||
window.Store.EphemeralFields = window.require('WAWebGetEphemeralFieldsMsgActionsUtils');
|
||||
window.Store.MsgActionChecks = window.require('WAWebMsgActionCapability');
|
||||
window.Store.QuotedMsg = window.require('WAWebQuotedMsgModelUtils');
|
||||
window.Store.LinkPreview = window.require('WAWebLinkPreviewChatAction');
|
||||
window.Store.Socket = window.require('WADeprecatedSendIq');
|
||||
window.Store.SocketWap = window.require('WAWap');
|
||||
window.Store.SearchContext = window.require('WAWebChatMessageSearch');
|
||||
window.Store.DrawerManager = window.require('WAWebDrawerManager').DrawerManager;
|
||||
window.Store.LidUtils = window.require('WAWebApiContact');
|
||||
window.Store.WidToJid = window.require('WAWebWidToJid');
|
||||
window.Store.JidToWid = window.require('WAWebJidToWid');
|
||||
window.Store.getMsgInfo = window.require('WAWebApiMessageInfoStore').queryMsgInfo;
|
||||
window.Store.QueryExist = window.require('WAWebQueryExistsJob').queryWidExists;
|
||||
window.Store.ReplyUtils = window.require('WAWebMsgReply');
|
||||
window.Store.BotSecret = window.require('WAWebBotMessageSecret');
|
||||
window.Store.BotProfiles = window.require('WAWebBotProfileCollection');
|
||||
window.Store.ContactCollection = window.require('WAWebContactCollection').ContactCollection;
|
||||
window.Store.DeviceList = window.require('WAWebApiDeviceList');
|
||||
window.Store.HistorySync = window.require('WAWebSendNonMessageDataRequest');
|
||||
window.Store.AddonReactionTable = window.require('WAWebAddonReactionTableMode').reactionTableMode;
|
||||
window.Store.AddonPollVoteTable = window.require('WAWebAddonPollVoteTableMode').pollVoteTableMode;
|
||||
window.Store.ChatGetters = window.require('WAWebChatGetters');
|
||||
window.Store.UploadUtils = window.require('WAWebUploadManager');
|
||||
window.Store.WAWebStreamModel = window.require('WAWebStreamModel');
|
||||
window.Store.FindOrCreateChat = window.require('WAWebFindChatAction');
|
||||
window.Store.CustomerNoteUtils = window.require('WAWebNoteAction');
|
||||
window.Store.BusinessGatingUtils = window.require('WAWebBizGatingUtils');
|
||||
window.Store.PollsVotesSchema = window.require('WAWebPollsVotesSchema');
|
||||
window.Store.PollsSendVote = window.require('WAWebPollsSendVoteMsgAction');
|
||||
|
||||
window.Store.Settings = {
|
||||
...window.require('WAWebUserPrefsGeneral'),
|
||||
...window.require('WAWebUserPrefsNotifications'),
|
||||
setPushname: window.require('WAWebSetPushnameConnAction').setPushname
|
||||
};
|
||||
window.Store.NumberInfo = {
|
||||
...window.require('WAPhoneUtils'),
|
||||
...window.require('WAPhoneFindCC')
|
||||
};
|
||||
window.Store.ForwardUtils = {
|
||||
...window.require('WAWebChatForwardMessage')
|
||||
};
|
||||
window.Store.PinnedMsgUtils = {
|
||||
...window.require('WAWebPinInChatSchema'),
|
||||
...window.require('WAWebSendPinMessageAction')
|
||||
};
|
||||
window.Store.ScheduledEventMsgUtils = {
|
||||
...window.require('WAWebGenerateEventCallLink'),
|
||||
...window.require('WAWebSendEventEditMsgAction'),
|
||||
...window.require('WAWebSendEventResponseMsgAction')
|
||||
};
|
||||
window.Store.VCard = {
|
||||
...window.require('WAWebFrontendVcardUtils'),
|
||||
...window.require('WAWebVcardParsingUtils'),
|
||||
...window.require('WAWebVcardGetNameFromParsed')
|
||||
};
|
||||
window.Store.StickerTools = {
|
||||
...window.require('WAWebImageUtils'),
|
||||
...window.require('WAWebAddWebpMetadata')
|
||||
};
|
||||
window.Store.GroupUtils = {
|
||||
...window.require('WAWebGroupCreateJob'),
|
||||
...window.require('WAWebGroupModifyInfoJob'),
|
||||
...window.require('WAWebExitGroupAction'),
|
||||
...window.require('WAWebContactProfilePicThumbBridge'),
|
||||
...window.require('WAWebSetPropertyGroupAction')
|
||||
};
|
||||
window.Store.GroupParticipants = {
|
||||
...window.require('WAWebModifyParticipantsGroupAction'),
|
||||
...window.require('WASmaxGroupsAddParticipantsRPC')
|
||||
};
|
||||
window.Store.GroupInvite = {
|
||||
...window.require('WAWebGroupInviteJob'),
|
||||
...window.require('WAWebGroupQueryJob'),
|
||||
...window.require('WAWebMexFetchGroupInviteCodeJob')
|
||||
};
|
||||
window.Store.GroupInviteV4 = {
|
||||
...window.require('WAWebGroupInviteV4Job'),
|
||||
...window.require('WAWebChatSendMessages')
|
||||
};
|
||||
window.Store.MembershipRequestUtils = {
|
||||
...window.require('WAWebApiMembershipApprovalRequestStore'),
|
||||
...window.require('WASmaxGroupsMembershipRequestsActionRPC')
|
||||
};
|
||||
window.Store.ChannelUtils = {
|
||||
...window.require('WAWebLoadNewsletterPreviewChatAction'),
|
||||
...window.require('WAWebNewsletterMetadataQueryJob'),
|
||||
...window.require('WAWebNewsletterCreateQueryJob'),
|
||||
...window.require('WAWebEditNewsletterMetadataAction'),
|
||||
...window.require('WAWebNewsletterDeleteAction'),
|
||||
...window.require('WAWebNewsletterSubscribeAction'),
|
||||
...window.require('WAWebNewsletterUnsubscribeAction'),
|
||||
...window.require('WAWebNewsletterDirectorySearchAction'),
|
||||
...window.require('WAWebNewsletterGatingUtils'),
|
||||
...window.require('WAWebNewsletterModelUtils'),
|
||||
...window.require('WAWebMexAcceptNewsletterAdminInviteJob'),
|
||||
...window.require('WAWebMexRevokeNewsletterAdminInviteJob'),
|
||||
...window.require('WAWebChangeNewsletterOwnerAction'),
|
||||
...window.require('WAWebDemoteNewsletterAdminAction'),
|
||||
...window.require('WAWebNewsletterDemoteAdminJob'),
|
||||
countryCodesIso: window.require('WAWebCountriesNativeCountryNames'),
|
||||
currentRegion: window.require('WAWebL10N').getRegion(),
|
||||
};
|
||||
window.Store.SendChannelMessage = {
|
||||
...window.require('WAWebNewsletterUpdateMsgsRecordsJob'),
|
||||
...window.require('WAWebMsgDataFromModel'),
|
||||
...window.require('WAWebNewsletterSendMessageJob'),
|
||||
...window.require('WAWebNewsletterSendMsgAction'),
|
||||
...window.require('WAMediaCalculateFilehash')
|
||||
};
|
||||
window.Store.ChannelSubscribers = {
|
||||
...window.require('WAWebMexFetchNewsletterSubscribersJob'),
|
||||
...window.require('WAWebNewsletterSubscriberListAction')
|
||||
};
|
||||
window.Store.AddressbookContactUtils = {
|
||||
...window.require('WAWebSaveContactAction'),
|
||||
...window.require('WAWebDeleteContactAction')
|
||||
};
|
||||
window.Store.StatusUtils = {
|
||||
...window.require('WAWebContactStatusBridge'),
|
||||
...window.require('WAWebSendStatusMsgAction'),
|
||||
...window.require('WAWebRevokeStatusAction'),
|
||||
...window.require('WAWebStatusGatingUtils')
|
||||
};
|
||||
|
||||
if (!window.Store.Chat._find || !window.Store.Chat.findImpl) {
|
||||
window.Store.Chat._find = e => {
|
||||
const target = window.Store.Chat.get(e);
|
||||
return target ? Promise.resolve(target) : Promise.resolve({
|
||||
id: e
|
||||
});
|
||||
};
|
||||
window.Store.Chat.findImpl = window.Store.Chat._find;
|
||||
}
|
||||
|
||||
/**
|
||||
* Target options object description
|
||||
* @typedef {Object} TargetOptions
|
||||
* @property {string|number} module The target module
|
||||
* @property {string} function The function name to get from a module
|
||||
*/
|
||||
/**
|
||||
* Function to modify functions
|
||||
* @param {TargetOptions} target Options specifying the target function to search for modifying
|
||||
* @param {Function} callback Modified function
|
||||
*/
|
||||
window.injectToFunction = (target, callback) => {
|
||||
try {
|
||||
let module = window.require(target.module);
|
||||
if (!module) return;
|
||||
|
||||
const path = target.function.split('.');
|
||||
const funcName = path.pop();
|
||||
|
||||
for (const key of path) {
|
||||
if (!module[key]) return;
|
||||
module = module[key];
|
||||
}
|
||||
|
||||
const originalFunction = module[funcName];
|
||||
if (typeof originalFunction !== 'function') return;
|
||||
|
||||
module[funcName] = (...args) => {
|
||||
try {
|
||||
return callback(originalFunction, ...args);
|
||||
} catch {
|
||||
return originalFunction(...args);
|
||||
}
|
||||
};
|
||||
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
window.injectToFunction({ module: 'WAWebBackendJobsCommon', function: 'mediaTypeFromProtobuf' }, (func, ...args) => { const [proto] = args; return proto.locationMessage ? null : func(...args); });
|
||||
|
||||
window.injectToFunction({ module: 'WAWebE2EProtoUtils', function: 'typeAttributeFromProtobuf' }, (func, ...args) => { const [proto] = args; return proto.locationMessage || proto.groupInviteMessage ? 'text' : func(...args); });
|
||||
};
|
||||
1229
node_modules/whatsapp-web.js/src/util/Injected/Utils.js
generated
vendored
Normal file
1229
node_modules/whatsapp-web.js/src/util/Injected/Utils.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
126
node_modules/whatsapp-web.js/src/util/InterfaceController.js
generated
vendored
Normal file
126
node_modules/whatsapp-web.js/src/util/InterfaceController.js
generated
vendored
Normal file
@@ -0,0 +1,126 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Interface Controller
|
||||
*/
|
||||
class InterfaceController {
|
||||
|
||||
constructor(props) {
|
||||
this.pupPage = props.pupPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the Chat Window
|
||||
* @param {string} chatId ID of the chat window that will be opened
|
||||
*/
|
||||
async openChatWindow(chatId) {
|
||||
return await this.pupPage.evaluate(async (chatId) => {
|
||||
const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
|
||||
return await window.Store.Cmd.openChatBottom({'chat':chat});
|
||||
}, chatId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the Chat Drawer
|
||||
* @param {string} chatId ID of the chat drawer that will be opened
|
||||
*/
|
||||
async openChatDrawer(chatId) {
|
||||
await this.pupPage.evaluate(async chatId => {
|
||||
let chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
|
||||
await window.Store.Cmd.openDrawerMid(chat);
|
||||
}, chatId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the Chat Search
|
||||
* @param {string} chatId ID of the chat search that will be opened
|
||||
*/
|
||||
async openChatSearch(chatId) {
|
||||
await this.pupPage.evaluate(async chatId => {
|
||||
let chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
|
||||
await window.Store.Cmd.chatSearch(chat);
|
||||
}, chatId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens or Scrolls the Chat Window to the position of the message
|
||||
* @param {string} msgId ID of the message that will be scrolled to
|
||||
*/
|
||||
async openChatWindowAt(msgId) {
|
||||
await this.pupPage.evaluate(async (msgId) => {
|
||||
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
||||
const chat = window.Store.Chat.get(msg.id.remote) ?? await window.Store.Chat.find(msg.id.remote);
|
||||
const searchContext = await window.Store.SearchContext.getSearchContext(chat, msg.id);
|
||||
await window.Store.Cmd.openChatAt({ chat: chat, msgContext: searchContext });
|
||||
}, msgId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the Message Drawer
|
||||
* @param {string} msgId ID of the message drawer that will be opened
|
||||
*/
|
||||
async openMessageDrawer(msgId) {
|
||||
await this.pupPage.evaluate(async msgId => {
|
||||
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
||||
await window.Store.Cmd.msgInfoDrawer(msg);
|
||||
}, msgId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the Right Drawer
|
||||
*/
|
||||
async closeRightDrawer() {
|
||||
await this.pupPage.evaluate(async () => {
|
||||
await window.Store.DrawerManager.closeDrawerRight();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Features
|
||||
*/
|
||||
async getFeatures() {
|
||||
return await this.pupPage.evaluate(() => {
|
||||
if(!window.Store.Features) throw new Error('This version of Whatsapp Web does not support features');
|
||||
return window.Store.Features.F;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Feature is enabled
|
||||
* @param {string} feature status to check
|
||||
*/
|
||||
async checkFeatureStatus(feature) {
|
||||
return await this.pupPage.evaluate((feature) => {
|
||||
if(!window.Store.Features) throw new Error('This version of Whatsapp Web does not support features');
|
||||
return window.Store.Features.supportsFeature(feature);
|
||||
}, feature);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable Features
|
||||
* @param {string[]} features to be enabled
|
||||
*/
|
||||
async enableFeatures(features) {
|
||||
await this.pupPage.evaluate((features) => {
|
||||
if(!window.Store.Features) throw new Error('This version of Whatsapp Web does not support features');
|
||||
for (const feature in features) {
|
||||
window.Store.Features.setFeature(features[feature], true);
|
||||
}
|
||||
}, features);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable Features
|
||||
* @param {string[]} features to be disabled
|
||||
*/
|
||||
async disableFeatures(features) {
|
||||
await this.pupPage.evaluate((features) => {
|
||||
if(!window.Store.Features) throw new Error('This version of Whatsapp Web does not support features');
|
||||
for (const feature in features) {
|
||||
window.Store.Features.setFeature(features[feature], false);
|
||||
}
|
||||
}, features);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = InterfaceController;
|
||||
23
node_modules/whatsapp-web.js/src/util/Puppeteer.js
generated
vendored
Normal file
23
node_modules/whatsapp-web.js/src/util/Puppeteer.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Expose a function to the page if it does not exist
|
||||
*
|
||||
* NOTE:
|
||||
* Rewrite it to 'upsertFunction' after updating Puppeteer to 20.6 or higher
|
||||
* using page.removeExposedFunction
|
||||
* https://pptr.dev/api/puppeteer.page.removeexposedfunction
|
||||
*
|
||||
* @param {object} page - Puppeteer Page instance
|
||||
* @param {string} name
|
||||
* @param {Function} fn
|
||||
*/
|
||||
async function exposeFunctionIfAbsent(page, name, fn) {
|
||||
const exist = await page.evaluate((name) => {
|
||||
return !!window[name];
|
||||
}, name);
|
||||
if (exist) {
|
||||
return;
|
||||
}
|
||||
await page.exposeFunction(name, fn);
|
||||
}
|
||||
|
||||
module.exports = {exposeFunctionIfAbsent};
|
||||
186
node_modules/whatsapp-web.js/src/util/Util.js
generated
vendored
Normal file
186
node_modules/whatsapp-web.js/src/util/Util.js
generated
vendored
Normal file
@@ -0,0 +1,186 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const Crypto = require('crypto');
|
||||
const { tmpdir } = require('os');
|
||||
const ffmpeg = require('fluent-ffmpeg');
|
||||
const webp = require('node-webpmux');
|
||||
const fs = require('fs').promises;
|
||||
const has = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
|
||||
|
||||
/**
|
||||
* Utility methods
|
||||
*/
|
||||
class Util {
|
||||
constructor() {
|
||||
throw new Error(`The ${this.constructor.name} class may not be instantiated.`);
|
||||
}
|
||||
|
||||
static generateHash(length) {
|
||||
var result = '';
|
||||
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
var charactersLength = characters.length;
|
||||
for (var i = 0; i < length; i++) {
|
||||
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets default properties on an object that aren't already specified.
|
||||
* @param {Object} def Default properties
|
||||
* @param {Object} given Object to assign defaults to
|
||||
* @returns {Object}
|
||||
* @private
|
||||
*/
|
||||
static mergeDefault(def, given) {
|
||||
if (!given) return def;
|
||||
for (const key in def) {
|
||||
if (!has(given, key) || given[key] === undefined) {
|
||||
given[key] = def[key];
|
||||
} else if (given[key] === Object(given[key])) {
|
||||
given[key] = Util.mergeDefault(def[key], given[key]);
|
||||
}
|
||||
}
|
||||
|
||||
return given;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a image to webp
|
||||
* @param {MessageMedia} media
|
||||
*
|
||||
* @returns {Promise<MessageMedia>} media in webp format
|
||||
*/
|
||||
static async formatImageToWebpSticker(media, pupPage) {
|
||||
if (!media.mimetype.includes('image'))
|
||||
throw new Error('media is not a image');
|
||||
|
||||
if (media.mimetype.includes('webp')) {
|
||||
return media;
|
||||
}
|
||||
|
||||
return pupPage.evaluate((media) => {
|
||||
return window.WWebJS.toStickerData(media);
|
||||
}, media);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a video to webp
|
||||
* @param {MessageMedia} media
|
||||
*
|
||||
* @returns {Promise<MessageMedia>} media in webp format
|
||||
*/
|
||||
static async formatVideoToWebpSticker(media) {
|
||||
if (!media.mimetype.includes('video'))
|
||||
throw new Error('media is not a video');
|
||||
|
||||
const videoType = media.mimetype.split('/')[1];
|
||||
|
||||
const tempFile = path.join(
|
||||
tmpdir(),
|
||||
`${Crypto.randomBytes(6).readUIntLE(0, 6).toString(36)}.webp`
|
||||
);
|
||||
|
||||
const stream = new (require('stream').Readable)();
|
||||
const buffer = Buffer.from(
|
||||
media.data.replace(`data:${media.mimetype};base64,`, ''),
|
||||
'base64'
|
||||
);
|
||||
stream.push(buffer);
|
||||
stream.push(null);
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
ffmpeg(stream)
|
||||
.inputFormat(videoType)
|
||||
.on('error', reject)
|
||||
.on('end', () => resolve(true))
|
||||
.addOutputOptions([
|
||||
'-vcodec',
|
||||
'libwebp',
|
||||
'-vf',
|
||||
// eslint-disable-next-line no-useless-escape
|
||||
'scale=\'iw*min(300/iw\,300/ih)\':\'ih*min(300/iw\,300/ih)\',format=rgba,pad=300:300:\'(300-iw)/2\':\'(300-ih)/2\':\'#00000000\',setsar=1,fps=10',
|
||||
'-loop',
|
||||
'0',
|
||||
'-ss',
|
||||
'00:00:00.0',
|
||||
'-t',
|
||||
'00:00:05.0',
|
||||
'-preset',
|
||||
'default',
|
||||
'-an',
|
||||
'-vsync',
|
||||
'0',
|
||||
'-s',
|
||||
'512:512',
|
||||
])
|
||||
.toFormat('webp')
|
||||
.save(tempFile);
|
||||
});
|
||||
|
||||
const data = await fs.readFile(tempFile, 'base64');
|
||||
await fs.unlink(tempFile);
|
||||
|
||||
return {
|
||||
mimetype: 'image/webp',
|
||||
data: data,
|
||||
filename: media.filename,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Sticker metadata.
|
||||
* @typedef {Object} StickerMetadata
|
||||
* @property {string} [name]
|
||||
* @property {string} [author]
|
||||
* @property {string[]} [categories]
|
||||
*/
|
||||
|
||||
/**
|
||||
* Formats a media to webp
|
||||
* @param {MessageMedia} media
|
||||
* @param {StickerMetadata} metadata
|
||||
*
|
||||
* @returns {Promise<MessageMedia>} media in webp format
|
||||
*/
|
||||
static async formatToWebpSticker(media, metadata, pupPage) {
|
||||
let webpMedia;
|
||||
|
||||
if (media.mimetype.includes('image'))
|
||||
webpMedia = await this.formatImageToWebpSticker(media, pupPage);
|
||||
else if (media.mimetype.includes('video'))
|
||||
webpMedia = await this.formatVideoToWebpSticker(media);
|
||||
else
|
||||
throw new Error('Invalid media format');
|
||||
|
||||
if (metadata.name || metadata.author) {
|
||||
const img = new webp.Image();
|
||||
const hash = this.generateHash(32);
|
||||
const stickerPackId = hash;
|
||||
const packname = metadata.name;
|
||||
const author = metadata.author;
|
||||
const categories = metadata.categories || [''];
|
||||
const json = { 'sticker-pack-id': stickerPackId, 'sticker-pack-name': packname, 'sticker-pack-publisher': author, 'emojis': categories };
|
||||
let exifAttr = Buffer.from([0x49, 0x49, 0x2A, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x41, 0x57, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00]);
|
||||
let jsonBuffer = Buffer.from(JSON.stringify(json), 'utf8');
|
||||
let exif = Buffer.concat([exifAttr, jsonBuffer]);
|
||||
exif.writeUIntLE(jsonBuffer.length, 14, 4);
|
||||
await img.load(Buffer.from(webpMedia.data, 'base64'));
|
||||
img.exif = exif;
|
||||
webpMedia.data = (await img.save(null)).toString('base64');
|
||||
}
|
||||
|
||||
return webpMedia;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure ffmpeg path
|
||||
* @param {string} path
|
||||
*/
|
||||
static setFfmpegPath(path) {
|
||||
ffmpeg.setFfmpegPath(path);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Util;
|
||||
Reference in New Issue
Block a user