mirror of
https://github.com/jxpeng98/obsidian-to-NotionNext
synced 2026-07-29 08:08:34 +08:00
feat: Add isAutoSync option to sync requests and update success notice logic
This commit is contained in:
@@ -15,6 +15,7 @@ interface BaseSyncRequest {
|
|||||||
markdown: string;
|
markdown: string;
|
||||||
nowFile: TFile;
|
nowFile: TFile;
|
||||||
app: App;
|
app: App;
|
||||||
|
isAutoSync?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface GeneralSyncRequest extends BaseSyncRequest {
|
interface GeneralSyncRequest extends BaseSyncRequest {
|
||||||
@@ -91,6 +92,7 @@ export class Upload2Notion extends UploadBase {
|
|||||||
|
|
||||||
async sync(request: SyncRequest): Promise<NotionPageResponse> {
|
async sync(request: SyncRequest): Promise<NotionPageResponse> {
|
||||||
const startedAt = Date.now();
|
const startedAt = Date.now();
|
||||||
|
this.isAutoSync = !!request.isAutoSync;
|
||||||
|
|
||||||
let response: NotionPageResponse;
|
let response: NotionPageResponse;
|
||||||
|
|
||||||
|
|||||||
@@ -18,12 +18,20 @@ interface PreparedBlocks {
|
|||||||
export abstract class UploadBase {
|
export abstract class UploadBase {
|
||||||
protected plugin: MyPlugin;
|
protected plugin: MyPlugin;
|
||||||
protected dbDetails: DatabaseDetails;
|
protected dbDetails: DatabaseDetails;
|
||||||
|
protected isAutoSync = false;
|
||||||
|
|
||||||
protected constructor(plugin: MyPlugin, dbDetails: DatabaseDetails) {
|
protected constructor(plugin: MyPlugin, dbDetails: DatabaseDetails) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.dbDetails = dbDetails;
|
this.dbDetails = dbDetails;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private shouldShowSuccessNotices(): boolean {
|
||||||
|
if (!this.isAutoSync) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return !!this.plugin.settings.autoSyncSuccessNotice;
|
||||||
|
}
|
||||||
|
|
||||||
async deletePage(notionID: string) {
|
async deletePage(notionID: string) {
|
||||||
const {notionAPI} = this.dbDetails;
|
const {notionAPI} = this.dbDetails;
|
||||||
return requestUrl({
|
return requestUrl({
|
||||||
@@ -190,7 +198,9 @@ export abstract class UploadBase {
|
|||||||
console.log(`${i18nConfig["ExtraBlockUploaded"]} to page: ${pageId}`);
|
console.log(`${i18nConfig["ExtraBlockUploaded"]} to page: ${pageId}`);
|
||||||
if (i === extraChunks.length - 1) {
|
if (i === extraChunks.length - 1) {
|
||||||
console.log(`${i18nConfig["BlockUploaded"]} to page: ${pageId}`);
|
console.log(`${i18nConfig["BlockUploaded"]} to page: ${pageId}`);
|
||||||
new Notice(`${i18nConfig["BlockUploaded"]} page: ${pageId}`, 5000);
|
if (this.shouldShowSuccessNotices()) {
|
||||||
|
new Notice(`${i18nConfig["BlockUploaded"]} page: ${pageId}`, 5000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ export async function uploadCommandNext(
|
|||||||
try {
|
try {
|
||||||
res = await upload.sync({
|
res = await upload.sync({
|
||||||
dataset: "next",
|
dataset: "next",
|
||||||
|
isAutoSync: options?.isAutoSync,
|
||||||
title: basename,
|
title: basename,
|
||||||
emoji: emoji || "",
|
emoji: emoji || "",
|
||||||
cover: cover || "",
|
cover: cover || "",
|
||||||
@@ -197,6 +198,7 @@ export async function uploadCommandGeneral(
|
|||||||
try {
|
try {
|
||||||
res = await upload.sync({
|
res = await upload.sync({
|
||||||
dataset: "general",
|
dataset: "general",
|
||||||
|
isAutoSync: options?.isAutoSync,
|
||||||
title: basename,
|
title: basename,
|
||||||
cover: cover || "",
|
cover: cover || "",
|
||||||
tags: tags || [],
|
tags: tags || [],
|
||||||
@@ -279,6 +281,7 @@ export async function uploadCommandCustom(
|
|||||||
try {
|
try {
|
||||||
res = await upload.sync({
|
res = await upload.sync({
|
||||||
dataset: "custom",
|
dataset: "custom",
|
||||||
|
isAutoSync: options?.isAutoSync,
|
||||||
cover: cover || "",
|
cover: cover || "",
|
||||||
customValues,
|
customValues,
|
||||||
markdown: markDownData,
|
markdown: markDownData,
|
||||||
|
|||||||
Reference in New Issue
Block a user