Skip to content

Commit

Permalink
add support for multimedia upload types
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanhandy committed May 23, 2024
1 parent 69301cf commit 9c04405
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface CloudinarySettings {
imageUpload: boolean;
audioUpload: boolean;
videoUpload: boolean;
rawUpload: boolean;
}

// Set settings defaults
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
})
}
Expand Down
16 changes: 16 additions & 0 deletions src/settings-tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
});
}
}

0 comments on commit 9c04405

Please sign in to comment.