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;
|
||||
nowFile: TFile;
|
||||
app: App;
|
||||
isAutoSync?: boolean;
|
||||
}
|
||||
|
||||
interface GeneralSyncRequest extends BaseSyncRequest {
|
||||
@@ -91,6 +92,7 @@ export class Upload2Notion extends UploadBase {
|
||||
|
||||
async sync(request: SyncRequest): Promise<NotionPageResponse> {
|
||||
const startedAt = Date.now();
|
||||
this.isAutoSync = !!request.isAutoSync;
|
||||
|
||||
let response: NotionPageResponse;
|
||||
|
||||
|
||||
@@ -18,12 +18,20 @@ interface PreparedBlocks {
|
||||
export abstract class UploadBase {
|
||||
protected plugin: MyPlugin;
|
||||
protected dbDetails: DatabaseDetails;
|
||||
protected isAutoSync = false;
|
||||
|
||||
protected constructor(plugin: MyPlugin, dbDetails: DatabaseDetails) {
|
||||
this.plugin = plugin;
|
||||
this.dbDetails = dbDetails;
|
||||
}
|
||||
|
||||
private shouldShowSuccessNotices(): boolean {
|
||||
if (!this.isAutoSync) {
|
||||
return true;
|
||||
}
|
||||
return !!this.plugin.settings.autoSyncSuccessNotice;
|
||||
}
|
||||
|
||||
async deletePage(notionID: string) {
|
||||
const {notionAPI} = this.dbDetails;
|
||||
return requestUrl({
|
||||
@@ -190,7 +198,9 @@ export abstract class UploadBase {
|
||||
console.log(`${i18nConfig["ExtraBlockUploaded"]} to page: ${pageId}`);
|
||||
if (i === extraChunks.length - 1) {
|
||||
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 {
|
||||
res = await upload.sync({
|
||||
dataset: "next",
|
||||
isAutoSync: options?.isAutoSync,
|
||||
title: basename,
|
||||
emoji: emoji || "",
|
||||
cover: cover || "",
|
||||
@@ -197,6 +198,7 @@ export async function uploadCommandGeneral(
|
||||
try {
|
||||
res = await upload.sync({
|
||||
dataset: "general",
|
||||
isAutoSync: options?.isAutoSync,
|
||||
title: basename,
|
||||
cover: cover || "",
|
||||
tags: tags || [],
|
||||
@@ -279,6 +281,7 @@ export async function uploadCommandCustom(
|
||||
try {
|
||||
res = await upload.sync({
|
||||
dataset: "custom",
|
||||
isAutoSync: options?.isAutoSync,
|
||||
cover: cover || "",
|
||||
customValues,
|
||||
markdown: markDownData,
|
||||
|
||||
Reference in New Issue
Block a user