@fluxfiles/ckeditor4 1.0.0 → 1.0.2

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/README.md CHANGED
@@ -79,8 +79,16 @@ The modal closes automatically after selection.
79
79
  | `locale` | string | `null` | UI language code |
80
80
  | `theme` | string | `null` | Picker theme: `light` / `dark` / `auto` |
81
81
  | `multiple` | boolean | `false` | Allow multi-file selection |
82
+ | `allowedTypes` | string[] | `null` | Extensions (`.pdf` or `pdf`) or MIME types / patterns (`image/*`, `application/pdf`). Shown only in picker mode: non-matching files are hidden and cannot be selected. UI convenience, not a security boundary (the token's `allowed_ext` claim is the server-side check) |
82
83
  | `imageDialog` | boolean | `true` | Inject the **Browse FluxFiles** button into the native Image dialog |
83
84
 
85
+ **Files with no permanent URL.** Two cases:
86
+
87
+ - On a gated local disk (`FLUXFILES_LOCAL_PRIVATE`) or an SFTP disk without `public_url`, `permanent_url` is `null` and the only link is an expiring `/api/fm/img|stream?token=` URL. The plugin never saves that into content: it shows one notification listing the refused files. Use a public disk or set `public_url`.
88
+ - A private bucket without `public_url` yields a presigned URL (up to 24h). That one **is** still inserted, with a `console.warn`, and it stops working when it expires.
89
+
90
+ Only `http(s)` URLs are ever inserted.
91
+
84
92
  ## License
85
93
 
86
94
  MIT — see [LICENSE](LICENSE) for details.
@@ -88,5 +96,5 @@ MIT — see [LICENSE](LICENSE) for details.
88
96
  ## Links
89
97
 
90
98
  - Main repository: `https://github.com/thai-pc/fluxfiles`
91
- - Documentation: `https://github.com/thai-pc/fluxfiles#ckeditor-4`
99
+ - Documentation: `https://github.com/thai-pc/fluxfiles#framework-adapters`
92
100
  - Issues: `https://github.com/thai-pc/fluxfiles/issues`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluxfiles/ckeditor4",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "CKEditor 4 plugin for FluxFiles",
5
5
  "license": "MIT",
6
6
  "main": "plugin.js",
@@ -19,7 +19,7 @@
19
19
  "devDependencies": { "esbuild": "^0.28.0", "jsdom": "^25.0.1", "vitest": "^2.1.8" },
20
20
  "publishConfig": { "access": "public" },
21
21
  "author": "thai-pc",
22
- "homepage": "https://github.com/thai-pc/fluxfiles#ckeditor-4",
22
+ "homepage": "https://github.com/thai-pc/fluxfiles#framework-adapters",
23
23
  "repository": {
24
24
  "type": "git",
25
25
  "url": "git+https://github.com/thai-pc/fluxfiles.git",
package/plugin.js CHANGED
@@ -26,14 +26,15 @@
26
26
  (function () {
27
27
  'use strict';
28
28
 
29
- // Shared toolbar glyph — the same F-folder icon TinyMCE registers, kept inline
30
- // (no separate image file) so both editor plugins stay visually in sync.
29
+ // Shared toolbar glyph: the FluxFiles logo's square folder silhouette with an
30
+ // "F", as a monochrome line icon, identical in the CKEditor 4, CKEditor 5,
31
+ // TinyMCE and Summernote plugins. Kept inline (no separate image file).
31
32
  // currentColor doesn't resolve inside an <img>, so use an explicit gray.
32
33
  var ICON_SVG = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none">'
33
- + '<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" '
34
+ + '<path d="M3 5a2 2 0 012-2h5l2 2h7a2 2 0 012 2v12a2 2 0 01-2 2H5a2 2 0 01-2-2V5z" '
34
35
  + 'fill="none" stroke="#575757" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>'
35
36
  // The "F" tells it apart from the editor's own folder/browse buttons.
36
- + '<path d="M10 16.5v-6h4.5M10 13.5h3.5" '
37
+ + '<path d="M10 16.5v-7h4.5M10 13h3.5" '
37
38
  + 'fill="none" stroke="#575757" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';
38
39
  var ICON_URI = 'data:image/svg+xml,' + encodeURIComponent(ICON_SVG);
39
40
 
@@ -52,9 +53,69 @@
52
53
  );
53
54
  }
54
55
 
56
+ // Selected URLs must be absolute and permanent. Older cores return a
57
+ // root-relative url ('/storage/uploads/x') that would resolve against the HOST
58
+ // page; resolve it against the FluxFiles endpoint's origin. And never let an
59
+ // expiring .../img|stream ?token= URL reach saved content.
60
+ function absUrl(u, endpoint) {
61
+ if (typeof u !== 'string') return '';
62
+ // Strip leading whitespace/control chars first: browsers ignore them, so
63
+ // " \tjavascript:..." would otherwise slip past a scheme check.
64
+ var t = u.replace(/^[\u0000-\u0020]+/, '');
65
+ if (t === '') return '';
66
+ var r = null;
67
+ try { r = new URL(t, endpoint || window.location.href); } catch (e) {
68
+ try { r = new URL(t, window.location.href); } catch (e2) { return ''; }
69
+ }
70
+ // Only http(s) may reach saved content (drops javascript:, data:, vbscript:, ...).
71
+ return (r.protocol === 'http:' || r.protocol === 'https:') ? r.href : '';
72
+ }
73
+ function isTokenUrl(u) {
74
+ return /\/(img|stream)(\.php)?\?([^#]*&)?token=/.test(u);
75
+ }
76
+ // Why a selection cannot be inserted: 'preview' (no URL), 'unsafe' (not http/https),
77
+ // 'token' (only an expiring /img|/stream token link, e.g. a private local or SFTP disk).
78
+ function refusalReason(raw, url) {
79
+ if (raw === '') return 'preview';
80
+ if (url === '') return 'unsafe';
81
+ return isTokenUrl(url) ? 'token' : '';
82
+ }
83
+ function refusalMessage(reason, name) {
84
+ if (reason === 'token') {
85
+ return '"' + name + '" is only available through an expiring link (private disk without a public URL), so it was not inserted. Use a public disk or set public_url.';
86
+ }
87
+ if (reason === 'unsafe') {
88
+ return '"' + name + '" has a URL that is not http(s), so it was not inserted.';
89
+ }
90
+ return '"' + 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.';
91
+ }
92
+ // User-visible refusal (a console.warn alone is invisible to editors).
93
+ // One combined message per selection (at most 5 lines).
94
+ function joinRefusals(msgs) {
95
+ var out = msgs.slice(0, 5);
96
+ if (msgs.length > 5) { out.push('… and ' + (msgs.length - 5) + ' more'); }
97
+ return out;
98
+ }
99
+ // showNotification() renders its argument as HTML and the messages carry file
100
+ // names (which can hold markup on storage written by other tools): encode them.
101
+ function notifyUser(editor, msgs) {
102
+ if (!msgs.length) return;
103
+ var lines = joinRefusals(msgs);
104
+ try {
105
+ if (editor && typeof editor.showNotification === 'function') {
106
+ editor.showNotification(lines.map(CKEDITOR.tools.htmlEncode).join('<br>'), 'warning');
107
+ return;
108
+ }
109
+ } catch (e) { /* fall through */ }
110
+ if (typeof window.alert === 'function') { try { window.alert(lines.join('\n')); } catch (e) { /* ignore */ } }
111
+ }
112
+
55
113
  // Normalize a selected file into the bits the insert / dialog paths need.
56
- function fileInfo(file) {
57
- var url = file.permanent_url || file.url || '';
114
+ function fileInfo(file, endpoint, notify) {
115
+ var raw = file.permanent_url || file.url || '';
116
+ var url = absUrl(raw, endpoint);
117
+ var reason = refusalReason(raw, url);
118
+ if (reason) { url = ''; } // expiring token / non-http(s) URL: never save it
58
119
  var name = file.name || file.basename || file.path || '';
59
120
  var meta = file.meta || {};
60
121
  // Preview-only selection (no permanent_url/url) — e.g. a watermark OVERLAY
@@ -63,7 +124,9 @@
63
124
  // watermark into the file first (Watermark editor → Apply). Refuse here.
64
125
  var embeddable = url !== '';
65
126
  if (!embeddable) {
66
- 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.');
127
+ var msg = refusalMessage(reason, name);
128
+ console.warn('[FluxFiles] ' + msg);
129
+ if (notify) { notify(msg); }
67
130
  } else if (/[?&](X-Amz-|Signature=)/.test(url)) {
68
131
  console.warn('[FluxFiles] Inserting a presigned (expiring) URL — it will break when the URL expires. Use a public disk or public_url for embeds.');
69
132
  }
@@ -117,8 +180,10 @@
117
180
  open(cfg, false, function (payload) {
118
181
  var file = firstFile(payload);
119
182
  if (!file) return;
120
- var info = fileInfo(file);
121
- if (!info.embeddable) return; // preview-only → already warned
183
+ var refused = [];
184
+ var info = fileInfo(file, cfg.endpoint, function (m) { refused.push(m); });
185
+ notifyUser(editor, refused);
186
+ if (!info.embeddable) return; // refused → already reported
122
187
  var set = function (id, val) {
123
188
  var el = dialog.getContentElement('info', id);
124
189
  if (el && val != null && val !== '') el.setValue(String(val));
@@ -150,11 +215,12 @@
150
215
  // quote in e.g. alt_text break out of the attribute (stored XSS).
151
216
  var encAttr = CKEDITOR.tools.htmlEncodeAttr;
152
217
  var enc = CKEDITOR.tools.htmlEncode;
218
+ var refused = [];
153
219
  for (var i = 0; i < files.length; i++) {
154
220
  var file = files[i];
155
221
  if (!file || file.is_dir) continue;
156
- var info = fileInfo(file);
157
- if (!info.embeddable) continue; // preview-only → already warned
222
+ var info = fileInfo(file, cfg.endpoint, function (m) { refused.push(m); });
223
+ if (!info.embeddable) continue; // refused → reported below
158
224
 
159
225
  if (info.isImage) {
160
226
  var dim = '';
@@ -165,6 +231,7 @@
165
231
  editor.insertHtml('<a href="' + encAttr(info.url) + '">' + enc(info.meta.title || info.name) + '</a>');
166
232
  }
167
233
  }
234
+ notifyUser(editor, refused);
168
235
  });
169
236
  }
170
237
  });
package/plugin.min.js CHANGED
@@ -1 +1,2 @@
1
- (function(){"use strict";var x='<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" 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" fill="none" stroke="#575757" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/><path d="M10 16.5v-6h4.5M10 13.5h3.5" fill="none" stroke="#575757" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',f="data:image/svg+xml,"+encodeURIComponent(x),h=!1;function v(){h||!CKEDITOR.document||!CKEDITOR.document.appendStyleText||(h=!0,CKEDITOR.document.appendStyleText('.cke_button__fluxfiles_icon{background:url("'+f+'") no-repeat 0 0 / 16px 16px !important}'))}function p(e){var n=e.permanent_url||e.url||"",i=e.name||e.basename||e.path||"",r=e.meta||{},l=n!=="";l?/[?&](X-Amz-|Signature=)/.test(n)&&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] "'+i+'" 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 o=e.mime&&e.mime.indexOf("image/")===0||/\.(jpe?g|png|gif|webp|svg|bmp|ico|avif)$/i.test(i);return{url:n,name:i,meta:r,isImage:o,embeddable:l,width:e.width||null,height:e.height||null}}function g(e,n,i){if(typeof FluxFiles>"u"){console.error("[FluxFiles] SDK (fluxfiles.js) is not loaded.");return}FluxFiles.open({endpoint:e.endpoint||"",token:e.token||"",disk:e.disk||"local",mode:"picker",multiple:!!n,maxUploadMb:e.maxUploadMb||null,maxFiles:e.maxFiles||null,locale:e.locale||null,theme:e.theme||null,disks:e.disks||null,allowedTypes:e.allowedTypes||null,path:e.path||"",onSelect:i})}function w(e){var n=Array.isArray(e)?e[0]:e;return n&&!n.is_dir?n:null}CKEDITOR.fluxfilesDialogHook||(CKEDITOR.fluxfilesDialogHook=!0,CKEDITOR.on("dialogDefinition",function(e){if(!(e.data.name!=="image"&&e.data.name!=="image2")){var n=e.editor,i=n&&n.config&&n.config.fluxfiles;if(!(!i||i.imageDialog===!1)){var r=e.data.definition,l=r.getContents("info")||r.getContents("Upload");l&&l.add({type:"button",id:"fluxfilesBrowse",label:"Browse FluxFiles",title:"Browse FluxFiles",onClick:function(){var o=this.getDialog();g(i,!1,function(u){var s=w(u);if(s){var t=p(s);if(t.embeddable){var a=function(b,m){var c=o.getContentElement("info",b);c&&m!=null&&m!==""&&c.setValue(String(m))};a("txtUrl",t.url),a("txtAlt",t.meta.alt_text||t.name),t.width&&a("txtWidth",t.width),t.height&&a("txtHeight",t.height);var d=o.getContentElement("info","txtUrl");d&&typeof d.onChange=="function"&&d.onChange()}}})}})}}})),CKEDITOR.plugins.add("fluxfiles",{init:function(e){var n=e.config.fluxfiles||{};e.addCommand("openFluxFiles",{exec:function(){g(n,n.multiple,function(i){for(var r=Array.isArray(i)?i:[i],l=CKEDITOR.tools.htmlEncodeAttr,o=CKEDITOR.tools.htmlEncode,u=0;u<r.length;u++){var s=r[u];if(!(!s||s.is_dir)){var t=p(s);if(t.embeddable)if(t.isImage){var a="";t.width&&(a+=' width="'+parseInt(t.width,10)+'"'),t.height&&(a+=' height="'+parseInt(t.height,10)+'"'),e.insertHtml('<img src="'+l(t.url)+'" alt="'+l(t.meta.alt_text||t.name)+'"'+a+" />")}else e.insertHtml('<a href="'+l(t.url)+'">'+o(t.meta.title||t.name)+"</a>")}}})}}),v(),e.ui.addButton("FluxFiles",{label:"FluxFiles",command:"openFluxFiles",toolbar:"insert",icon:f})}})})();
1
+ (function(){"use strict";var b='<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none"><path d="M3 5a2 2 0 012-2h5l2 2h7a2 2 0 012 2v12a2 2 0 01-2 2H5a2 2 0 01-2-2V5z" fill="none" stroke="#575757" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/><path d="M10 16.5v-7h4.5M10 13h3.5" fill="none" stroke="#575757" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',p="data:image/svg+xml,"+encodeURIComponent(b),m=!1;function k(){m||!CKEDITOR.document||!CKEDITOR.document.appendStyleText||(m=!0,CKEDITOR.document.appendStyleText('.cke_button__fluxfiles_icon{background:url("'+p+'") no-repeat 0 0 / 16px 16px !important}'))}function F(e,t){if(typeof e!="string")return"";var i=e.replace(/^[\u0000-\u0020]+/,"");if(i==="")return"";var r=null;try{r=new URL(i,t||window.location.href)}catch{try{r=new URL(i,window.location.href)}catch{return""}}return r.protocol==="http:"||r.protocol==="https:"?r.href:""}function C(e){return/\/(img|stream)(\.php)?\?([^#]*&)?token=/.test(e)}function I(e,t){return e===""?"preview":t===""?"unsafe":C(t)?"token":""}function R(e,t){return e==="token"?'"'+t+'" is only available through an expiring link (private disk without a public URL), so it was not inserted. Use a public disk or set public_url.':e==="unsafe"?'"'+t+'" has a URL that is not http(s), so it was not inserted.':'"'+t+'" 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.'}function U(e){var t=e.slice(0,5);return e.length>5&&t.push("\u2026 and "+(e.length-5)+" more"),t}function w(e,t){if(t.length){var i=U(t);try{if(e&&typeof e.showNotification=="function"){e.showNotification(i.map(CKEDITOR.tools.htmlEncode).join("<br>"),"warning");return}}catch{}if(typeof window.alert=="function")try{window.alert(i.join(`
2
+ `))}catch{}}}function g(e,t,i){var r=e.permanent_url||e.url||"",a=F(r,t),s=I(r,a);s&&(a="");var u=e.name||e.basename||e.path||"",d=e.meta||{},o=a!=="";if(o)/[?&](X-Amz-|Signature=)/.test(a)&&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.");else{var n=R(s,u);console.warn("[FluxFiles] "+n),i&&i(n)}var l=e.mime&&e.mime.indexOf("image/")===0||/\.(jpe?g|png|gif|webp|svg|bmp|ico|avif)$/i.test(u);return{url:a,name:u,meta:d,isImage:l,embeddable:o,width:e.width||null,height:e.height||null}}function v(e,t,i){if(typeof FluxFiles>"u"){console.error("[FluxFiles] SDK (fluxfiles.js) is not loaded.");return}FluxFiles.open({endpoint:e.endpoint||"",token:e.token||"",disk:e.disk||"local",mode:"picker",multiple:!!t,maxUploadMb:e.maxUploadMb||null,maxFiles:e.maxFiles||null,locale:e.locale||null,theme:e.theme||null,disks:e.disks||null,allowedTypes:e.allowedTypes||null,path:e.path||"",onSelect:i})}function y(e){var t=Array.isArray(e)?e[0]:e;return t&&!t.is_dir?t:null}CKEDITOR.fluxfilesDialogHook||(CKEDITOR.fluxfilesDialogHook=!0,CKEDITOR.on("dialogDefinition",function(e){if(!(e.data.name!=="image"&&e.data.name!=="image2")){var t=e.editor,i=t&&t.config&&t.config.fluxfiles;if(!(!i||i.imageDialog===!1)){var r=e.data.definition,a=r.getContents("info")||r.getContents("Upload");a&&a.add({type:"button",id:"fluxfilesBrowse",label:"Browse FluxFiles",title:"Browse FluxFiles",onClick:function(){var s=this.getDialog();v(i,!1,function(u){var d=y(u);if(d){var o=[],n=g(d,i.endpoint,function(h){o.push(h)});if(w(t,o),!!n.embeddable){var l=function(h,c){var x=s.getContentElement("info",h);x&&c!=null&&c!==""&&x.setValue(String(c))};l("txtUrl",n.url),l("txtAlt",n.meta.alt_text||n.name),n.width&&l("txtWidth",n.width),n.height&&l("txtHeight",n.height);var f=s.getContentElement("info","txtUrl");f&&typeof f.onChange=="function"&&f.onChange()}}})}})}}})),CKEDITOR.plugins.add("fluxfiles",{init:function(e){var t=e.config.fluxfiles||{};e.addCommand("openFluxFiles",{exec:function(){v(t,t.multiple,function(i){for(var r=Array.isArray(i)?i:[i],a=CKEDITOR.tools.htmlEncodeAttr,s=CKEDITOR.tools.htmlEncode,u=[],d=0;d<r.length;d++){var o=r[d];if(!(!o||o.is_dir)){var n=g(o,t.endpoint,function(f){u.push(f)});if(n.embeddable)if(n.isImage){var l="";n.width&&(l+=' width="'+parseInt(n.width,10)+'"'),n.height&&(l+=' height="'+parseInt(n.height,10)+'"'),e.insertHtml('<img src="'+a(n.url)+'" alt="'+a(n.meta.alt_text||n.name)+'"'+l+" />")}else e.insertHtml('<a href="'+a(n.url)+'">'+s(n.meta.title||n.name)+"</a>")}}w(e,u)})}}),k(),e.ui.addButton("FluxFiles",{label:"FluxFiles",command:"openFluxFiles",toolbar:"insert",icon:p})}})})();