Add killpage support
This commit is contained in:
parent
79a833133c
commit
37129d3833
3 changed files with 34 additions and 2 deletions
|
|
@ -18,9 +18,15 @@ export class MediaWikiClient {
|
|||
* @param {string} wikiURL Target wiki's MediaWiki path (i.e. the path that
|
||||
* contains `index.php` and `api.php`) without a trailing slash. For example
|
||||
* for English Wikipedia this would be `'https://en.wikipedia.org/w'`.
|
||||
* @param {object} options
|
||||
* @param {string} [options.killPage] Name of a page that, if provided, will
|
||||
* be read periodically. If the page ever contains text, the process will be
|
||||
* killed. This is a safety measure allowing other editors to kill an
|
||||
* unattended script if it misbehaves.
|
||||
*/
|
||||
constructor (wikiURL) {
|
||||
constructor (wikiURL, {killPage}) {
|
||||
this.wikiURL = wikiURL;
|
||||
this.killPage = killPage;
|
||||
this.fetch = makeFetchCookie(fetch);
|
||||
}
|
||||
|
||||
|
|
@ -122,6 +128,20 @@ export class MediaWikiClient {
|
|||
if (body.login.result === 'Failed') {
|
||||
throw new Error(body.login.reason);
|
||||
}
|
||||
|
||||
if (this.killPage) {
|
||||
// start the kill page check loop as soon as we're logged in
|
||||
const checkKillPage = async () => {
|
||||
let content = await this.readPage(this.killPage);
|
||||
if (content.trim()) {
|
||||
console.error('*** Kill page is not empty; stopping ***\n');
|
||||
console.error(content);
|
||||
process.exit(1);
|
||||
}
|
||||
setTimeout(checkKillPage, 30 * 1000); // every 30 seconds
|
||||
};
|
||||
checkKillPage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue