Loading editor/html/js/api.js +10 −0 Original line number Diff line number Diff line Loading @@ -247,6 +247,16 @@ var EditorApi = (function() { }); }, mediaCreatePreview: function(connId, mediaId, width, height) { var params = { command: 'media_create_preview', media_id: mediaId }; if (width > 0) params.width = width; if (height > 0) params.height = height; return request('POST', '/api/connection/media/' + connId, params); }, // HTML import/export importHtml: function(html) { return request('POST', '/api/document/import-html', { html: html }); Loading editor/html/js/media-browser.js +12 −3 Original line number Diff line number Diff line Loading @@ -119,7 +119,7 @@ var MediaBrowser = (function() { } for (var i = 0; i < media.length; i++) { _grid.appendChild(_createMediaItem(media[i])); _grid.appendChild(_createMediaItem(media[i], connId)); } }).catch(function(err) { _status.textContent = 'Error: ' + (err.error || 'Unknown'); Loading @@ -127,16 +127,25 @@ var MediaBrowser = (function() { }); } function _createMediaItem(item) { function _createMediaItem(item, connId) { var div = document.createElement('div'); div.className = 'media-grid-item'; div.dataset.id = item.id; if (item.kind === 'image' || item.content_type.indexOf('image') === 0) { var img = document.createElement('img'); img.src = item.url + '?w=150&h=150'; img.alt = item.filename; img.loading = 'lazy'; // Create preview with width=150, height auto-calculated EditorApi.mediaCreatePreview(connId, item.id, 150, 0).then(function(prev) { if (prev.url) { img.src = prev.url; } else { img.src = item.url; } }).catch(function() { img.src = item.url; }); div.appendChild(img); } else { var icon = document.createElement('div'); Loading editor/src/webedit_api.cpp +13 −1 Original line number Diff line number Diff line Loading @@ -1876,7 +1876,8 @@ void webedit::Api::handleMediaBrowse(libhttppp::HttpRequest &curreq, json_object_object_get_ex(req, "command", &cmdObj); std::string command = cmdObj ? json_object_get_string(cmdObj) : ""; if (command != "media_list_albums" && command != "media_list_media") { if (command != "media_list_albums" && command != "media_list_media" && command != "media_create_preview") { json_object_put(req); sendJsonError(curreq, 400, "Invalid command"); return; Loading Loading @@ -1935,6 +1936,17 @@ void webedit::Api::handleMediaBrowse(libhttppp::HttpRequest &curreq, if (json_object_object_get_ex(item, "media", &mediaObj)) { json_object_object_add(result, "media", json_object_get(mediaObj)); } // Forward media_create_preview response fields json_object *urlObj = nullptr, *wObj = nullptr, *hObj = nullptr; if (json_object_object_get_ex(item, "url", &urlObj)) { json_object_object_add(result, "url", json_object_get(urlObj)); } if (json_object_object_get_ex(item, "width", &wObj)) { json_object_object_add(result, "width", json_object_get(wObj)); } if (json_object_object_get_ex(item, "height", &hObj)) { json_object_object_add(result, "height", json_object_get(hObj)); } } } json_object_put(apiResp); Loading Loading
editor/html/js/api.js +10 −0 Original line number Diff line number Diff line Loading @@ -247,6 +247,16 @@ var EditorApi = (function() { }); }, mediaCreatePreview: function(connId, mediaId, width, height) { var params = { command: 'media_create_preview', media_id: mediaId }; if (width > 0) params.width = width; if (height > 0) params.height = height; return request('POST', '/api/connection/media/' + connId, params); }, // HTML import/export importHtml: function(html) { return request('POST', '/api/document/import-html', { html: html }); Loading
editor/html/js/media-browser.js +12 −3 Original line number Diff line number Diff line Loading @@ -119,7 +119,7 @@ var MediaBrowser = (function() { } for (var i = 0; i < media.length; i++) { _grid.appendChild(_createMediaItem(media[i])); _grid.appendChild(_createMediaItem(media[i], connId)); } }).catch(function(err) { _status.textContent = 'Error: ' + (err.error || 'Unknown'); Loading @@ -127,16 +127,25 @@ var MediaBrowser = (function() { }); } function _createMediaItem(item) { function _createMediaItem(item, connId) { var div = document.createElement('div'); div.className = 'media-grid-item'; div.dataset.id = item.id; if (item.kind === 'image' || item.content_type.indexOf('image') === 0) { var img = document.createElement('img'); img.src = item.url + '?w=150&h=150'; img.alt = item.filename; img.loading = 'lazy'; // Create preview with width=150, height auto-calculated EditorApi.mediaCreatePreview(connId, item.id, 150, 0).then(function(prev) { if (prev.url) { img.src = prev.url; } else { img.src = item.url; } }).catch(function() { img.src = item.url; }); div.appendChild(img); } else { var icon = document.createElement('div'); Loading
editor/src/webedit_api.cpp +13 −1 Original line number Diff line number Diff line Loading @@ -1876,7 +1876,8 @@ void webedit::Api::handleMediaBrowse(libhttppp::HttpRequest &curreq, json_object_object_get_ex(req, "command", &cmdObj); std::string command = cmdObj ? json_object_get_string(cmdObj) : ""; if (command != "media_list_albums" && command != "media_list_media") { if (command != "media_list_albums" && command != "media_list_media" && command != "media_create_preview") { json_object_put(req); sendJsonError(curreq, 400, "Invalid command"); return; Loading Loading @@ -1935,6 +1936,17 @@ void webedit::Api::handleMediaBrowse(libhttppp::HttpRequest &curreq, if (json_object_object_get_ex(item, "media", &mediaObj)) { json_object_object_add(result, "media", json_object_get(mediaObj)); } // Forward media_create_preview response fields json_object *urlObj = nullptr, *wObj = nullptr, *hObj = nullptr; if (json_object_object_get_ex(item, "url", &urlObj)) { json_object_object_add(result, "url", json_object_get(urlObj)); } if (json_object_object_get_ex(item, "width", &wObj)) { json_object_object_add(result, "width", json_object_get(wObj)); } if (json_object_object_get_ex(item, "height", &hObj)) { json_object_object_add(result, "height", json_object_get(hObj)); } } } json_object_put(apiResp); Loading