File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ import Ajv, {JSONSchemaType} from 'ajv';
22import { Mwn } from 'mwn' ;
33import parser from 'node-html-parser' ;
44
5+ const USER_AGENT = 'Highlight.css updater' ;
6+
57interface Config {
68 groups : {
79 [ key : string ] : {
@@ -78,8 +80,15 @@ async function getUsers({groups, overrides}: Config) {
7880 searchParams [ `groups[${ index ++ } ]` ] = group ;
7981 users [ group ] = [ ] ;
8082 }
81- const response = await fetch ( `https://dev.fandom.com/wiki/Special:ListGlobalUsers?${ new URLSearchParams ( searchParams ) } ` ) ;
83+ const response = await fetch ( `https://dev.fandom.com/wiki/Special:ListGlobalUsers?${ new URLSearchParams ( searchParams ) } ` , {
84+ headers : {
85+ 'User-Agent' : USER_AGENT ,
86+ } ,
87+ } ) ;
8288 const html = await response . text ( ) ;
89+ if ( ! response . ok ) {
90+ throw new Error ( `failed to fetch user group list: status code ${ response . status } , response: ${ html } ` ) ;
91+ }
8392 const tree = parser . parse ( html ) ;
8493 for ( const node of tree . querySelectorAll ( '.list-global-users-members > li' ) ) {
8594 const name = node . querySelector ( 'bdi' ) ?. innerText ;
@@ -129,7 +138,7 @@ async function init() {
129138 apiUrl : 'https://dev.fandom.com/api.php' ,
130139 password : process . env . PASSWORD ,
131140 silent : true ,
132- userAgent : 'Highlight.css updater' ,
141+ userAgent : USER_AGENT ,
133142 username : process . env . USERNAME ,
134143 } ) ;
135144 await bot . login ( ) ;
You can’t perform that action at this time.
0 commit comments