mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 03:29:14 +00:00
Compare commits
2 Commits
add-polls
...
pedroslope
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8afe71d959 | ||
|
|
afb0b5d7d3 |
@@ -6,6 +6,7 @@ const moduleRaid = require('@pedroslopez/moduleraid/moduleraid');
|
||||
|
||||
const Util = require('./util/Util');
|
||||
const InterfaceController = require('./util/InterfaceController');
|
||||
const { getIndexForVersion } = require('./util/VersionResolver');
|
||||
const { WhatsWebURL, DefaultOptions, Events, WAState } = require('./util/Constants');
|
||||
const { ExposeStore, LoadUtils } = require('./util/Injected');
|
||||
const ChatFactory = require('./factories/ChatFactory');
|
||||
@@ -108,6 +109,7 @@ class Client extends EventEmitter {
|
||||
this.pupPage = page;
|
||||
|
||||
await this.authStrategy.afterBrowserInitialized();
|
||||
await this.initVersionOverride();
|
||||
|
||||
await page.goto(WhatsWebURL, {
|
||||
waitUntil: 'load',
|
||||
@@ -562,6 +564,22 @@ class Client extends EventEmitter {
|
||||
});
|
||||
}
|
||||
|
||||
async initVersionOverride() {
|
||||
const version = this.options.webVersion;
|
||||
await this.pupPage.setRequestInterception(true);
|
||||
this.pupPage.on('request', async (req) => {
|
||||
if(req.url() === WhatsWebURL) {
|
||||
req.respond({
|
||||
status: 200,
|
||||
contentType: 'text/html',
|
||||
body: await getIndexForVersion(version)
|
||||
});
|
||||
} else {
|
||||
req.continue();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the client
|
||||
*/
|
||||
|
||||
@@ -7,6 +7,7 @@ exports.DefaultOptions = {
|
||||
headless: true,
|
||||
defaultViewport: null
|
||||
},
|
||||
webVersion: '2.2244.6',
|
||||
authTimeoutMs: 0,
|
||||
qrMaxRetries: 0,
|
||||
takeoverOnConflict: false,
|
||||
|
||||
16
src/util/VersionResolver.js
Normal file
16
src/util/VersionResolver.js
Normal file
@@ -0,0 +1,16 @@
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
const VERSION_ARCHIVE_URL = 'https://archive.wwebjs.dev/web-index';
|
||||
|
||||
class VersionResolveError extends Error { }
|
||||
|
||||
const getIndexForVersion = async (version) => {
|
||||
const cachedRes = await fetch(`${VERSION_ARCHIVE_URL}/${version}`);
|
||||
if(!cachedRes.ok) throw new VersionResolveError(`Couldn't load app for version ${version} from the archive`);
|
||||
return cachedRes.text();
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
VersionResolveError,
|
||||
getIndexForVersion
|
||||
};
|
||||
@@ -18,15 +18,24 @@ const getCurrentVersion = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const updateVersion = async (oldVersion, newVersion) => {
|
||||
const readmePath = '../../README.md';
|
||||
|
||||
const readme = fs.readFileSync(readmePath);
|
||||
const newReadme = readme.toString().replaceAll(oldVersion, newVersion);
|
||||
const updateInFile = (filePath, oldVersion, newVersion) => {
|
||||
const originalFile = fs.readFileSync(filePath);
|
||||
const newFile = originalFile.toString().replaceAll(oldVersion, newVersion);
|
||||
|
||||
fs.writeFileSync(readmePath, newReadme);
|
||||
fs.writeFileSync('./.version', newVersion);
|
||||
|
||||
fs.writeFileSync(filePath, newFile);
|
||||
};
|
||||
|
||||
const updateVersion = async (oldVersion, newVersion) => {
|
||||
const filesToUpdate = [
|
||||
'../../src/util/Constants.js',
|
||||
'../../README.md',
|
||||
];
|
||||
|
||||
for (const file of filesToUpdate) {
|
||||
updateInFile(file, oldVersion, newVersion);
|
||||
}
|
||||
|
||||
fs.writeFileSync('./.version', newVersion);
|
||||
};
|
||||
|
||||
(async () => {
|
||||
|
||||
Reference in New Issue
Block a user