Comparing version 0.6.0 to 0.6.1
{ | ||
"name": "notabase", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"description": "API Wrapper For Notion's Database", | ||
@@ -5,0 +5,0 @@ "main": "src/notabase.js", |
import Collection from './collection' | ||
import { getBlockHashId, getFullBlockId } from './utils' | ||
import { getBlockHashId, getFullBlockId, getUrlPageId } from './utils' | ||
@@ -11,2 +11,3 @@ | ||
this.collectionSchemaStore = {} | ||
this.collectionStore = {} | ||
const { proxy, token } = options | ||
@@ -117,24 +118,30 @@ // proxy > browser env + cloudflare worker | ||
} | ||
async _fetch(urlOrPageId) { | ||
let collectionId, collectionViewId | ||
async fetch(urlOrPageId) { | ||
let collectionId, collectionViewId, pageId | ||
if (urlOrPageId.match("^[a-zA-Z0-9-]+$")) { | ||
// pageId with '-' split | ||
[collectionId, collectionViewId] = await this.getPageCollectionInfo(getBlockHashId(urlOrPageId)) | ||
pageId = getBlockHashId(urlOrPageId) | ||
if (pageId && pageId in this.collectionStore) { | ||
return this.collectionStore[pageId] | ||
} else { | ||
[collectionId, collectionViewId] = await this.getPageCollectionInfo(getBlockHashId(urlOrPageId)) | ||
} | ||
} else if (urlOrPageId.startsWith("http")) { | ||
// url | ||
let [base, params] = urlOrPageId.split('?') | ||
if (!process.browser) { | ||
const { URLSearchParams } = require('url') | ||
pageId = getUrlPageId(urlOrPageId) | ||
if (pageId && pageId in this.collectionStore) { | ||
return this.collectionStore[pageId] | ||
} else { | ||
let [base, params] = urlOrPageId.split('?') | ||
let baseUrlList = base.split('/'); // 这里需要添加分号,否则编译出错。 参见 https://www.zhihu.com/question/20298345/answer/49551142 | ||
[collectionId, collectionViewId] = await this.getPageCollectionInfo(baseUrlList[baseUrlList.length - 1]) | ||
} | ||
let p = new URLSearchParams(params) | ||
let baseUrlList = base.split('/'); // 这里需要添加分号,否则编译出错。 参见 https://www.zhihu.com/question/20298345/answer/49551142 | ||
[collectionId, collectionViewId] = await this.getPageCollectionInfo(baseUrlList[baseUrlList.length - 1]) | ||
} | ||
let r = await this.fetchCollectionData(collectionId, collectionViewId) | ||
this.collectionStore[pageId] = r | ||
return r | ||
} | ||
async fetch(dbMap) { | ||
async fetchAll(dbMap) { | ||
let db = {} | ||
@@ -141,0 +148,0 @@ let requests = Object.entries(dbMap).map(item => { |
@@ -25,3 +25,3 @@ const NOTION_BASE_URL = "https://www.notion.so" | ||
} | ||
const getUrlBlockId = (url) => { | ||
const getUrlPageId = (url) => { | ||
let pUrl | ||
@@ -35,4 +35,4 @@ if (!process.browser) { | ||
let pathList = pUrl.pathname.split('/') | ||
let blockID = pathList[pathList.length - 1] | ||
return blockID | ||
let pagId = pathList[pathList.length - 1] | ||
return pagId | ||
} | ||
@@ -57,2 +57,2 @@ const parseImageUrl = (url, width) => { | ||
module.exports = { isPageId, getBlockHashId, getFullBlockId, getBrowseableUrl, getUrlBlockId, parseImageUrl } | ||
module.exports = { isPageId, getBlockHashId, getFullBlockId, getBrowseableUrl, getUrlPageId, parseImageUrl } |
24770
491