Skip to content

Commit

Permalink
MDL-75260 tiny_media: Move uploader to editor_tiny
Browse files Browse the repository at this point in the history
Part of MDL-75966
  • Loading branch information
andrewnicols committed Nov 10, 2022
1 parent 92765e9 commit 7104655
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 18 deletions.
3 changes: 3 additions & 0 deletions lib/editor/tiny/amd/build/uploader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/editor/tiny/amd/build/uploader.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -16,7 +16,7 @@
/**
* Tiny Media plugin for Moodle.
*
* @module tiny_media/plugin
* @module editor_tiny/uploade
* @copyright 2022 Andrew Lyons <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
Expand All @@ -28,9 +28,8 @@ import {getFilePicker} from 'editor_tiny/options';

// This image uploader is based on advice given at:
// https://www.tiny.cloud/docs/tinymce/6/upload-images/
export default (activeEditor, blobInfo, progress) => new Promise((resolve, reject) => {
notifyUploadStarted(activeEditor.targetElm.id);
debugger; // eslint-disable-line
export default (editor, filePickerType, blob, fileName, progress) => new Promise((resolve, reject) => {
notifyUploadStarted(editor.targetElm.id);

const xhr = new XMLHttpRequest();

Expand Down Expand Up @@ -60,7 +59,7 @@ export default (activeEditor, blobInfo, progress) => new Promise((resolve, rejec
return;
}

notifyUploadCompleted(activeEditor.targetElm.id);
notifyUploadCompleted(editor.targetElm.id);

let location;
if (response.url) {
Expand All @@ -81,13 +80,16 @@ export default (activeEditor, blobInfo, progress) => new Promise((resolve, rejec
});

xhr.addEventListener('error', () => {
reject(`Image upload failed due to an XHR transport error. Code: ${xhr.status}`);
reject({
message: `Upload failed due to an XHR transport error. Code: ${xhr.status}`,
remove: true,
});
});

const formData = new FormData();
const options = getFilePicker(activeEditor, 'image');
const options = getFilePicker(editor, filePickerType);

formData.append('repo_upload_file', blobInfo.blob());
formData.append('repo_upload_file', blob, fileName);
formData.append('itemid', options.itemid);
Object.values(options.repositories).some((repository) => {
if (repository.type === 'upload') {
Expand Down
4 changes: 2 additions & 2 deletions lib/editor/tiny/plugins/media/amd/build/configuration.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7104655

Please sign in to comment.