import axios from "axios" ; import * as vscode from "vscode" ; import { YQauth } from "./YQauth" ; import * as path from "path" ; export async function saveAnswer ( document , content , context ) { if ( ! context . globalState . get ( "yuqueToken" ) ) { vscode . window . showErrorMessage ( "请先获得语雀授权" , "是" , "否" ) . then ( ( result ) => { if ( result === "是" ) { YQauth ( context ) ; } } ) ; } else { const yuqueToken = context . globalState . get ( "yuqueToken" ) ; const yuqueRepoId = context . globalState . get ( "yuqueRepoId" ) ; const { fileName } = document ; const basename = path . basename ( fileName ) ; const dayId = basename . slice ( 0 , basename . indexOf ( "." ) ) ; try { await axios ( { method : "post" , url : `https://www.yuque.com/api/v2/repos/${ yuqueRepoId }/docs` , headers : { "X-Auth-Token" : yuqueToken , "Content-Type" : "application/x-www-form-urlencoded" , } , params : { title : basename , slug : dayId , public : 0 , body : content , } , } ) ; vscode . window . showInformationMessage ( "保存成功" ) ; } catch ( e ) { vscode . window . showErrorMessage ( "保存失败" ) ; } } }