@fluxfiles/tinymce 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluxfiles/tinymce",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "TinyMCE plugin for FluxFiles",
5
5
  "license": "MIT",
6
6
  "main": "plugin.js",
package/plugin.js CHANGED
@@ -30,10 +30,15 @@
30
30
  (function () {
31
31
  'use strict';
32
32
 
33
+ // Encode a value for use inside an HTML ATTRIBUTE (src="...", alt="...", href="...").
34
+ // The DOM textNode→innerHTML trick alone only encodes &/</> (correct for text-node
35
+ // context) but leaves `"` untouched, letting a quote in e.g. alt_text break out of the
36
+ // attribute and inject arbitrary attributes/script (stored XSS). Order matters: encode
37
+ // `&` first (via the DOM trick) so the following quote replacements aren't re-escaped.
33
38
  function escHtml(str) {
34
39
  var div = document.createElement('div');
35
40
  div.appendChild(document.createTextNode(str || ''));
36
- return div.innerHTML;
41
+ return div.innerHTML.replace(/"/g, '&quot;').replace(/'/g, '&#39;');
37
42
  }
38
43
 
39
44
  function cfg(editor) {
@@ -58,9 +63,19 @@
58
63
  var name = file.name || file.basename || file.path || '';
59
64
  var meta = file.meta || {};
60
65
 
61
- // Still presigned (private disk, no public_url)? Warn — it will expire and
62
- // break the saved link/image.
63
- if (/[?&](X-Amz-|Signature=)/.test(url)) {
66
+ // Preview-only selection (no permanent_url and no url) — e.g. a watermark
67
+ // OVERLAY image with allow_download=false. Its only view is img_base, a
68
+ // short-lived token URL that must NOT be saved into content (it expires →
69
+ // broken image), and inserting the empty string would yield <img src="">.
70
+ // To embed a *watermarked* image, burn the watermark into the file first
71
+ // (Watermark editor → Apply) — that yields a stable, watermarked
72
+ // permanent_url. So we refuse here rather than insert a clean/broken image.
73
+ var embeddable = url !== '';
74
+ if (!embeddable) {
75
+ console.warn('[FluxFiles] "' + name + '" is preview-only (no embeddable URL — e.g. a watermark overlay with allow_download=false), so it was not inserted. Burn in the watermark (Watermark editor → Apply) or issue a downloadable token to embed it.');
76
+ } else if (/[?&](X-Amz-|Signature=)/.test(url)) {
77
+ // Still presigned (private disk, no public_url)? Warn — it will expire
78
+ // and break the saved link/image.
64
79
  console.warn('[FluxFiles] Inserting a presigned (expiring) URL — it will break when the URL expires. Use a public disk or public_url for embeds.');
65
80
  }
66
81
 
@@ -68,7 +83,7 @@
68
83
  || /\.(jpe?g|png|gif|webp|svg|bmp|ico|avif)$/i.test(name);
69
84
 
70
85
  return {
71
- url: url, name: name, meta: meta, isImage: isImage,
86
+ url: url, name: name, meta: meta, isImage: isImage, embeddable: embeddable,
72
87
  width: file.width || null, height: file.height || null
73
88
  };
74
89
  }
@@ -96,6 +111,7 @@
96
111
  var file = files[i];
97
112
  if (!file || file.is_dir) continue;
98
113
  var info = fileInfo(file);
114
+ if (!info.embeddable) continue; // preview-only → already warned
99
115
 
100
116
  if (info.isImage) {
101
117
  var dim = '';
@@ -118,6 +134,7 @@
118
134
  var file = Array.isArray(payload) ? payload[0] : payload;
119
135
  if (!file || file.is_dir) return;
120
136
  var info = fileInfo(file);
137
+ if (!info.embeddable) return; // preview-only → already warned
121
138
  var data = {};
122
139
 
123
140
  if (meta && meta.filetype === 'image') {
package/plugin.min.js CHANGED
@@ -1 +1 @@
1
- (function(){"use strict";function r(e){var t=document.createElement("div");return t.appendChild(document.createTextNode(e||"")),t.innerHTML}function c(e){return{endpoint:e.getParam("fluxfiles_endpoint",""),token:e.getParam("fluxfiles_token",""),disk:e.getParam("fluxfiles_disk","local"),locale:e.getParam("fluxfiles_locale",null),theme:e.getParam("fluxfiles_theme",null),disks:e.getParam("fluxfiles_disks",null),multiple:e.getParam("fluxfiles_multiple",!1),maxUploadMb:e.getParam("fluxfiles_max_upload_mb",null),maxFiles:e.getParam("fluxfiles_max_files",null)}}function m(e){var t=e.permanent_url||e.url||"",a=e.name||e.basename||e.path||"",i=e.meta||{};/[?&](X-Amz-|Signature=)/.test(t)&&console.warn("[FluxFiles] Inserting a presigned (expiring) URL \u2014 it will break when the URL expires. Use a public disk or public_url for embeds.");var s=e.mime&&e.mime.indexOf("image/")===0||/\.(jpe?g|png|gif|webp|svg|bmp|ico|avif)$/i.test(a);return{url:t,name:a,meta:i,isImage:s,width:e.width||null,height:e.height||null}}function o(e,t,a){if(typeof FluxFiles>"u"){console.error("[FluxFiles] SDK (fluxfiles.js) is not loaded.");return}var i=c(e);FluxFiles.open({endpoint:i.endpoint,token:i.token,disk:i.disk,mode:"picker",multiple:!!t,maxUploadMb:i.maxUploadMb,maxFiles:i.maxFiles,locale:i.locale,theme:i.theme,disks:i.disks,onSelect:a})}function f(e){o(e,c(e).multiple,function(t){for(var a=Array.isArray(t)?t:[t],i=0;i<a.length;i++){var s=a[i];if(!(!s||s.is_dir)){var l=m(s);if(l.isImage){var n="";l.width&&(n+=' width="'+parseInt(l.width,10)+'"'),l.height&&(n+=' height="'+parseInt(l.height,10)+'"'),e.insertContent('<img src="'+r(l.url)+'" alt="'+r(l.meta.alt_text||l.name)+'"'+n+" />")}else e.insertContent('<a href="'+r(l.url)+'">'+r(l.meta.title||l.name)+"</a>")}}})}function g(e){return function(t,a,i){o(e,!1,function(s){var l=Array.isArray(s)?s[0]:s;if(!(!l||l.is_dir)){var n=m(l),u={};i&&i.filetype==="image"?(u.alt=n.meta.alt_text||n.name,n.width&&(u.width=String(n.width)),n.height&&(u.height=String(n.height))):i&&i.filetype==="media"||(u.text=n.meta.title||n.name,u.title=n.meta.title||n.name),t(n.url,u)}})}}function p(e){if(e.getParam("fluxfiles_image_dialog",!0)!==!1&&typeof e.getParam("file_picker_callback")!="function"){var t=g(e);e.settings&&(e.settings.file_picker_callback=t,e.settings.file_picker_types||(e.settings.file_picker_types="file image media"));try{e.options&&typeof e.options.set=="function"&&(e.options.set("file_picker_callback",t),e.options.get("file_picker_types")||e.options.set("file_picker_types","file image media"))}catch{}}}tinymce.PluginManager.add("fluxfiles",function(e){p(e);var t=parseInt(tinymce.majorVersion,10);if(t>=5)return e.ui.registry.addIcon("fluxfiles",'<svg width="24" height="24" viewBox="0 0 24 24" fill="none"><path d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>'),e.ui.registry.addButton("fluxfiles",{icon:"fluxfiles",tooltip:"FluxFiles",onAction:function(){f(e)}}),e.ui.registry.addMenuItem("fluxfiles",{icon:"fluxfiles",text:"FluxFiles",onAction:function(){f(e)}}),{getMetadata:function(){return{name:"FluxFiles",url:"https://github.com/thai-pc/fluxfiles"}}};e.addButton("fluxfiles",{icon:"browse",tooltip:"FluxFiles",onclick:function(){f(e)}}),e.addMenuItem("fluxfiles",{icon:"browse",text:"FluxFiles",onclick:function(){f(e)},context:"insert"})})})();
1
+ (function(){"use strict";function u(e){var t=document.createElement("div");return t.appendChild(document.createTextNode(e||"")),t.innerHTML.replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function m(e){return{endpoint:e.getParam("fluxfiles_endpoint",""),token:e.getParam("fluxfiles_token",""),disk:e.getParam("fluxfiles_disk","local"),locale:e.getParam("fluxfiles_locale",null),theme:e.getParam("fluxfiles_theme",null),disks:e.getParam("fluxfiles_disks",null),multiple:e.getParam("fluxfiles_multiple",!1),maxUploadMb:e.getParam("fluxfiles_max_upload_mb",null),maxFiles:e.getParam("fluxfiles_max_files",null)}}function o(e){var t=e.permanent_url||e.url||"",a=e.name||e.basename||e.path||"",i=e.meta||{},s=t!=="";s?/[?&](X-Amz-|Signature=)/.test(t)&&console.warn("[FluxFiles] Inserting a presigned (expiring) URL \u2014 it will break when the URL expires. Use a public disk or public_url for embeds."):console.warn('[FluxFiles] "'+a+'" is preview-only (no embeddable URL \u2014 e.g. a watermark overlay with allow_download=false), so it was not inserted. Burn in the watermark (Watermark editor \u2192 Apply) or issue a downloadable token to embed it.');var l=e.mime&&e.mime.indexOf("image/")===0||/\.(jpe?g|png|gif|webp|svg|bmp|ico|avif)$/i.test(a);return{url:t,name:a,meta:i,isImage:l,embeddable:s,width:e.width||null,height:e.height||null}}function c(e,t,a){if(typeof FluxFiles>"u"){console.error("[FluxFiles] SDK (fluxfiles.js) is not loaded.");return}var i=m(e);FluxFiles.open({endpoint:i.endpoint,token:i.token,disk:i.disk,mode:"picker",multiple:!!t,maxUploadMb:i.maxUploadMb,maxFiles:i.maxFiles,locale:i.locale,theme:i.theme,disks:i.disks,onSelect:a})}function f(e){c(e,m(e).multiple,function(t){for(var a=Array.isArray(t)?t:[t],i=0;i<a.length;i++){var s=a[i];if(!(!s||s.is_dir)){var l=o(s);if(l.embeddable)if(l.isImage){var n="";l.width&&(n+=' width="'+parseInt(l.width,10)+'"'),l.height&&(n+=' height="'+parseInt(l.height,10)+'"'),e.insertContent('<img src="'+u(l.url)+'" alt="'+u(l.meta.alt_text||l.name)+'"'+n+" />")}else e.insertContent('<a href="'+u(l.url)+'">'+u(l.meta.title||l.name)+"</a>")}}})}function p(e){return function(t,a,i){c(e,!1,function(s){var l=Array.isArray(s)?s[0]:s;if(!(!l||l.is_dir)){var n=o(l);if(n.embeddable){var r={};i&&i.filetype==="image"?(r.alt=n.meta.alt_text||n.name,n.width&&(r.width=String(n.width)),n.height&&(r.height=String(n.height))):i&&i.filetype==="media"||(r.text=n.meta.title||n.name,r.title=n.meta.title||n.name),t(n.url,r)}}})}}function g(e){if(e.getParam("fluxfiles_image_dialog",!0)!==!1&&typeof e.getParam("file_picker_callback")!="function"){var t=p(e);e.settings&&(e.settings.file_picker_callback=t,e.settings.file_picker_types||(e.settings.file_picker_types="file image media"));try{e.options&&typeof e.options.set=="function"&&(e.options.set("file_picker_callback",t),e.options.get("file_picker_types")||e.options.set("file_picker_types","file image media"))}catch{}}}tinymce.PluginManager.add("fluxfiles",function(e){g(e);var t=parseInt(tinymce.majorVersion,10);if(t>=5)return e.ui.registry.addIcon("fluxfiles",'<svg width="24" height="24" viewBox="0 0 24 24" fill="none"><path d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>'),e.ui.registry.addButton("fluxfiles",{icon:"fluxfiles",tooltip:"FluxFiles",onAction:function(){f(e)}}),e.ui.registry.addMenuItem("fluxfiles",{icon:"fluxfiles",text:"FluxFiles",onAction:function(){f(e)}}),{getMetadata:function(){return{name:"FluxFiles",url:"https://github.com/thai-pc/fluxfiles"}}};e.addButton("fluxfiles",{icon:"browse",tooltip:"FluxFiles",onclick:function(){f(e)}}),e.addMenuItem("fluxfiles",{icon:"browse",text:"FluxFiles",onclick:function(){f(e)},context:"insert"})})})();