mirror of
https://github.com/jxpeng98/obsidian-to-NotionNext
synced 2026-07-29 16:35:57 +08:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1344c14933 | ||
|
|
c1f4ecd14b | ||
|
|
5942876c92 | ||
|
|
3218eb9fba | ||
|
|
48566eca20 | ||
|
|
8bd8346423 | ||
|
|
00411e9599 | ||
|
|
296125f6b4 | ||
|
|
1b385ccd0a | ||
|
|
a90e4871bb | ||
|
|
885ccba027 | ||
|
|
f282dde1b7 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -21,3 +21,6 @@ data.json
|
|||||||
# Exclude macOS Finder (System Explorer) View States
|
# Exclude macOS Finder (System Explorer) View States
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.history
|
.history
|
||||||
|
|
||||||
|
# local data
|
||||||
|
local-data
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
## Fix
|
## Fix
|
||||||
|
|
||||||
- Fix code block not being highlighted in Notion after syncing.
|
- Fix a bug that the plugin cannot read the title from the markdown front matter if using custom database.
|
||||||
- 修复代码块同步之后,在 Notion 中未高亮的问题。
|
- 修复当使用自定义数据库时,插件无法从markdown front matter中读取标题的问题。
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"id": "share-to-notionnext",
|
"id": "share-to-notionnext",
|
||||||
"name": "Share to NotionNext",
|
"name": "Share to NotionNext",
|
||||||
"version": "2.4.1",
|
"version": "2.4.3",
|
||||||
"minAppVersion": "0.0.1",
|
"minAppVersion": "0.0.1",
|
||||||
"description": "Shares obsidian md file to notion with notion api for NotionNext web deploy, originally created by EasyChris/obsidian-to-notion.",
|
"description": "Shares obsidian md file to notion with notion api for NotionNext web deploy, originally created by EasyChris/obsidian-to-notion.",
|
||||||
"author": "EasyChris, jxpeng98",
|
"author": "EasyChris, jxpeng98",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "share-to-notionnext",
|
"name": "share-to-notionnext",
|
||||||
"version": "2.4.1",
|
"version": "2.4.3",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"description": "Share files to any Notion database using the Notion API, originally created by EasyChris/obsidian-to-notion.",
|
"description": "Share files to any Notion database using the Notion API, originally created by EasyChris/obsidian-to-notion.",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
@@ -27,7 +27,6 @@
|
|||||||
"@jxpeng98/martian": "^1.2.7",
|
"@jxpeng98/martian": "^1.2.7",
|
||||||
"https-proxy-agent": "^7.0.2",
|
"https-proxy-agent": "^7.0.2",
|
||||||
"node-fetch": "^3.3.2",
|
"node-fetch": "^3.3.2",
|
||||||
"process": "^0.11.10",
|
|
||||||
"remark-math": "^6.0.0",
|
"remark-math": "^6.0.0",
|
||||||
"yaml": "^2.3.4",
|
"yaml": "^2.3.4",
|
||||||
"yaml-front-matter": "^4.1.1"
|
"yaml-front-matter": "^4.1.1"
|
||||||
|
|||||||
@@ -8,10 +8,42 @@ export const I18n: {[key: string]:any} = {
|
|||||||
ja,
|
ja,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const I18nConfig = (lang: string): any => {
|
class I18nManager {
|
||||||
return I18n[lang];
|
private currentLanguage: string;
|
||||||
};
|
|
||||||
|
|
||||||
const storedLanguage = window.localStorage.getItem("language");
|
constructor() {
|
||||||
|
this.currentLanguage = this.detectLanguage();
|
||||||
|
}
|
||||||
|
|
||||||
export const i18nConfig = I18n[storedLanguage || window.navigator.language.split('-')[0] || "en"];
|
// return the language to use
|
||||||
|
private detectLanguage(): string {
|
||||||
|
const storedLanguage = window.localStorage.getItem("language");
|
||||||
|
if (storedLanguage && this.isLanguageSupported(storedLanguage)) {
|
||||||
|
console.log(`Using stored language: ${storedLanguage}`);
|
||||||
|
return storedLanguage;
|
||||||
|
}
|
||||||
|
|
||||||
|
const browserLanguage = window.navigator.language.split("-")[0];
|
||||||
|
if (this.isLanguageSupported(browserLanguage)) {
|
||||||
|
console.log(`Using browser language: ${browserLanguage}`);
|
||||||
|
return browserLanguage;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default to English if no match is found
|
||||||
|
console.log("Using default language: en");
|
||||||
|
return "en";
|
||||||
|
}
|
||||||
|
|
||||||
|
private isLanguageSupported(lang: string): boolean {
|
||||||
|
return Object.prototype.hasOwnProperty.call(I18n, lang);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the i18n configuration for the current language
|
||||||
|
public getConfig(): any {
|
||||||
|
return I18n[this.currentLanguage];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const i18nManager = new I18nManager();
|
||||||
|
|
||||||
|
export const i18nConfig = i18nManager.getConfig();
|
||||||
|
|||||||
@@ -79,4 +79,5 @@ export const en = {
|
|||||||
BlockUploaded: "All blocks uploaded",
|
BlockUploaded: "All blocks uploaded",
|
||||||
ExtraBlockUploaded: "Extra blocks uploaded",
|
ExtraBlockUploaded: "Extra blocks uploaded",
|
||||||
CheckConsole: "Check the console for more information \n opt+cmd+i/ctrl+shift+i",
|
CheckConsole: "Check the console for more information \n opt+cmd+i/ctrl+shift+i",
|
||||||
|
"reach-mobile-limit": "The number of blocks exceeds the limit of 100, please use the desktop plugin",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
|
|||||||
|
|
||||||
addIcons();
|
addIcons();
|
||||||
// This creates an icon in the left ribbon.
|
// This creates an icon in the left ribbon.
|
||||||
const ribbonIconEl = this.addRibbonIcon(
|
this.addRibbonIcon(
|
||||||
"notion-logo",
|
"notion-logo",
|
||||||
i18nConfig.ribbonIcon,
|
i18nConfig.ribbonIcon,
|
||||||
async (evt: MouseEvent) => {
|
async (evt: MouseEvent) => {
|
||||||
|
|||||||
@@ -76,6 +76,9 @@ export async function uploadCommandGeneral(
|
|||||||
|
|
||||||
const {markDownData, nowFile, cover, tags} = await getNowFileMarkdownContentGeneral(app, settings)
|
const {markDownData, nowFile, cover, tags} = await getNowFileMarkdownContentGeneral(app, settings)
|
||||||
|
|
||||||
|
new Notice(`Start upload ${nowFile.basename}`);
|
||||||
|
console.log(`Start upload ${nowFile.basename}`);
|
||||||
|
|
||||||
if (markDownData) {
|
if (markDownData) {
|
||||||
const {basename} = nowFile;
|
const {basename} = nowFile;
|
||||||
|
|
||||||
@@ -111,6 +114,9 @@ export async function uploadCommandCustom(
|
|||||||
|
|
||||||
const {markDownData, nowFile, cover, customValues} = await getNowFileMarkdownContentCustom(app, dbDetails)
|
const {markDownData, nowFile, cover, customValues} = await getNowFileMarkdownContentCustom(app, dbDetails)
|
||||||
|
|
||||||
|
new Notice(`Start upload ${nowFile.basename}`);
|
||||||
|
console.log(`Start upload ${nowFile.basename}`);
|
||||||
|
|
||||||
if (markDownData) {
|
if (markDownData) {
|
||||||
const {basename} = nowFile;
|
const {basename} = nowFile;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import {App, Notice, TFile} from "obsidian";
|
import {App, Notice, TFile, Platform, requestUrl} from "obsidian";
|
||||||
import {Client} from "@notionhq/client";
|
|
||||||
import {markdownToBlocks} from "@jxpeng98/martian";
|
import {markdownToBlocks} from "@jxpeng98/martian";
|
||||||
import * as yamlFrontMatter from "yaml-front-matter";
|
import * as yamlFrontMatter from "yaml-front-matter";
|
||||||
// import * as yaml from "yaml"
|
|
||||||
import MyPlugin from "src/main";
|
import MyPlugin from "src/main";
|
||||||
import {DatabaseDetails, PluginSettings} from "../../ui/settingTabs";
|
import {DatabaseDetails, PluginSettings} from "../../ui/settingTabs";
|
||||||
import {UploadBaseGeneral} from "./BaseUpload2NotionGeneral";
|
import {UploadBaseGeneral} from "./BaseUpload2NotionGeneral";
|
||||||
@@ -10,6 +8,11 @@ import {updateYamlInfo} from "../updateYaml";
|
|||||||
import fetch from 'node-fetch';
|
import fetch from 'node-fetch';
|
||||||
import {i18nConfig} from "../../lang/I18n";
|
import {i18nConfig} from "../../lang/I18n";
|
||||||
|
|
||||||
|
interface CreatePageResponse {
|
||||||
|
response: any;
|
||||||
|
data: any;
|
||||||
|
}
|
||||||
|
|
||||||
export class Upload2NotionGeneral extends UploadBaseGeneral {
|
export class Upload2NotionGeneral extends UploadBaseGeneral {
|
||||||
settings: PluginSettings;
|
settings: PluginSettings;
|
||||||
dbDetails: DatabaseDetails;
|
dbDetails: DatabaseDetails;
|
||||||
@@ -48,7 +51,7 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
|||||||
cover: string,
|
cover: string,
|
||||||
tags: string[],
|
tags: string[],
|
||||||
childArr: any,
|
childArr: any,
|
||||||
) {
|
): Promise<CreatePageResponse> {
|
||||||
|
|
||||||
const {
|
const {
|
||||||
databaseID,
|
databaseID,
|
||||||
@@ -139,8 +142,32 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log(bodyString)
|
console.log(bodyString)
|
||||||
|
console.log(Platform.isDesktopApp)
|
||||||
|
|
||||||
const response = await fetch("https://api.notion.com/v1/pages", {
|
let response: any;
|
||||||
|
let data: any;
|
||||||
|
|
||||||
|
if (Platform.isMobileApp) {
|
||||||
|
if(childArrLength > 100) {
|
||||||
|
new Notice(i18nConfig["reach-mobile-limit"], 5000);
|
||||||
|
} else {
|
||||||
|
response = await requestUrl({
|
||||||
|
url: `https://api.notion.com/v1/pages`,
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
// 'User-Agent': 'obsidian.md',
|
||||||
|
Authorization:
|
||||||
|
"Bearer " + notionAPI,
|
||||||
|
"Notion-Version": "2022-06-28",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(bodyString),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Platform.isDesktopApp) {
|
||||||
|
response = await fetch("https://api.notion.com/v1/pages", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -150,10 +177,11 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
|||||||
body: JSON.stringify(bodyString),
|
body: JSON.stringify(bodyString),
|
||||||
});
|
});
|
||||||
|
|
||||||
const data: any = await response.json();
|
data = await response.json();
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
new Notice(`Error ${data.status}: ${data.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
|
new Notice(`Error ${data.status}: ${data.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
|
||||||
|
console.log(`Error message: \n ${data.message}`);
|
||||||
} else {
|
} else {
|
||||||
console.log(`Page created: ${data.url}`);
|
console.log(`Page created: ${data.url}`);
|
||||||
console.log(`Page ID: ${data.id}`);
|
console.log(`Page ID: ${data.id}`);
|
||||||
@@ -192,10 +220,11 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
response, // for status code
|
response,
|
||||||
data // for id and url
|
data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,11 +245,11 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
|||||||
const yamlContent: any = yamlFrontMatter.loadFront(markdown);
|
const yamlContent: any = yamlFrontMatter.loadFront(markdown);
|
||||||
const __content = yamlContent.__content;
|
const __content = yamlContent.__content;
|
||||||
const file2Block = markdownToBlocks(__content, options);
|
const file2Block = markdownToBlocks(__content, options);
|
||||||
const frontmasster =
|
const frontMatter =
|
||||||
app.metadataCache.getFileCache(nowFile)?.frontmatter;
|
app.metadataCache.getFileCache(nowFile)?.frontmatter;
|
||||||
const {abName} = this.dbDetails
|
const {abName} = this.dbDetails
|
||||||
const notionIDKey = `NotionID-${abName}`;
|
const notionIDKey = `NotionID-${abName}`;
|
||||||
const notionID = frontmasster ? frontmasster[notionIDKey] : null;
|
const notionID = frontMatter ? frontMatter[notionIDKey] : null;
|
||||||
|
|
||||||
|
|
||||||
if (notionID) {
|
if (notionID) {
|
||||||
@@ -237,10 +266,30 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
|||||||
|
|
||||||
let {response, data} = res;
|
let {response, data} = res;
|
||||||
|
|
||||||
// console.log(response)
|
if (Platform.isDesktopApp) {
|
||||||
|
|
||||||
if (response && response.status === 200) {
|
if (response && response.status === 200) {
|
||||||
await updateYamlInfo(markdown, nowFile, data, app, this.plugin, this.dbDetails);
|
await updateYamlInfo(
|
||||||
|
markdown,
|
||||||
|
nowFile,
|
||||||
|
data,
|
||||||
|
app,
|
||||||
|
this.plugin,
|
||||||
|
this.dbDetails
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Platform.isMobileApp) {
|
||||||
|
if (response && response.status === 200) {
|
||||||
|
await updateYamlInfo(
|
||||||
|
markdown,
|
||||||
|
nowFile,
|
||||||
|
response,
|
||||||
|
app,
|
||||||
|
this.plugin,
|
||||||
|
this.dbDetails,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
import {UploadBaseNext} from "./BaseUpload2NotionNext";
|
import {UploadBaseNext} from "./BaseUpload2NotionNext";
|
||||||
import {App, Notice, TFile} from "obsidian";
|
import {App, Notice, TFile, Platform, requestUrl} from "obsidian";
|
||||||
import {Client} from "@notionhq/client";
|
|
||||||
import {markdownToBlocks} from "@jxpeng98/martian";
|
import {markdownToBlocks} from "@jxpeng98/martian";
|
||||||
import * as yamlFrontMatter from "yaml-front-matter";
|
import * as yamlFrontMatter from "yaml-front-matter";
|
||||||
// import * as yaml from "yaml"
|
|
||||||
import MyPlugin from "src/main";
|
import MyPlugin from "src/main";
|
||||||
import {DatabaseDetails, PluginSettings} from "../../ui/settingTabs";
|
import {DatabaseDetails, PluginSettings} from "../../ui/settingTabs";
|
||||||
import {updateYamlInfo} from "../updateYaml";
|
import {updateYamlInfo} from "../updateYaml";
|
||||||
import {LIMITS, paragraph} from "@jxpeng98/martian/src/notion";
|
import {LIMITS, paragraph} from "@jxpeng98/martian/src/notion";
|
||||||
import fetch from "node-fetch";
|
import fetch from 'node-fetch';
|
||||||
import {i18nConfig} from "../../lang/I18n";
|
import {i18nConfig} from "../../lang/I18n";
|
||||||
|
|
||||||
|
interface CreatePageResponse {
|
||||||
|
response: any;
|
||||||
|
data: any;
|
||||||
|
}
|
||||||
|
|
||||||
export class Upload2NotionNext extends UploadBaseNext {
|
export class Upload2NotionNext extends UploadBaseNext {
|
||||||
settings: PluginSettings;
|
settings: PluginSettings;
|
||||||
dbDetails: DatabaseDetails;
|
dbDetails: DatabaseDetails;
|
||||||
@@ -79,7 +82,7 @@ export class Upload2NotionNext extends UploadBaseNext {
|
|||||||
favicon: string,
|
favicon: string,
|
||||||
datetime: string,
|
datetime: string,
|
||||||
childArr: any,
|
childArr: any,
|
||||||
) {
|
): Promise<CreatePageResponse> {
|
||||||
const {databaseID, notionAPI} = this.dbDetails;
|
const {databaseID, notionAPI} = this.dbDetails;
|
||||||
|
|
||||||
// remove the annotations from the childArr if type is code block
|
// remove the annotations from the childArr if type is code block
|
||||||
@@ -241,19 +244,41 @@ export class Upload2NotionNext extends UploadBaseNext {
|
|||||||
|
|
||||||
console.log(bodyString);
|
console.log(bodyString);
|
||||||
|
|
||||||
const response = await fetch("https://api.notion.com/v1/pages", {
|
let response: any;
|
||||||
|
let data: any;
|
||||||
|
|
||||||
|
if (Platform.isMobileApp) {
|
||||||
|
if(childArrLength > 100) {
|
||||||
|
new Notice(i18nConfig["reach-mobile-limit"], 5000);
|
||||||
|
} else {
|
||||||
|
response = await requestUrl({
|
||||||
|
url: `https://api.notion.com/v1/pages`,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: "Bearer " + notionAPI,
|
// 'User-Agent': 'obsidian.md',
|
||||||
|
Authorization:
|
||||||
|
"Bearer " + notionAPI,
|
||||||
|
"Notion-Version": "2022-06-28",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(bodyString),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Platform.isDesktopApp) {
|
||||||
|
response = await fetch("https://api.notion.com/v1/pages", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": "Bearer " + notionAPI,
|
||||||
"Notion-Version": "2022-06-28",
|
"Notion-Version": "2022-06-28",
|
||||||
},
|
},
|
||||||
body: JSON.stringify(bodyString),
|
body: JSON.stringify(bodyString),
|
||||||
});
|
});
|
||||||
|
|
||||||
const data: any = await response.json();
|
data = await response.json();
|
||||||
|
|
||||||
// can use response.ok or response.status === 200
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
new Notice(`Error ${data.status}: ${data.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
|
new Notice(`Error ${data.status}: ${data.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
|
||||||
console.log(`Error message: \n ${data.message}`);
|
console.log(`Error message: \n ${data.message}`);
|
||||||
@@ -262,18 +287,16 @@ export class Upload2NotionNext extends UploadBaseNext {
|
|||||||
console.log(`Page ID: ${data.id}`);
|
console.log(`Page ID: ${data.id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the childArr is over 100, patch the rest of the blocks append to the page
|
// upload the rest of the blocks
|
||||||
if (pushCount > 0) {
|
if (pushCount > 0) {
|
||||||
for (let i = 0; i < pushCount; i++) {
|
for (let i = 0; i < pushCount; i++) {
|
||||||
const extraBlocks = {
|
const extraBlocks = {
|
||||||
children: extraArr[i]
|
children: extraArr[i],
|
||||||
}
|
};
|
||||||
|
|
||||||
console.log(extraBlocks)
|
console.log(extraBlocks)
|
||||||
|
|
||||||
const extraResponse = await fetch(
|
const extraResponse = await fetch(`https://api.notion.com/v1/blocks/${data.id}/children`, {
|
||||||
`https://api.notion.com/v1/blocks/${data.id}/children`,
|
|
||||||
{
|
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -286,10 +309,7 @@ export class Upload2NotionNext extends UploadBaseNext {
|
|||||||
const extraData: any = await extraResponse.json();
|
const extraData: any = await extraResponse.json();
|
||||||
|
|
||||||
if (!extraResponse.ok) {
|
if (!extraResponse.ok) {
|
||||||
new Notice(
|
new Notice(`Error ${extraData.status}: ${extraData.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
|
||||||
`Extra Block: Error ${extraData.status}: ${extraData.code} \n ${i18nConfig["CheckConsole"]}`,
|
|
||||||
5000,
|
|
||||||
);
|
|
||||||
console.log(`Error message: \n ${extraData.message}`);
|
console.log(`Error message: \n ${extraData.message}`);
|
||||||
} else {
|
} else {
|
||||||
console.log(`${i18nConfig["ExtraBlockUploaded"]} to page: ${data.id}`);
|
console.log(`${i18nConfig["ExtraBlockUploaded"]} to page: ${data.id}`);
|
||||||
@@ -300,10 +320,11 @@ export class Upload2NotionNext extends UploadBaseNext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
response, // for status code
|
response,
|
||||||
data, // for id and url
|
data
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -395,6 +416,7 @@ export class Upload2NotionNext extends UploadBaseNext {
|
|||||||
|
|
||||||
let {response, data} = res;
|
let {response, data} = res;
|
||||||
|
|
||||||
|
if (Platform.isDesktopApp) {
|
||||||
if (response && response.status === 200) {
|
if (response && response.status === 200) {
|
||||||
await updateYamlInfo(
|
await updateYamlInfo(
|
||||||
markdown,
|
markdown,
|
||||||
@@ -402,9 +424,23 @@ export class Upload2NotionNext extends UploadBaseNext {
|
|||||||
data,
|
data,
|
||||||
app,
|
app,
|
||||||
this.plugin,
|
this.plugin,
|
||||||
|
this.dbDetails
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Platform.isMobileApp) {
|
||||||
|
if (response && response.status === 200) {
|
||||||
|
await updateYamlInfo(
|
||||||
|
markdown,
|
||||||
|
nowFile,
|
||||||
|
response,
|
||||||
|
app,
|
||||||
|
this.plugin,
|
||||||
this.dbDetails,
|
this.dbDetails,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import {App, Notice, TFile} from "obsidian";
|
import {App, Notice, Platform, TFile, requestUrl} from "obsidian";
|
||||||
import {markdownToBlocks} from "@jxpeng98/martian";
|
import {markdownToBlocks} from "@jxpeng98/martian";
|
||||||
import * as yamlFrontMatter from "yaml-front-matter";
|
import * as yamlFrontMatter from "yaml-front-matter";
|
||||||
// import * as yaml from "yaml"
|
|
||||||
import MyPlugin from "src/main";
|
import MyPlugin from "src/main";
|
||||||
import {DatabaseDetails, PluginSettings} from "../../ui/settingTabs";
|
import {DatabaseDetails, PluginSettings} from "../../ui/settingTabs";
|
||||||
import {updateYamlInfo} from "../updateYaml";
|
import {updateYamlInfo} from "../updateYaml";
|
||||||
@@ -10,6 +9,11 @@ import fetch from 'node-fetch';
|
|||||||
import {i18nConfig} from "../../lang/I18n";
|
import {i18nConfig} from "../../lang/I18n";
|
||||||
|
|
||||||
|
|
||||||
|
interface CreatePageResponse {
|
||||||
|
response: any;
|
||||||
|
data: any;
|
||||||
|
}
|
||||||
|
|
||||||
export class Upload2NotionCustom extends UploadBaseCustom {
|
export class Upload2NotionCustom extends UploadBaseCustom {
|
||||||
settings: PluginSettings;
|
settings: PluginSettings;
|
||||||
dbDetails: DatabaseDetails;
|
dbDetails: DatabaseDetails;
|
||||||
@@ -46,7 +50,7 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
cover: string,
|
cover: string,
|
||||||
customValues: Record<string, string>,
|
customValues: Record<string, string>,
|
||||||
childArr: any,
|
childArr: any,
|
||||||
) {
|
): Promise<CreatePageResponse> {
|
||||||
|
|
||||||
const {
|
const {
|
||||||
databaseID,
|
databaseID,
|
||||||
@@ -110,8 +114,32 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log(bodyString)
|
console.log(bodyString)
|
||||||
|
console.log(Platform.isDesktopApp)
|
||||||
|
|
||||||
const response = await fetch("https://api.notion.com/v1/pages", {
|
let response: any;
|
||||||
|
let data: any;
|
||||||
|
|
||||||
|
if (Platform.isMobileApp) {
|
||||||
|
if(childArrLength > 100) {
|
||||||
|
new Notice(i18nConfig["reach-mobile-limit"], 5000);
|
||||||
|
} else {
|
||||||
|
response = await requestUrl({
|
||||||
|
url: `https://api.notion.com/v1/pages`,
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
// 'User-Agent': 'obsidian.md',
|
||||||
|
Authorization:
|
||||||
|
"Bearer " + notionAPI,
|
||||||
|
"Notion-Version": "2022-06-28",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(bodyString),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Platform.isDesktopApp) {
|
||||||
|
response = await fetch("https://api.notion.com/v1/pages", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -121,7 +149,7 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
body: JSON.stringify(bodyString),
|
body: JSON.stringify(bodyString),
|
||||||
});
|
});
|
||||||
|
|
||||||
const data: any = await response.json();
|
data = await response.json();
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
new Notice(`Error ${data.status}: ${data.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
|
new Notice(`Error ${data.status}: ${data.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
|
||||||
@@ -164,6 +192,7 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
response, // for status code
|
response, // for status code
|
||||||
@@ -209,8 +238,30 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
|
|
||||||
// console.log(response)
|
// console.log(response)
|
||||||
|
|
||||||
|
if (Platform.isDesktopApp) {
|
||||||
if (response && response.status === 200) {
|
if (response && response.status === 200) {
|
||||||
await updateYamlInfo(markdown, nowFile, data, app, this.plugin, this.dbDetails);
|
await updateYamlInfo(
|
||||||
|
markdown,
|
||||||
|
nowFile,
|
||||||
|
data,
|
||||||
|
app,
|
||||||
|
this.plugin,
|
||||||
|
this.dbDetails
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Platform.isMobileApp) {
|
||||||
|
if (response && response.status === 200) {
|
||||||
|
await updateYamlInfo(
|
||||||
|
markdown,
|
||||||
|
nowFile,
|
||||||
|
response,
|
||||||
|
app,
|
||||||
|
this.plugin,
|
||||||
|
this.dbDetails,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
@@ -35,7 +35,10 @@ export async function getNowFileMarkdownContentCustom(
|
|||||||
|
|
||||||
// If a 'title' type property exists, use the file's basename as its value
|
// If a 'title' type property exists, use the file's basename as its value
|
||||||
if (titleProperty) {
|
if (titleProperty) {
|
||||||
customValues[titleProperty.customName] = nowFile.basename; // Use 'basename' for the file name without extension
|
customValues[titleProperty.customName] =
|
||||||
|
(FileCache.frontmatter && FileCache.frontmatter[titleProperty.customName]) ?
|
||||||
|
FileCache.frontmatter[titleProperty.customName] : // use the front matter value if it exists
|
||||||
|
nowFile.basename; // Use 'basename' for the file name without extension
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -1245,11 +1245,6 @@ picomatch@^2.3.1:
|
|||||||
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42"
|
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42"
|
||||||
integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==
|
integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==
|
||||||
|
|
||||||
process@^0.11.10:
|
|
||||||
version "0.11.10"
|
|
||||||
resolved "https://registry.yarnpkg.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182"
|
|
||||||
integrity sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==
|
|
||||||
|
|
||||||
queue-microtask@^1.2.2:
|
queue-microtask@^1.2.2:
|
||||||
version "1.2.3"
|
version "1.2.3"
|
||||||
resolved "https://registry.yarnpkg.com/queue-microtask/-/queue-microtask-1.2.3.tgz#4929228bbc724dfac43e0efb058caf7b6cfb6243"
|
resolved "https://registry.yarnpkg.com/queue-microtask/-/queue-microtask-1.2.3.tgz#4929228bbc724dfac43e0efb058caf7b6cfb6243"
|
||||||
|
|||||||
Reference in New Issue
Block a user