Skip to content

Commit

Permalink
fix(attachment): allow force push attachment with extension
Browse files Browse the repository at this point in the history
in my case, pdf can be edited a lot, so i prefer to always force push them

I can't compare the content of the file because they can be edited externally (ie with github actions)
  • Loading branch information
Mara-Li committed Sep 28, 2023
1 parent 96d4780 commit 773270c
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 50 deletions.
7 changes: 5 additions & 2 deletions src/GitHub/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
import {
checkEmptyConfiguration,
checkIfRepoIsInAnother,
forcePushAttachment,
isAttachment,
isShared,
} from "../utils/data_validation_test";
Expand Down Expand Up @@ -581,15 +582,17 @@ export default class Publisher {
);
const repoFrontmatter = properties.frontmatter;
try {
const { status } = await this.octokit.request(
const {status} = await this.octokit.request(
"GET /repos/{owner}/{repo}/contents/{path}",
{
owner: repoFrontmatter.repo.owner,
repo: repoFrontmatter.repo.repo,
path: imagePath,
});
if (status === 200) {
notif({ settings: this.settings }, i18next.t("error.alreadyExists", { file: file.name }));
if (forcePushAttachment(file, properties.settings)) {
newLinkedFiles.push(file);
} else notif({ settings: this.settings }, i18next.t("error.alreadyExists", { file: file.name }));
continue;
}
} catch (e) {
Expand Down
7 changes: 7 additions & 0 deletions src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
"title": "Text & links"
},
"embed": {
"attachment": "Attachments",
"bake": {
"text": "Allow you to add text before and after each embed, for example adding HTML or stylize the block with markdown.",
"textAfter": {
Expand All @@ -230,6 +231,11 @@
"desc": "To use a folder different from default",
"title": "Default attachment folder"
},
"forcePush": {
"desc": "The following extensions will always be sent to the repository, even if they already exist there. \nSeparate extensions with a comma.",
"infoAboutAttachments": "Normally, attachments are only sent if it does not exist on the repository.",
"title": "Force push attachments"
},
"links": {
"desc": "Allow to edit the links of the embeds, removing entirely the citation, or transform to a simple link",
"dp": {
Expand All @@ -240,6 +246,7 @@
},
"title": "Change embed markup"
},
"notes": "Note (Markdown)",
"title": "Embed",
"transferImage": {
"desc": "Send attachments embedded in a file to GitHub.",
Expand Down
9 changes: 8 additions & 1 deletion src/i18n/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
"title": "Texte & liens"
},
"embed": {
"attachment": "Pièces-jointes",
"bake": {
"text": "Permet d'ajouter du texte avant et après chaque intégration, par exemple en ajoutant du HTML ou en stylisant le bloc avec du markdown.",
"textAfter": {
Expand All @@ -230,6 +231,11 @@
"desc": "Pour utiliser un dossier différent de celui par défaut pour les pièces-jointes.",
"title": "Dossier de pièces-jointes par défaut"
},
"forcePush": {
"desc": "Les extensions suivantes seront toujours envoyés dans le dépôt, même si elles y existent déjà. Séparer les extensions par une virgule.",
"infoAboutAttachments": "Normalement, les pièces-jointes sont envoyées uniquement si elle n'existe pas sur le dépôt.",
"title": "Forcer l'envoie des pièces-jointes"
},
"links": {
"desc": "Permet d'éditer les liens des embeds, en supprimant entièrement la citation, ou en la transformant en un simple lien.",
"dp": {
Expand All @@ -240,6 +246,7 @@
},
"title": "Changer les balises d'embed"
},
"notes": "Note (Markdown)",
"title": "Embed",
"transferImage": {
"desc": "Transférer les pièces-jointes",
Expand Down Expand Up @@ -445,7 +452,7 @@
},
"shareKey": {
"all": {
"desc": "Allow to share all file and ignore the share key state",
"desc": "Autoriser le partage de tous les fichiers et ignorer l'état de la clé de partage",
"title": "Partager tous les fichiers sans clé de partage"
},
"desc": "Clé de partage",
Expand Down
116 changes: 71 additions & 45 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import { TokenEditPath } from "./settings/modals/token_path";
import {
autoCleanCondition,
autoCleanUpSettingsOnCondition,
folderHideShowSettings,
shortcutsHideShow, showHideBasedOnFolder,
folderHideShowSettings, showHideBasedOnFolder,
} from "./settings/style";
import { checkRepositoryValidity, verifyRateLimitAPI } from "./utils/data_validation_test";

Expand All @@ -39,7 +38,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
const { containerEl } = this;
containerEl.empty();
containerEl.addClass("github-publisher");

const PUBLISHER_TABS = {
"github-configuration": {
name: i18next.t("settings.github.title"),
Expand Down Expand Up @@ -197,7 +196,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
.addText((text) =>
text
.setPlaceholder(
i18next.t("settings.github.username.title")
i18next.t("settings.github.username.title")
)
.setValue(githubSettings.user)
.onChange(async (value) => {
Expand Down Expand Up @@ -327,7 +326,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
new Setting(this.settingsPage)
.setName(i18next.t("settings.githubWorkflow.githubAction.title"))
.setDesc(
i18next.t("settings.githubWorkflow.githubAction.desc")
i18next.t("settings.githubWorkflow.githubAction.desc")
)
.addText((text) => {
text.setPlaceholder("ci")
Expand Down Expand Up @@ -435,10 +434,10 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
});
const frontmatterTitleSet = new Setting(this.settingsPage)
.setName(
i18next.t("settings.upload.useFrontmatterTitle.title")
i18next.t("settings.upload.useFrontmatterTitle.title")
)
.setDesc(
i18next.t("settings.upload.useFrontmatterTitle.desc")
i18next.t("settings.upload.useFrontmatterTitle.desc")
)
.setClass("title")
.addToggle((toggle) => {
Expand Down Expand Up @@ -466,7 +465,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
new Setting(this.settingsPage)
.setName(desc)
.setDesc(
i18next.t("settings.upload.regexFilePathTitle.desc")
i18next.t("settings.upload.regexFilePathTitle.desc")
)
.addButton((button) => {
button
Expand All @@ -483,11 +482,11 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
})).open();
});
});

const folderNoteSettings = new Setting(this.settingsPage)
.setName(i18next.t("settings.conversion.links.folderNote.title"))
.setDesc(
i18next.t("settings.conversion.links.folderNote.desc")
i18next.t("settings.conversion.links.folderNote.desc")
)
.addToggle((toggle) => {
toggle
Expand Down Expand Up @@ -517,10 +516,10 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
if (this.app.plugins.manifests["metadata-extractor"]) {
new Setting(this.settingsPage)
.setName(
i18next.t("settings.githubWorkflow.useMetadataExtractor.title")
i18next.t("settings.githubWorkflow.useMetadataExtractor.title")
)
.setDesc(
i18next.t("settings.githubWorkflow.useMetadataExtractor.desc")
i18next.t("settings.githubWorkflow.useMetadataExtractor.desc")
)
.addText((text) => {
text.setPlaceholder("docs/_assets/metadata")
Expand Down Expand Up @@ -579,7 +578,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
autoCleanSetting,
this.plugin
);

folderHideShowSettings(
frontmatterKeySettings,
rootFolderSettings,
Expand Down Expand Up @@ -629,10 +628,10 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
if (textSettings.links.internal && !this.plugin.settings.plugin.shareAll?.enable) {
new Setting(this.settingsPage)
.setName(
i18next.t("settings.conversion.links.nonShared.title")
i18next.t("settings.conversion.links.nonShared.title")
)
.setDesc(
i18next.t("settings.conversion.links.nonShared.desc")
i18next.t("settings.conversion.links.nonShared.desc")
)
.addToggle((toggle) => {
toggle
Expand All @@ -648,7 +647,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
new Setting(this.settingsPage)
.setName(i18next.t("settings.conversion.links.wikilinks.title"))
.setDesc(
i18next.t("settings.conversion.links.wikilinks.desc")
i18next.t("settings.conversion.links.wikilinks.desc")
)
.addToggle((toggle) => {
toggle
Expand Down Expand Up @@ -718,10 +717,10 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
this.settingsPage.createEl("h5", { text: "Tags" });
new Setting(this.settingsPage)
.setName(
i18next.t("settings.conversion.tags.inlineTags.title")
i18next.t("settings.conversion.tags.inlineTags.title")
)
.setDesc(
i18next.t("settings.conversion.tags.inlineTags.desc")
i18next.t("settings.conversion.tags.inlineTags.desc")
)
.addToggle((toggle) => {
toggle
Expand Down Expand Up @@ -764,42 +763,67 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
});
});


}

/**
* Render the settings page for the embeds settings
*/
async renderEmbedConfiguration() {
this.settingsPage.empty();

this.settingsPage.createEl("h5", { text: i18next.t("settings.embed.attachment"), cls: "center" });

const embedSettings = this.plugin.settings.embed;
new Setting(this.settingsPage)
.setName(i18next.t("settings.embed.transferImage.title"))
.setDesc(i18next.t("settings.embed.transferImage.desc"))
.addToggle((toggle) => {
toggle
.setValue(embedSettings.attachments)
.onChange(async (value) => {
embedSettings.attachments = value;
shortcutsHideShow(value, settingsDefaultImage);
await this.plugin.saveSettings();
this.renderSettingsPage(EnumbSettingsTabId.embed);
});
});

const settingsDefaultImage = new Setting(this.settingsPage)
.setName(i18next.t("settings.embed.defaultImageFolder.title"))
.setDesc(i18next.t("settings.embed.defaultImageFolder.desc"))
.addText((text) => {
text.setPlaceholder("docs/images")
.setValue(embedSettings.folder)
.onChange(async (value) => {
embedSettings.folder = value.replace(
/\/$/,
""
);
await this.plugin.saveSettings();
});
});
if (embedSettings.attachments) {
new Setting(this.settingsPage)
.setName(i18next.t("settings.embed.defaultImageFolder.title"))
.setDesc(i18next.t("settings.embed.defaultImageFolder.desc"))
.addText((text) => {
text.setPlaceholder("docs/images")
.setValue(embedSettings.folder)
.onChange(async (value) => {
embedSettings.folder = value.replace(
/\/$/,
""
);
await this.plugin.saveSettings();
});
});

const forcePushDesc = document.createDocumentFragment();
forcePushDesc.createEl("div", { text: i18next.t("settings.embed.forcePush.infoAboutAttachments") });
forcePushDesc.createEl("div", { text: i18next.t("settings.embed.forcePush.desc") });

new Setting(this.settingsPage)
.setName(i18next.t("settings.embed.forcePush.title"))
.setDesc(forcePushDesc)
.setClass("mini")
.addTextArea((text) => {
text
.setPlaceholder("pdf, png")
.setValue(embedSettings.forcePushAttachments?.join(", "))
.onChange(async (value) => {
embedSettings.forcePushAttachments = value
.split(/[,\n]\W*/)
.map((item) => item.trim())
.filter((item) => item.length > 0);
await this.plugin.saveSettings();
});
});
}

new Setting(this.settingsPage)
.setName(i18next.t("settings.embed.transferMetaFile.title"))
Expand All @@ -818,6 +842,8 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
});
});

this.settingsPage.createEl("h5", { text: i18next.t("settings.embed.notes"), cls: "center"});

new Setting(this.settingsPage)
.setName(i18next.t("settings.embed.transferNotes.title"))
.setDesc(i18next.t("settings.embed.transferNotes.desc"))
Expand Down Expand Up @@ -870,7 +896,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
await this.plugin.saveSettings();
}
await this.plugin.saveSettings();
this.settingsPage.createEl("h4", {text: i18next.t("settings.embed.bake.title")});
this.settingsPage.createEl("h5", {text: i18next.t("settings.embed.bake.title"), cls: "border-bottom"});
this.settingsPage.createEl("p", {text: i18next.t("settings.embed.bake.text")});
this.settingsPage.createEl("p", undefined, (el) => {
el.createEl("span", {
Expand Down Expand Up @@ -924,7 +950,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
*/
renderPluginSettings() {
const pluginSettings = this.plugin.settings.plugin;

this.settingsPage.createEl("h3", {text: i18next.t("settings.plugin.head.share")});
new Setting(this.settingsPage)
.setName(i18next.t("settings.plugin.shareKey.all.title"))
Expand Down Expand Up @@ -968,7 +994,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
})
);
}

new Setting(this.settingsPage)
.setName(i18next.t("settings.plugin.excludedFolder.title"))
.setDesc(i18next.t("settings.plugin.excludedFolder.desc"))
Expand Down Expand Up @@ -1010,7 +1036,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
})
);
this.settingsPage.createEl("h3", {text: i18next.t("settings.plugin.head.copyLinks")});

new Setting(this.settingsPage)
.setName(i18next.t("settings.plugin.copyLink.title"))
.setDesc(i18next.t("settings.plugin.copyLink.desc"))
Expand All @@ -1021,7 +1047,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
pluginSettings.copyLink.enable = value;
await this.plugin.saveSettings();
this.renderSettingsPage(EnumbSettingsTabId.plugin);

})
);

Expand All @@ -1040,7 +1066,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
new Setting(this.settingsPage)
.setName(i18next.t("settings.plugin.copyLink.linkPathRemover.title"))
.setDesc(
i18next.t("settings.plugin.copyLink.linkPathRemover.desc")
i18next.t("settings.plugin.copyLink.linkPathRemover.desc")
)
.addText((text) => {
text.setPlaceholder("docs")
Expand All @@ -1050,7 +1076,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
await this.plugin.saveSettings();
});
});

new Setting(this.settingsPage)
.setName(i18next.t("settings.plugin.copyLink.command.desc"))
.addToggle((toggle) =>
Expand All @@ -1076,8 +1102,8 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
await this.plugin.saveSettings();
})
);
this.settingsPage.createEl("h4", {text: i18next.t("settings.plugin.head.log")});

this.settingsPage.createEl("h4", {text: i18next.t("settings.plugin.head.log")});

new Setting(this.settingsPage)
.setName(i18next.t("settings.plugin.logNoticeHeader.title"))
Expand All @@ -1090,7 +1116,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
await this.plugin.saveSettings();
})
);

new Setting(this.settingsPage)
.setName(i18next.t("settings.plugin.dev.title"))
.setDesc(i18next.t("settings.plugin.dev.desc"))
Expand Down
Loading

0 comments on commit 773270c

Please sign in to comment.