Skip to content

Commit 65540b5

Browse files
committed
feat: restrict templater integration behind a setting
1 parent 3369a4c commit 65540b5

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/main.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,9 @@ export default class MediaDbPlugin extends Plugin {
297297

298298
const targetFile = await this.createNote(this.mediaTypeManager.getFileName(mediaTypeModel), fileContent, options);
299299

300-
await useTemplaterPluginInFile(this.app, targetFile);
300+
if (this.settings.enableTemplaterIntegration) {
301+
await useTemplaterPluginInFile(this.app, targetFile);
302+
}
301303
} catch (e) {
302304
console.warn(e);
303305
new Notice(e.toString());
@@ -376,7 +378,7 @@ export default class MediaDbPlugin extends Plugin {
376378
frontMatter.dataSource = mediaTypeModel.dataSource;
377379
}
378380

379-
if (hasTemplaterPlugin(this.app)) {
381+
if (this.settings.enableTemplaterIntegration && hasTemplaterPlugin(this.app)) {
380382
// Only support stringifyYaml for templater plugin
381383
// Include the media variable in all templater commands by using a top level JavaScript execution command.
382384
fileContent = `---\n<%* const media = ${JSON.stringify(mediaTypeModel)} %>\n${stringifyYaml(frontMatter)}---\n${fileContent}`;

src/settings/Settings.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface MediaDbPluginSettings {
1717
customDateFormat: string;
1818
openNoteInNewTab: boolean;
1919
useDefaultFrontMatter: boolean;
20+
enableTemplaterIntegration: boolean;
2021

2122
movieTemplate: string;
2223
seriesTemplate: string;
@@ -65,6 +66,7 @@ const DEFAULT_SETTINGS: MediaDbPluginSettings = {
6566
customDateFormat: 'L',
6667
openNoteInNewTab: true,
6768
useDefaultFrontMatter: true,
69+
enableTemplaterIntegration: false,
6870

6971
movieTemplate: '',
7072
seriesTemplate: '',
@@ -232,6 +234,18 @@ export class MediaDbSettingTab extends PluginSettingTab {
232234
});
233235
});
234236

237+
new Setting(containerEl)
238+
.setName('Enable Templater integration')
239+
.setDesc(
240+
'Enable integration with the templater plugin, this also needs templater to be installed. Warning: Templater allows you to execute arbitrary JavaScript code and system commands.',
241+
)
242+
.addToggle(cb => {
243+
cb.setValue(this.plugin.settings.enableTemplaterIntegration).onChange(data => {
244+
this.plugin.settings.enableTemplaterIntegration = data;
245+
this.plugin.saveSettings();
246+
});
247+
});
248+
235249
containerEl.createEl('h3', { text: 'New File Location' });
236250
// region new file location
237251
new Setting(containerEl)

0 commit comments

Comments
 (0)