feat: Add isAutoSync option to sync requests and update success notice logic

This commit is contained in:
Jiaxin Peng
2026-03-04 09:14:38 +00:00
parent 3e00f127e9
commit cd7eb78378
3 changed files with 16 additions and 1 deletions

View File

@@ -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;

View File

@@ -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);
}
}
}
}

View File

@@ -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,