aboutsummaryrefslogtreecommitdiff
path: root/resources/assets/javascripts/cke/StudipUpload.js
blob: e1d0eceee13212bfd818cd57e6764291164ddc42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class StudipUploadAdapter {
    constructor(loader) {
        this.loader = loader;
    }

    upload() {
        return this.loader.file.then(
            (file) =>
                new Promise((resolve, reject) => {
                    var data = new FormData();
                    data.append('files[]', file);

                    $.ajax({
                        url: STUDIP.URLHelper.getURL('dispatch.php/wysiwyg/upload'),
                        type: 'POST',
                        data: data,
                        contentType: false,
                        async: false,
                        processData: false,
                        cache: false,
                        dataType: 'json',
                        error: function (err) {
                            reject(err);
                        },
                        success: function (data) {
                            resolve({ default: data.files[0].url });
                        },
                    });
                })
        );
    }

    // Aborts the upload process.
    abort() {}
}

export default function StudipUpload(editor) {
    if (editor.plugins.has('FileRepository')) {
        editor.plugins.get('FileRepository').createUploadAdapter = (loader) => {
            return new StudipUploadAdapter(loader);
        };
    }
}