Skip to content

Commit 0425db6

Browse files
authored
Get rid of FileUploader component (along w/ ember-uploader package) (#408)
* Get rid of FileUploader component * u-edit/shared-modules/drag-and-drop: use our own uploader service to perform uploads * get rid of ember-uploader * prevent ember-cli-code-coverage babel plugin setup from leaking when parent runs tests w/ COVERAGE=true * fix context * linter fix
1 parent 768c19c commit 0425db6

File tree

15 files changed

+2038
-743
lines changed

15 files changed

+2038
-743
lines changed

addon/components/file-uploader.hbs

-30
This file was deleted.

addon/components/file-uploader.js

-181
This file was deleted.

addon/components/input-uploader/component.js

-10
This file was deleted.

addon/components/u-edit/shared-modules/drag-and-drop.js

+21-35
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
import Uploader from '@upfluence/ember-upf-utils/uploader';
21
import Configuration from '@upfluence/ember-upf-utils/configuration';
32

43
export default class ModuleBuilder {
5-
constructor(session, toast) {
6-
Object.assign(this, { session, toast });
4+
constructor(uploader, toast) {
5+
Object.assign(this, { uploader, toast });
76
}
87

98
build(editor, element) {
10-
return new Module(editor, element, this.session, this.toast);
9+
return new Module(editor, element, this.uploader, this.toast);
1110
}
1211
}
1312

1413
class Module {
15-
constructor(editor, element, session, toast) {
16-
Object.assign(this, { editor, element, session, toast });
14+
constructor(editor, element, uploader, toast) {
15+
Object.assign(this, { editor, element, uploader, toast });
1716

1817
this.editor.registerModule(this);
1918

@@ -22,35 +21,17 @@ class Module {
2221
};
2322
}
2423

25-
_uploaderBuilder() {
26-
let uploader = Uploader.create({
27-
ajaxSettings: {
28-
dataType: 'json',
29-
headers: {
30-
...this.uploaderHeaders,
31-
Authorization: `Bearer ${this.session.data.authenticated.access_token}`
32-
}
33-
},
34-
url: Configuration.uploaderUrl,
35-
allowedExtensions: 'jpg,jpeg,png,gif',
36-
maxSize: null
37-
});
38-
39-
uploader
40-
.on('didValidationError', (error) => {
41-
this.toast.error(error || 'Your file is invalid. Please check the requirements.');
42-
this._removeLoadingState();
43-
})
44-
.on('didUpload', (element) => {
45-
this.editor.insertImage(element.artifact.url);
46-
this._removeLoadingState();
47-
});
48-
49-
return uploader;
50-
}
51-
5224
_uploadFile(file) {
53-
this._uploaderBuilder().upload(file, { privacy: 'public' });
25+
this.uploader.upload(
26+
{
27+
file: file,
28+
privacy: 'public',
29+
scope: 'anonymous',
30+
onSuccess: this._onSuccess.bind(this),
31+
onFailure: this._removeLoadingState
32+
},
33+
[{ type: 'filetype', value: ['image', 'gif'] }]
34+
);
5435
}
5536

5637
_createLoadingStates() {
@@ -90,9 +71,14 @@ class Module {
9071
document.querySelector('.uedit__loading-image-upload').classList.add('uedit__loading-image-upload--hidden');
9172
}
9273

74+
_onSuccess(artifact) {
75+
this.editor.insertImage(artifact.url);
76+
this._removeLoadingState();
77+
}
78+
9379
onImageUpload(files) {
9480
this._addLoadingStates();
95-
Array.prototype.forEach.call(files, (file) => this._uploadFile(file));
81+
Array.from(files || []).forEach((file) => this._uploadFile(file));
9682
}
9783

9884
getOptions() {

0 commit comments

Comments
 (0)