Alex-D / Trumbowyg

A lightweight and amazing WYSIWYG JavaScript editor under 10kB
https://alex-d.github.io/Trumbowyg
MIT License
3.99k stars 612 forks source link

nombed not return all elements #1481

Open JonathanJvs opened 1 month ago

JonathanJvs commented 1 month ago

When we get an request with the proxy, the returned just the url in data, not the html and others elements in the preview of response.

Proposition:

`function (data) { // Build request URL var requestUrl = new URL(trumbowyg.o.plugins.noembed.proxy); Object.keys(data).forEach((key) => { requestUrl.searchParams.append(key, data[key].trim()); });

                                // Launch async request
                                fetch(requestUrl, {
                                    method: 'GET',
                                    cache: 'no-cache',
                                    signal: AbortSignal.timeout(2000)
                                }).then((response) => {
                                    return response.json().then((json) => {
                                        if (trumbowyg.o.plugins.noembed.success) {
                                            trumbowyg.o.plugins.noembed.success(json, trumbowyg, $modal);
                                            return;
                                        }

                                        if (!json.html) {
                                            trumbowyg.addErrorOnModalField(
                                                $('input[type=text]', $modal),
                                                json.error
                                            );
                                            return;
                                        }

                                        trumbowyg.execCmd('insertHTML', json.html);
                                        setTimeout(function () {
                                            trumbowyg.closeModal();
                                        }, 250);
                                    });
                                }).catch((...args) => {
                                    if (trumbowyg.o.plugins.noembed.error) {
                                        trumbowyg.o.plugins.noembed.error(...args);
                                        return;
                                    }

                                    trumbowyg.addErrorOnModalField(
                                        $('input[type=text]', $modal),
                                        trumbowyg.lang.noembedError
                                    );
                                });
                            }`
bastienJanon commented 1 week ago

I reproduce, i tested my proxy which return truly html but I don't know why sucess callback return only a json like {video: "url-of-video"}

EDIT: i just found the problem the case only append when a plugins.noembed.sucessCallback is provided,

image

L.122 you send data (data request) instead of response