UNPKG

bot_genshin

Version:
153 lines (134 loc) 5.18 kB
<!doctype html> <html> <head> <meta name="generator" content="JSDoc 3.6.7"> <meta charset="utf-8"> <title>whatsapp-web.js 1.14.0 &raquo; Source: structures/MessageMedia.js</title> <link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css"> <link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css"> <link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css"> <link href="css/baseline.css" rel="stylesheet"> </head> <body onload="prettyPrint()"> <nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar"> <div id="jsdoc-navbar-container"> <div id="jsdoc-navbar-content"> <a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>14.<wbr>0</a> </div> </div> </nav> <div id="jsdoc-body-container"> <div id="jsdoc-content"> <div id="jsdoc-content-container"> <div id="jsdoc-banner" role="banner"> </div> <div id="jsdoc-main" role="main"> <header class="page-header"> <h1>Source: structures/MessageMedia.js</h1> </header> <article> <pre class="prettyprint linenums"><code>&#x27;use strict&#x27;; const fs &#x3D; require(&#x27;fs&#x27;); const path &#x3D; require(&#x27;path&#x27;); const mime &#x3D; require(&#x27;mime&#x27;); const fetch &#x3D; require(&#x27;node-fetch&#x27;); const { URL } &#x3D; require(&#x27;url&#x27;); /** * Media attached to a message * @param {string} mimetype MIME type of the attachment * @param {string} data Base64-encoded data of the file * @param {?string} filename Document file name */ class MessageMedia { constructor(mimetype, data, filename) { /** * MIME type of the attachment * @type {string} */ this.mimetype &#x3D; mimetype; /** * Base64 encoded data that represents the file * @type {string} */ this.data &#x3D; data; /** * Name of the file (for documents) * @type {?string} */ this.filename &#x3D; filename; } /** * Creates a MessageMedia instance from a local file path * @param {string} filePath * @returns {MessageMedia} */ static fromFilePath(filePath) { const b64data &#x3D; fs.readFileSync(filePath, {encoding: &#x27;base64&#x27;}); const mimetype &#x3D; mime.getType(filePath); const filename &#x3D; path.basename(filePath); return new MessageMedia(mimetype, b64data, filename); } /** * Creates a MessageMedia instance from a URL * @param {string} url * @param {Object} [options] * @param {number} [options.unsafeMime&#x3D;false] * @param {object} [options.client] * @param {object} [options.reqOptions] * @param {number} [options.reqOptions.size&#x3D;0] * @returns {Promise&amp;lt;MessageMedia&gt;} */ static async fromUrl(url, options &#x3D; {}) { let mimetype; if (!options.unsafeMime) { const pUrl &#x3D; new URL(url); mimetype &#x3D; mime.getType(pUrl.pathname); if (!mimetype) throw new Error(&#x27;Unable to determine MIME type&#x27;); } async function fetchData (url, options) { const reqOptions &#x3D; Object.assign({ headers: { accept: &#x27;image/* video/* text/* audio/*&#x27; } }, options); const response &#x3D; await fetch(url, reqOptions); const mime &#x3D; response.headers.get(&#x27;Content-Type&#x27;); let data &#x3D; &#x27;&#x27;; if (response.buffer) { data &#x3D; (await response.buffer()).toString(&#x27;base64&#x27;); } else { const bArray &#x3D; new Uint8Array(await response.arrayBuffer()); bArray.forEach((b) &#x3D;&gt; { data +&#x3D; String.fromCharCode(b); }); data &#x3D; btoa(data); } return { data, mime }; } const res &#x3D; options.client ? (await options.client.pupPage.evaluate(fetchData, url, options.reqOptions)) : (await fetchData(url, options.reqOptions)); if (!mimetype) mimetype &#x3D; res.mime; return new MessageMedia(mimetype, res.data, null); } } module.exports &#x3D; MessageMedia;</code></pre> </article> </div> </div> <nav id="jsdoc-toc-nav" role="navigation"></nav> </div> </div> <footer id="jsdoc-footer" class="jsdoc-footer"> <div id="jsdoc-footer-container"> <p> Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on August 1, 2021. </p> </div> </footer> <script src="scripts/jquery.min.js"></script> <script src="scripts/tree.jquery.js"></script> <script src="scripts/prettify.js"></script> <script src="scripts/jsdoc-toc.js"></script> <script src="scripts/linenumber.js"></script> <script src="scripts/scrollanchor.js"></script> </body> </html>