MCPcopy Create free account
hub / github.com/Xu22Web/tech-study-js / getAnswer

Function getAnswer

tech-study.js:338–370  ·  view source on GitHub ↗

* @description 获取答案

(question)

Source from the content-addressed store, hash-verified

336 * @description 获取答案
337 */
338async function getAnswer(question) {
339 // 数据
340 const data = {
341 txt_name: md5(question),
342 password: '',
343 };
344 try {
345 const params = new URLSearchParams(data);
346 // 请求
347 const res = await fetch(API_CONFIG.answerSearch, {
348 method: 'POST',
349 mode: 'cors',
350 headers: {
351 'Content-Type': 'application/x-www-form-urlencoded',
352 },
353 body: params.toString(),
354 });
355 // 请求成功
356 if (res.ok) {
357 const result = await res.json();
358 const { data, status } = result;
359 if (status !== 0) {
360 // 答案列表
361 const answerList = JSON.parse(data.txt_content);
362 // 答案
363 const answers = answerList[0].content.split(/[;\s]/);
364 return answers;
365 }
366 }
367 }
368 catch (error) { }
369 return [];
370}
371/**
372 * @description 保存答案
373 */

Callers 1

doingExamFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected