Comparing version 0.5.0-next.2 to 0.5.0-next.3
{ | ||
"name": "notabase", | ||
"version": "0.5.0-next.2", | ||
"version": "0.5.0-next.3", | ||
"description": "API Wrapper For Notion's Database", | ||
@@ -5,0 +5,0 @@ "main": "src/notabase.js", |
@@ -0,1 +1,6 @@ | ||
const token_v2 = undefined | ||
const cookies = `token_v2=${token_v2}` | ||
const AUTH_CODE = 'nobody knows but you' | ||
addEventListener('fetch', event => { | ||
@@ -8,3 +13,3 @@ event.respondWith(fetchAndApply(event.request)) | ||
"Access-Control-Allow-Methods": "GET, HEAD, POST,PUT, OPTIONS", | ||
"Access-Control-Allow-Headers": "Content-Type", | ||
"Access-Control-Allow-Headers": "Content-Type,auth-code", | ||
} | ||
@@ -43,6 +48,15 @@ | ||
// 因为 PWA SW 中服务缓存 POST 请求,但是 notion 获取数据全是用的 POST 请求。这就很尴尬。。。 | ||
// 因为 SW 中无法缓存 POST 请求,但是 notion 获取数据全是用的 POST 请求 | ||
// 解决办法是把 POST 请求中的 body 转字符串,放在 url的查询参数中,在这里转换为 POST 请求 | ||
body = url.searchParams.get("body") | ||
let addHeader = {} | ||
let authCode = request.headers.get('auth-code') | ||
if (authCode && authCode === AUTH_CODE && token_v2) { | ||
// 本人操作 | ||
addHeader = { cookies } | ||
} | ||
// todo 针对 CUD 请求添加 cookies | ||
response = await fetch(`https://www.notion.so${url.pathname}`, { | ||
@@ -52,3 +66,4 @@ body: body, // must match 'Content-Type' header | ||
'content-type': 'application/json;charset=UTF-8', | ||
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36' | ||
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36', | ||
...addHeader | ||
}, | ||
@@ -55,0 +70,0 @@ method: "POST", // *GET, POST, PUT, DELETE, etc. |
@@ -29,3 +29,3 @@ const NOTION_BASE_URL = "https://www.notion.so" | ||
'content-type': 'application/json;charset=UTF-8', | ||
'auth-code': authCode, // custom header | ||
'x-auth-code': authCode, // custom header | ||
} | ||
@@ -32,0 +32,0 @@ }) |
30701
643