electron fs: use notion:// for api reqs instead of http://

This commit is contained in:
dragonwocky 2021-12-13 18:40:26 +11:00
parent a44ae9f4f1
commit 50a77d05a1
Signed by: dragonwocky
GPG Key ID: 86DFC3C312A56010
2 changed files with 7 additions and 3 deletions

8
insert/env/fs.mjs vendored
View File

@ -32,7 +32,9 @@ export const localPath = (path) => `notion://www.notion.so/__notion-enhancer/${p
* @returns {object} the json value of the requested file as a js object * @returns {object} the json value of the requested file as a js object
*/ */
export const getJSON = (path, opts = {}) => { export const getJSON = (path, opts = {}) => {
if (path.startsWith('http')) return fetch(path, opts).then((res) => res.json()); path = path.replace(/^https:\/\/www\.notion\.so\//, 'notion://www.notion.so/');
const networkPath = path.startsWith('http') || path.startsWith('notion://');
if (networkPath) return fetch(path, opts).then((res) => res.json());
try { try {
return globalThis.__enhancerElectronApi.nodeRequire(`notion-enhancer/${path}`); return globalThis.__enhancerElectronApi.nodeRequire(`notion-enhancer/${path}`);
} catch (err) { } catch (err) {
@ -47,7 +49,9 @@ export const getJSON = (path, opts = {}) => {
* @returns {string} the text content of the requested file * @returns {string} the text content of the requested file
*/ */
export const getText = (path, opts = {}) => { export const getText = (path, opts = {}) => {
if (path.startsWith('http')) return fetch(path, opts).then((res) => res.text()); path = path.replace(/^https:\/\/www\.notion\.so\//, 'notion://www.notion.so/');
const networkPath = path.startsWith('http') || path.startsWith('notion://');
if (networkPath) return fetch(path, opts).then((res) => res.text());
try { try {
const fs = globalThis.__enhancerElectronApi.nodeRequire('fs'); const fs = globalThis.__enhancerElectronApi.nodeRequire('fs');
return fs.readFileSync(notionPath(`notion-enhancer/${path}`)); return fs.readFileSync(notionPath(`notion-enhancer/${path}`));

@ -1 +1 @@
Subproject commit 33d70f998901cf1c9cbf857f68c1d2bf4d5c8ceb Subproject commit 5a039543b275503ee0df6a888390821dae9807b4