From 0e322fd955493a2424764a11370de23bac35027e Mon Sep 17 00:00:00 2001 From: Mara Date: Sun, 27 Nov 2022 06:53:24 +0100 Subject: [PATCH] fix: attemp to fix multiple added status bar fix #45 --- plugin/commands.ts | 10 +++++----- plugin/publishing/upload.ts | 35 +++++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/plugin/commands.ts b/plugin/commands.ts index 20e505a6..b8d16c37 100644 --- a/plugin/commands.ts +++ b/plugin/commands.ts @@ -21,11 +21,11 @@ export async function shareAllMarkedNotes(PublisherManager: GithubBranch, settin * @param sharedFiles File marked to true * @param createGitHubBranch prevent to multiple creation of branch if already exists */ + const statusBar = new ShareStatusBar( + statusBarItems, + sharedFiles.length + ); try { - const statusBar = new ShareStatusBar( - statusBarItems, - sharedFiles.length - ); let errorCount = 0; if (sharedFiles.length > 0) { const publishedFiles = sharedFiles.map( @@ -55,7 +55,6 @@ export async function shareAllMarkedNotes(PublisherManager: GithubBranch, settin await noticeMessage(PublisherManager, noticeValue, settings, repoFrontmatter); } else { new Notice((t("errorPublish") as StringFunc)(settings.githubRepo)); - } } } catch (error) { @@ -63,6 +62,7 @@ export async function shareAllMarkedNotes(PublisherManager: GithubBranch, settin new Notice( t("unablePublishMultiNotes") as string ); + statusBar.error(); } } diff --git a/plugin/publishing/upload.ts b/plugin/publishing/upload.ts index dbc5910e..ef64f5de 100644 --- a/plugin/publishing/upload.ts +++ b/plugin/publishing/upload.ts @@ -10,7 +10,7 @@ import { FilesManagement } from "./filesManagement"; import { Octokit } from "@octokit/core"; import { Base64 } from "js-base64"; import {deleteFromGithub} from "./delete" - +import t, {StringFunc} from "../i18n"; import { @@ -54,18 +54,29 @@ export default class Publisher { if (linkedFiles.length> 1) { const statusBarItems = this.plugin.addStatusBarItem(); const statusBar = new ShareStatusBar(statusBarItems, linkedFiles.length, true); - for (const image of linkedFiles) { - if (!fileHistory.includes(image)) { - if ((image.extension === 'md') && deepScan) { - await this.publish(image, false, ref, repoFrontmatter, fileHistory, true); - } else if (isAttachment(image.extension) && sourceFrontmatter.attachment) { - await this.uploadImage(image, ref, sourceFrontmatter, repoFrontmatter); - fileHistory.push(image); + try { + for (const image of linkedFiles) { + try { + if (!fileHistory.includes(image)) { + if ((image.extension === 'md') && deepScan) { + await this.publish(image, false, ref, repoFrontmatter, fileHistory, true); + } else if (isAttachment(image.extension) && sourceFrontmatter.attachment) { + await this.uploadImage(image, ref, sourceFrontmatter, repoFrontmatter); + fileHistory.push(image); + } + } + statusBar.increment(); + } catch (e) { + new Notice((t("unablePublishNote") as StringFunc)(image.name)); + console.error(e); } } - statusBar.increment(); + statusBar.finish(8000); + } catch (e) { + noticeLog(e, this.settings); + new Notice((t('errorPublish') as StringFunc)(repoFrontmatter.repo)); + statusBar.error(); } - statusBar.finish(8000); } else { // 1 one item to send const embed = linkedFiles[0]; if (!fileHistory.includes(embed)) { @@ -105,7 +116,7 @@ export default class Publisher { return false; } try { - console.log("Publishing file: " + file.path); + noticeLog("Publishing file: " + file.path, this.settings); fileHistory.push(file) const frontmatterSettings = getFrontmatterCondition(frontmatter, this.settings); let embedFiles = shareFiles.getSharedEmbed(file, frontmatterSettings); @@ -117,7 +128,7 @@ export default class Publisher { const path = getReceiptFolder(file, this.settings, this.metadataCache, this.vault) //if repoFrontmatter is an array, it means that the file is in a multiple repo if (repoFrontmatter instanceof Array) { - console.log("Multiple repo", repoFrontmatter) + noticeLog("Multiple repo" + repoFrontmatter, this.settings) const success: boolean[] = []; for (const repo of repoFrontmatter) { success.push(await this.uploadMultiple(file, text, ref, frontmatterSettings, path, repo, embedFiles, fileHistory, deepScan, shareFiles, autoclean));