diff --git a/src/GitHub/branch.ts b/src/GitHub/branch.ts index e31756e0..fa4cc7da 100644 --- a/src/GitHub/branch.ts +++ b/src/GitHub/branch.ts @@ -24,15 +24,13 @@ export class GithubBranch extends FilesManagement { await this.newBranchOnRepo(repo); } } - + private async findMainBranch(prop: Properties) { const allBranch = await this.octokit.request("GET /repos/{owner}/{repo}/branches", { owner: prop.owner, repo: prop.repo, }); - return allBranch.data.find( - (branch: { name: string }) => branch.name === prop.branch - ); + return allBranch.data.find((branch: { name: string }) => branch.name === prop.branch); } /** @@ -258,17 +256,21 @@ export class GithubBranch extends FilesManagement { this.console.info( i18next.t("commands.checkValidity.repoExistsTestBranch", { repo }) ); - + const branchExist = await this.findMainBranch(repo); if (!branchExist) { - const errorMsg = i18next.t("commands.checkValidity.inBranch.error404", {repo}); + const errorMsg = i18next.t("commands.checkValidity.inBranch.error404", { + repo, + }); this.console.fatal(errorMsg); - + break; } this.console.info(i18next.t("commands.checkValidity.success", {repo})); if (!silent) { - this.console.noticeSuccess(i18next.t("commands.checkValidity.success", {repo})); + this.console.noticeSuccess( + i18next.t("commands.checkValidity.success", {repo}) + ); } } } catch (e) { diff --git a/src/GitHub/files.ts b/src/GitHub/files.ts index 81d7f53e..0e53533a 100644 --- a/src/GitHub/files.ts +++ b/src/GitHub/files.ts @@ -606,4 +606,32 @@ export class FilesManagement extends Publisher { } return newFiles; } + + async wasEditedSinceLastSync( + file: TFile, + repo: Repository | null, + repoPath: string + ): Promise { + //first check if the file exist in github + if (this.settings.embed.forcePush || this.settings.embed.forcePush == null) + return true; + const githubFile = await this.octokit.request("GET /repos/{owner}/{repo}/commits", { + owner: repo?.user ?? this.settings.github.user, + repo: repo?.repo ?? this.settings.github.repo, + path: repoPath, + }); + if (githubFile.status !== 200) return true; //doesn't exists + const vaultEditedTime = new Date(file.stat.mtime); + const lastCommittedFile = githubFile.data[0]; + if ( + !lastCommittedFile || + !lastCommittedFile.commit || + !lastCommittedFile.commit.committer || + !lastCommittedFile.commit.committer.date + ) { + return true; + } + const githubDate = new Date(lastCommittedFile.commit.committer.date); + return vaultEditedTime > githubDate; + } } diff --git a/src/GitHub/upload.ts b/src/GitHub/upload.ts index 2232fa7d..6ddda5ff 100644 --- a/src/GitHub/upload.ts +++ b/src/GitHub/upload.ts @@ -173,7 +173,23 @@ export default class Publisher { ) { const shareFiles = new FilesManagement(this.octokit, this.plugin); let frontmatter = frontmatterFromFile(file, this.plugin, null); + const filePath = getReceiptFolder( + file, + repo.repository, + this.plugin, + repo.frontmatter + ); if (!isShared(frontmatter, this.settings, file, repo.repository)) return false; + if (!(await shareFiles.wasEditedSinceLastSync(file, repo.repository, filePath))) { + const msg = i18next.t("publish.upToDate", { + file: file.name, + repo: `${repo.repository?.user ?? this.settings.github.user}/${ + repo.repository?.repo ?? this.settings.github.repo + }:${repo.repository?.branch ?? this.branchName}`, + }); + new Notice(msg); + return false; + } frontmatter = mergeFrontmatter( frontmatter, sourceFrontmatter, @@ -182,6 +198,7 @@ export default class Publisher { const prop = getProperties(this.plugin, repo.repository, frontmatter); const isNotEmpty = await checkEmptyConfiguration(prop, this.plugin); repo.frontmatter = prop; + if ( fileHistory.includes(file) || !checkIfRepoIsInAnother(prop, repo.frontmatter) || @@ -207,15 +224,6 @@ export default class Publisher { frontmatterRepository, frontmatterSettingsFromFile ); - let embedFiles = shareFiles.getSharedEmbed(file, frontmatterSettings); - embedFiles = await shareFiles.getMetadataLinks( - file, - embedFiles, - frontmatterSettings - ); - const linkedFiles = shareFiles.getLinkedByEmbedding(file); - - let text = await this.vault.cachedRead(file); const multiProperties: MultiProperties = { plugin: this.plugin, frontmatter: { @@ -223,8 +231,17 @@ export default class Publisher { prop: repo.frontmatter, }, repository: repo.repository, - filepath: getReceiptFolder(file, repo.repository, this.plugin, repo.frontmatter), + filepath: filePath, }; + + let embedFiles = shareFiles.getSharedEmbed(file, frontmatterSettings); + embedFiles = await shareFiles.getMetadataLinks( + file, + embedFiles, + frontmatterSettings + ); + const linkedFiles = shareFiles.getLinkedByEmbedding(file); + let text = await this.vault.cachedRead(file); text = await mainConverting(text, file, frontmatter, linkedFiles, multiProperties); const path = multiProperties.filepath; const prop = Array.isArray(repo.frontmatter) diff --git a/src/i18n/locales b/src/i18n/locales index b2d50b05..a5114995 160000 --- a/src/i18n/locales +++ b/src/i18n/locales @@ -1 +1 @@ -Subproject commit b2d50b05bf75ccf8b70525718924806c70f02dee +Subproject commit a5114995a99dc940a20b770289c37029bc915162 diff --git a/src/interfaces/constant.ts b/src/interfaces/constant.ts index 07b1690d..33932b1d 100644 --- a/src/interfaces/constant.ts +++ b/src/interfaces/constant.ts @@ -87,7 +87,6 @@ export const DEFAULT_SETTINGS: Partial = { unHandledObsidianExt: [], sendSimpleLinks: true, forcePush: true, - }, plugin: { shareKey: "share", diff --git a/src/settings.ts b/src/settings.ts index 89acc0bc..27bad5aa 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -1026,7 +1026,6 @@ export class EnveloppeSettingsTab extends PluginSettingTab { }); }); - if (embedSettings.notes) { new Setting(this.settingsPage) .setName(i18next.t("settings.embed.links.title")) diff --git a/src/utils/logs.ts b/src/utils/logs.ts index 7bdcfa8d..9b876043 100644 --- a/src/utils/logs.ts +++ b/src/utils/logs.ts @@ -47,12 +47,12 @@ export class Logs { this.logger.debug(...messages); this.notif(messages); } - + trace(...messages: unknown[]) { this.logger.trace(...messages); this.notif(messages); } - + silly(...messages: unknown[]) { this.logger.silly(...messages); this.notif(messages); @@ -132,7 +132,7 @@ export class Logs { cls: ["error", "enveloppe", "icons", "notification"], }); const html = sanitizeHTMLToDom(message); - setIcon(notifSpan, "mail-question"); + setIcon(notifSpan, "alert-triangle"); notif .createSpan({ cls: ["error", "enveloppe", "notification"],