(questionUrl)
| 156 | } |
| 157 | |
| 158 | async function getQuestionSubmitInfo(questionUrl) { |
| 159 | const body = await request({uri: questionUrl, jar: cookies}); |
| 160 | const $ = cheerio.load(body); |
| 161 | |
| 162 | const elemList = $('.question-form input[name="__csrf_token"]'); |
| 163 | assert(elemList.length == 1); |
| 164 | const csrf_token = elemList[0].attribs.value; |
| 165 | |
| 166 | const questionSubmitInfo = {questionUrl, csrf_token}; |
| 167 | |
| 168 | if (argv.type == 'v2') { |
| 169 | const elemList = $('.question-data'); |
| 170 | assert(elemList.length == 1); |
| 171 | assert(elemList[0].children != null); |
| 172 | assert(elemList[0].children.length == 1); |
| 173 | assert(elemList[0].children[0].data != null); |
| 174 | const questionData = JSON.parse(decodeURIComponent(Buffer.from(elemList[0].children[0].data, 'base64').toString())); |
| 175 | assert(questionData.variant != null); |
| 176 | questionSubmitInfo.variant = questionData.variant; |
| 177 | } else if (argv.type == 'v3') { |
| 178 | const elemList = $('.question-form input[name="__variant_id"]'); |
| 179 | assert(elemList.length == 1); |
| 180 | questionSubmitInfo.variant_id = Number.parseInt(elemList[0].attribs.value); |
| 181 | } else { |
| 182 | throw new Error(`unknown type: ${argv.type}`); |
| 183 | } |
| 184 | |
| 185 | return questionSubmitInfo; |
| 186 | } |
| 187 | |
| 188 | async function postQuestionAnswer(questionSubmitInfo) { |
| 189 | let form; |
no test coverage detected