diff --git a/src/main.ts b/src/main.ts index 045f340..825509e 100755 --- a/src/main.ts +++ b/src/main.ts @@ -24,6 +24,7 @@ interface CloudinarySettings { imageUpload: boolean; audioUpload: boolean; videoUpload: boolean; + rawUpload: boolean; } // Set settings defaults @@ -37,7 +38,8 @@ const DEFAULT_SETTINGS: CloudinarySettings = { clipboardUpload: true, imageUpload: true, audioUpload: false, - videoUpload: false + videoUpload: false, + rawUpload: false }; export default class CloudinaryUploader extends Plugin { settings: CloudinarySettings; @@ -71,13 +73,16 @@ export default class CloudinaryUploader extends Plugin { private uploadFiles = async (files: FileList,event,editor) => { // On paste event, get "files" from clipbaord or drag data - // If files contain image, move to API call - // if Files empty or does not contain image, throw error + // If files contain image, video, or audio move to API call + // if Files empty or does not contain above, then keep default paste behaviour if(files.length > 0){ if((this.settings.audioUpload && files[0].type.startsWith("audio")) || (this.settings.videoUpload && files[0].type.startsWith('video')) || - (this.settings.imageUpload && files[0].type.startsWith('image'))){ - event.preventDefault(); // Prevent default paste behaviour + (this.settings.imageUpload && files[0].type.startsWith('image')) || + + (this.settings.rawUpload && !files[0].type.startsWith('image')) && + !files[0].type.startsWith('audio') && !files[0].type.startsWith('video') ){ + event.preventDefault(); // Prevent default paste behaviour if (this.settings.cloudName && this.settings.uploadPreset) { for (let file of files) { @@ -129,7 +134,7 @@ export default class CloudinaryUploader extends Plugin { this.replaceText(editor, pastePlaceText, replaceMarkdownText) }, err => { // Fail otherwise - new Notice(err, 5000) + new Notice("There was something wrong with the upload. PLease check your cloud name and template name before trying again "+err, 5000) console.log(err) }) } diff --git a/src/settings-tab.ts b/src/settings-tab.ts index fda0f03..9db57cb 100755 --- a/src/settings-tab.ts +++ b/src/settings-tab.ts @@ -222,5 +222,21 @@ export default class CloudinaryUploaderSettingTab extends PluginSettingTab { } }) }); + new Setting(containerEl) + .setName("Upload Raw Files") + .setDesc("Raw files are those files that are not necessarily media files, but Cloudinary will still accept for upload") + .addToggle((toggle) => { + toggle + .setValue(this.plugin.settings.rawUpload) + .onChange(async (value) => { + try { + this.plugin.settings.rawUpload = value; + await this.plugin.saveSettings(); + } + catch (e) { + console.log(e) + } + }) + }); } } \ No newline at end of file