From da6bf581677e54d8d3bcc74ef970eaee5b491b94 Mon Sep 17 00:00:00 2001 From: terwer Date: Fri, 29 Jul 2022 12:22:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:#13=20=E5=8F=91=E5=B8=83=E5=88=B0Vuepress-?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E9=9D=9E=E6=8C=82=E4=BB=B6=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/siyuan/siYuanApi.ts | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/lib/siyuan/siYuanApi.ts b/src/lib/siyuan/siYuanApi.ts index 9833ddd4..a95e1456 100644 --- a/src/lib/siyuan/siYuanApi.ts +++ b/src/lib/siyuan/siYuanApi.ts @@ -53,18 +53,40 @@ export { 以id获取思源块信息 as getBlockByID, }; -async function 向思源请求数据(url: string, data: any) { +/** + * 向思源请求数据 + * @param url url + * @param data 数据 + * @param method 请求方法 GET | POST + * @param useToken 权限TOKEN + */ +async function 向思源请求数据(url: string, data: any, method?: string, useToken?: boolean) { let resData = null if (config.baseUrl != "") { url = config.baseUrl + url } - await fetch(url, { + + let m = "POST" + if (method) { + m = method; + } + + let fetchOps = { body: JSON.stringify(data), - method: 'POST', - headers: { - Authorization: `Token ${config.token}`, + method: m + } + if (useToken) { + fetchOps = { + body: JSON.stringify(data), + method: m, + // @ts-ignore + headers: { + Authorization: `Token ${config.token}`, + } } - }).then(function (response) { + } + + await fetch(url, fetchOps).then(function (response) { resData = response.json() }) return resData