plugin-file-preview-auth 1.1.0 → 1.1.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
@@ -1,65 +1,65 @@
1
- # Authenticated File Previewer
2
-
3
- NocoBase plugin for previewing files with **Bearer token authentication**. Solves the problem where default preview components fail to load files from storage that requires authentication.
4
-
5
- ## Features
6
-
7
- ### Supported File Types
8
-
9
- | Type | Extensions | Preview Method |
10
- |------|-----------|---------------|
11
- | **PDF** | `.pdf` | Rendered in `<iframe>` via authenticated blob URL |
12
- | **Images** | `.png` `.jpg` `.jpeg` `.gif` `.webp` `.svg` `.bmp` | Rendered in `<img>` via authenticated blob URL |
13
- | **Text** | `.txt` `.csv` `.json` `.xml` `.yaml` `.yml` `.xaml` `.html` `.css` `.js` `.log` `.md` | Fetched as text, displayed in formatted `<pre>` block |
14
- | **Word** | `.docx` | Rendered using [docx-preview](https://github.com/VolodymyrBayworker/docx-preview) (bundled) |
15
- | **Excel** | `.xlsx` `.xls` | Rendered as HTML table using [SheetJS](https://sheetjs.com/) (bundled) with multi-sheet tabs |
16
-
17
- All other file types show a download prompt with authenticated download.
18
-
19
- ### Authentication Flow
20
-
21
- 1. File URL is resolved from the attachment/file record
22
- 2. File is fetched from server with `Authorization: Bearer <token>` header
23
- 3. Response is converted to a Blob (binary) or text
24
- 4. Content is rendered client-side — no unauthenticated requests are made
25
-
26
- ### File Manager Integration
27
-
28
- The plugin registers handlers in both NocoBase preview registries:
29
-
30
- - **`attachmentFileTypes`** — Intercepts all file clicks in Upload/Attachment fields
31
- - **`filePreviewTypes`** — Handles previews in File Manager plugin
32
-
33
- ### Additional Features
34
-
35
- - **Authenticated download** — Download button in preview modal also uses Bearer token
36
- - **Multi-sheet support** — Excel files with multiple sheets display tabs for navigation
37
- - **Code-split bundles** — DOCX and XLSX libraries are lazy-loaded only when needed
38
- - **i18n** — English, Vietnamese, Chinese translations included
39
- - **Zero server-side processing** — All preview rendering happens in the browser
40
-
41
- ## Installation
42
-
43
- ```bash
44
- # From .tgz file
45
- yarn pm add /path/to/plugin-file-preview-auth-1.1.0.tgz
46
- yarn pm enable plugin-file-preview-auth
47
- ```
48
-
49
- ## Compatibility
50
-
51
- - NocoBase **2.x**
52
- - Requires `plugin-file-manager` to be enabled
53
-
54
- ## Changelog
55
-
56
- ### v1.1.0
57
- - Added DOCX preview (docx-preview, bundled)
58
- - Added XLSX/XLS preview with multi-sheet tabs (SheetJS, bundled)
59
- - Added YAML, YML, XAML to text preview
60
- - Libraries are code-split and lazy-loaded
61
-
62
- ### v1.0.1
63
- - Initial release
64
- - PDF, Image, and Text preview with Bearer token auth
65
- - Authenticated download for all file types
1
+ # Authenticated File Previewer
2
+
3
+ NocoBase plugin for previewing files with **Bearer token authentication**. Solves the problem where default preview components fail to load files from storage that requires authentication.
4
+
5
+ ## Features
6
+
7
+ ### Supported File Types
8
+
9
+ | Type | Extensions | Preview Method |
10
+ |------|-----------|---------------|
11
+ | **PDF** | `.pdf` | Rendered in `<iframe>` via authenticated blob URL |
12
+ | **Images** | `.png` `.jpg` `.jpeg` `.gif` `.webp` `.svg` `.bmp` | Rendered in `<img>` via authenticated blob URL |
13
+ | **Text** | `.txt` `.csv` `.json` `.xml` `.yaml` `.yml` `.xaml` `.html` `.css` `.js` `.log` `.md` | Fetched as text, displayed in formatted `<pre>` block |
14
+ | **Word** | `.docx` | Rendered using [docx-preview](https://github.com/VolodymyrBayworker/docx-preview) (bundled) |
15
+ | **Excel** | `.xlsx` `.xls` | Rendered as HTML table using [SheetJS](https://sheetjs.com/) (bundled) with multi-sheet tabs |
16
+
17
+ All other file types show a download prompt with authenticated download.
18
+
19
+ ### Authentication Flow
20
+
21
+ 1. File URL is resolved from the attachment/file record
22
+ 2. File is fetched from server with `Authorization: Bearer <token>` header
23
+ 3. Response is converted to a Blob (binary) or text
24
+ 4. Content is rendered client-side — no unauthenticated requests are made
25
+
26
+ ### File Manager Integration
27
+
28
+ The plugin registers handlers in both NocoBase preview registries:
29
+
30
+ - **`attachmentFileTypes`** — Intercepts all file clicks in Upload/Attachment fields
31
+ - **`filePreviewTypes`** — Handles previews in File Manager plugin
32
+
33
+ ### Additional Features
34
+
35
+ - **Authenticated download** — Download button in preview modal also uses Bearer token
36
+ - **Multi-sheet support** — Excel files with multiple sheets display tabs for navigation
37
+ - **Code-split bundles** — DOCX and XLSX libraries are lazy-loaded only when needed
38
+ - **i18n** — English, Vietnamese, Chinese translations included
39
+ - **Zero server-side processing** — All preview rendering happens in the browser
40
+
41
+ ## Installation
42
+
43
+ ```bash
44
+ # From .tgz file
45
+ yarn pm add /path/to/plugin-file-preview-auth-1.1.0.tgz
46
+ yarn pm enable plugin-file-preview-auth
47
+ ```
48
+
49
+ ## Compatibility
50
+
51
+ - NocoBase **2.x**
52
+ - Requires `plugin-file-manager` to be enabled
53
+
54
+ ## Changelog
55
+
56
+ ### v1.1.0
57
+ - Added DOCX preview (docx-preview, bundled)
58
+ - Added XLSX/XLS preview with multi-sheet tabs (SheetJS, bundled)
59
+ - Added YAML, YML, XAML to text preview
60
+ - Libraries are code-split and lazy-loaded
61
+
62
+ ### v1.0.1
63
+ - Initial release
64
+ - PDF, Image, and Text preview with Bearer token auth
65
+ - Authenticated download for all file types
@@ -0,0 +1,13 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import { Plugin } from '@nocobase/client';
10
+ export declare class PluginFilePreviewAuthClient extends Plugin {
11
+ load(): Promise<void>;
12
+ }
13
+ export default PluginFilePreviewAuthClient;
@@ -7,4 +7,4 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
 
10
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@nocobase/plugin-file-manager/client"),require("@nocobase/client"),require("react"),require("@ant-design/icons"),require("antd")):"function"==typeof define&&define.amd?define("plugin-file-preview-auth",["@nocobase/plugin-file-manager/client","@nocobase/client","react","@ant-design/icons","antd"],t):"object"==typeof exports?exports["plugin-file-preview-auth"]=t(require("@nocobase/plugin-file-manager/client"),require("@nocobase/client"),require("react"),require("@ant-design/icons"),require("antd")):e["plugin-file-preview-auth"]=t(e["@nocobase/plugin-file-manager/client"],e["@nocobase/client"],e.react,e["@ant-design/icons"],e.antd)}(self,function(e,t,n,r,i){return function(){var o,l,a,u,c,s,f={581:function(e){e.exports=function(e,t){return"undefined"!=typeof __deoptimization_sideEffect__&&__deoptimization_sideEffect__(e,t),t}},482:function(e){"use strict";e.exports=r},772:function(e){"use strict";e.exports=t},183:function(t){"use strict";t.exports=e},721:function(e){"use strict";e.exports=i},156:function(e){"use strict";e.exports=n}},p={};function d(e){var t=p[e];if(void 0!==t)return t.exports;var n=p[e]={exports:{}};return f[e](n,n.exports,d),n.exports}d.m=f,d.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return d.d(t,{a:t}),t},d.d=function(e,t){for(var n in t)d.o(t,n)&&!d.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},d.f={},d.e=function(e){return Promise.all(Object.keys(d.f).reduce(function(t,n){return d.f[n](e,t),t},[]))},d.u=function(e){return""+({395:"02dcfcac51f80d8d",463:"348b1a931814844c"})[e]+".js"},d.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),d.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o={},l="plugin-file-preview-auth:",d.l=function(e,t,n,r){if(o[e])return void o[e].push(t);if(void 0!==n)for(var i,a,u=document.getElementsByTagName("script"),c=0;c<u.length;c++){var s=u[c];if(s.getAttribute("src")==e||s.getAttribute("data-webpack")==l+n){i=s;break}}i||(a=!0,(i=document.createElement("script")).charset="utf-8",i.timeout=120,d.nc&&i.setAttribute("nonce",d.nc),i.setAttribute("data-webpack",l+n),i.src=e),o[e]=[t];var f=function(t,n){i.onerror=i.onload=null,clearTimeout(p);var r=o[e];if(delete o[e],i.parentNode&&i.parentNode.removeChild(i),r&&r.forEach(function(e){return e(n)}),t)return t(n)},p=setTimeout(f.bind(null,void 0,{type:"timeout",target:i}),12e4);i.onerror=f.bind(null,i.onerror),i.onload=f.bind(null,i.onload),a&&document.head.appendChild(i)},d.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(a=window.__webpack_public_path__||"/").endsWith("/")||(a+="/"),d.p=a+"static/plugins/plugin-file-preview-auth/dist/client/",u={909:0},d.f.j=function(e,t){var n=d.o(u,e)?u[e]:void 0;if(0!==n)if(n)t.push(n[2]);else{var r=new Promise(function(t,r){n=u[e]=[t,r]});t.push(n[2]=r);var i=d.p+d.u(e),o=Error();d.l(i,function(t){if(d.o(u,e)&&(0!==(n=u[e])&&(u[e]=void 0),n)){var r=t&&("load"===t.type?"missing":t.type),i=t&&t.target&&t.target.src;o.message="Loading chunk "+e+" failed.\n("+r+": "+i+")",o.name="ChunkLoadError",o.type=r,o.request=i,n[1](o)}},"chunk-"+e,e)}},c=function(e,t){var n,r,i=t[0],o=t[1],l=t[2],a=0;if(i.some(function(e){return 0!==u[e]})){for(n in o)d.o(o,n)&&(d.m[n]=o[n]);l&&l(d)}for(e&&e(t);a<i.length;a++)r=i[a],d.o(u,r)&&u[r]&&u[r][0](),u[r]=0},(s=self.webpackChunkplugin_file_preview_auth=self.webpackChunkplugin_file_preview_auth||[]).forEach(c.bind(null,0)),s.push=c.bind(null,s.push.bind(s));var m={};return!function(){"use strict";d.r(m),d.d(m,{default:function(){return ei},PluginFilePreviewAuthClient:function(){return er}});var e=d(156),t=d.n(e),n=d(482),r=d(721),i=d(772),o=d(183),l=JSON.parse('{"u2":"plugin-file-preview-auth"}');function a(){var e=(0,i.useApp)();return function(t){return e.i18n.t(t,{ns:[l.u2,"client"]})}}var u=d(581);function c(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function s(e,t,n,r,i,o,l){try{var a=e[o](l),u=a.value}catch(e){n(e);return}a.done?t(u):Promise.resolve(u).then(r,i)}function f(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var o=e.apply(t,n);function l(e){s(o,r,i,l,a,"next",e)}function a(e){s(o,r,i,l,a,"throw",e)}l(void 0)})}}function p(e,t,n){return(p=x()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&b(i,n.prototype),i}).apply(null,arguments)}function h(e){return(h=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function v(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}function y(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n.push.apply(n,r)}return n})(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}function b(e,t){return(b=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function g(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,i=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=i){var o=[],l=!0,a=!1;try{for(i=i.call(e);!(l=(n=i.next()).done)&&(o.push(n.value),!t||o.length!==t);l=!0);}catch(e){a=!0,r=e}finally{try{l||null==i.return||i.return()}finally{if(a)throw r}}return o}}(e,t)||function(e,t){if(e){if("string"==typeof e)return c(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return c(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function w(e){var t="function"==typeof Map?new Map:void 0;return(w=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return p(e,arguments,h(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),b(n,e)})(e)}function x(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(x=function(){return!!e})()}function E(e,t){var n,r,i,o,l={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){var u=[o,a];if(n)throw TypeError("Generator is already executing.");for(;l;)try{if(n=1,r&&(i=2&u[0]?r.return:u[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,u[1])).done)return i;switch(r=0,i&&(u=[2&u[0],i.value]),u[0]){case 0:case 1:i=u;break;case 4:return l.label++,{value:u[1],done:!1};case 5:l.label++,r=u[1],u=[0];continue;case 7:u=l.ops.pop(),l.trys.pop();continue;default:if(!(i=(i=l.trys).length>0&&i[i.length-1])&&(6===u[0]||2===u[0])){l=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){l.label=u[1];break}if(6===u[0]&&l.label<i[1]){l.label=i[1],i=u;break}if(i&&l.label<i[2]){l.label=i[2],l.ops.push(u);break}i[2]&&l.ops.pop(),l.trys.pop();continue}u=t.call(e,l)}catch(e){u=[6,e],r=0}finally{n=i=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}var k=["application/pdf"],O=["image/png","image/jpeg","image/gif","image/webp","image/svg+xml","image/bmp"],j=["text/plain","text/csv","text/html","text/css","text/javascript","application/json","application/xml","text/xml","text/yaml","application/x-yaml"],S=["application/vnd.openxmlformats-officedocument.wordprocessingml.document"],P=["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.ms-excel"],C=["pdf"],_=["png","jpg","jpeg","gif","webp","svg","bmp"],L=["txt","csv","html","css","js","json","xml","log","md","yaml","yml","xaml"],T=["docx"],F=["xlsx","xls"],A=function(e){var t=("string"==typeof e?e:(null==e?void 0:e.extname)||(null==e?void 0:e.name)||(null==e?void 0:e.filename)||(null==e?void 0:e.url)||"").split("?")[0].split("#")[0],n=t.lastIndexOf(".");return -1!==n?t.slice(n+1).toLowerCase().replace(/^\./,""):""},R=function(e){var t="string"==typeof e?e:null==e?void 0:e.url;return t?t.startsWith("https://")||t.startsWith("http://")?t:"".concat(location.origin,"/").concat(t.replace(/^\//,"")):""},I=function(e){if((null==e?void 0:e.mimetype)&&k.includes(e.mimetype))return!0;var t=A(e);return!!t&&C.includes(t)},U=function(e){if((null==e?void 0:e.mimetype)&&O.includes(e.mimetype)||(null==e?void 0:e.mimetype)&&(0,i.matchMimetype)(e,"image/*"))return!0;var t=A(e);return!!t&&_.includes(t)},D=function(e){if((null==e?void 0:e.mimetype)&&j.includes(e.mimetype))return!0;var t=A(e);return!!t&&L.includes(t)},B=function(e){if((null==e?void 0:e.mimetype)&&S.includes(e.mimetype))return!0;var t=A(e);return!!t&&T.includes(t)},M=function(e){if((null==e?void 0:e.mimetype)&&P.includes(e.mimetype))return!0;var t=A(e);return!!t&&F.includes(t)},q=function(e){return e?e.title&&e.extname?"".concat(e.title).concat(e.extname):e.filename||e.name||e.title||"download":"download"};function z(e,t){return N.apply(this,arguments)}function N(){return(N=f(function(e,t){var n,r;return E(this,function(i){switch(i.label){case 0:return n={},t&&(n.Authorization="Bearer ".concat(t)),[4,fetch(e,{method:"GET",headers:n,credentials:"include"})];case 1:if(!(r=i.sent()).ok)throw Error("Failed to fetch file: ".concat(r.status," ").concat(r.statusText));return[2,r.blob()]}})})).apply(this,arguments)}function W(){return(W=f(function(e,t){var n,r;return E(this,function(i){switch(i.label){case 0:return n={},t&&(n.Authorization="Bearer ".concat(t)),[4,fetch(e,{method:"GET",headers:n,credentials:"include"})];case 1:if(!(r=i.sent()).ok)throw Error("Failed to fetch file: ".concat(r.status," ").concat(r.statusText));return[2,r.text()]}})})).apply(this,arguments)}function H(e,t){return X.apply(this,arguments)}function X(){return(X=f(function(e,t){var n,r,i,o,l;return E(this,function(a){switch(a.label){case 0:if(!(n=R(e)))return[2];return[4,z(n,t)];case 1:return r=a.sent(),i=q(e),(o=document.createElement("a")).href=l=URL.createObjectURL(r),o.download=i,document.body.appendChild(o),o.click(),document.body.removeChild(o),setTimeout(function(){return URL.revokeObjectURL(l)},1e3),[2]}})})).apply(this,arguments)}function G(t,n){var r=g((0,e.useState)(null),2),i=r[0],o=r[1],l=g((0,e.useState)(!0),2),a=l[0],u=l[1],c=g((0,e.useState)(null),2),s=c[0],f=c[1],p=(0,e.useRef)(null);return(0,e.useEffect)(function(){var e=!1,r=R(t);if(!r){u(!1),f("No file URL");return}return u(!0),f(null),z(r,n).then(function(t){if(!e){var n=URL.createObjectURL(t);p.current=n,o(n),u(!1)}}).catch(function(t){e||(f(t.message||"Failed to load"),u(!1))}),function(){e=!0,p.current&&(URL.revokeObjectURL(p.current),p.current=null)}},["string"==typeof t?t:null==t?void 0:t.url,n]),{blobUrl:i,loading:a,error:s}}function Y(e){var n=e.message;return t().createElement("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%",width:"100%"}},t().createElement(r.Spin,{tip:n}))}function J(e){var n=e.message;return t().createElement("div",{style:{padding:20,textAlign:"center",color:"#ff4d4f"}},n)}function $(e){var n,r=e.file,o=(0,i.useAPIClient)(),l=a(),u=G(r,(null==(n=o.auth)?void 0:n.token)||""),c=u.blobUrl,s=u.loading,f=u.error;return s?t().createElement(Y,{message:l("Loading preview...")}):f||!c?t().createElement(J,{message:l("Failed to load file preview")}):t().createElement("iframe",{src:c,width:"100%",height:"100%",style:{border:"none"}})}function K(e){var n,r=e.file,o=(0,i.useAPIClient)(),l=a(),u=G(r,(null==(n=o.auth)?void 0:n.token)||""),c=u.blobUrl,s=u.loading,f=u.error;return s?t().createElement(Y,{message:l("Loading preview...")}):f||!c?t().createElement(J,{message:l("Failed to load file preview")}):t().createElement("img",{src:c,style:{maxWidth:"100%",maxHeight:"100%",objectFit:"contain"},alt:(null==r?void 0:r.title)||(null==r?void 0:r.filename)||""})}function Q(n){var r,o,l,u,c,s,f,p,d,m,h=n.file,v=(0,i.useAPIClient)(),y=a(),b=(null==(m=v.auth)?void 0:m.token)||"",w=(o=(r=g((0,e.useState)(null),2))[0],l=r[1],c=(u=g((0,e.useState)(!0),2))[0],s=u[1],p=(f=g((0,e.useState)(null),2))[0],d=f[1],(0,e.useEffect)(function(){var e=!1,t=R(h);if(!t){s(!1),d("No file URL");return}return s(!0),d(null),(function(e,t){return W.apply(this,arguments)})(t,b).then(function(t){e||(l(t),s(!1))}).catch(function(t){e||(d(t.message||"Failed to load"),s(!1))}),function(){e=!0}},["string"==typeof h?h:null==h?void 0:h.url,b]),{text:o,loading:c,error:p}),x=w.text,E=w.loading,k=w.error;return E?t().createElement(Y,{message:y("Loading preview...")}):k||null===x?t().createElement(J,{message:y("Failed to load file preview")}):t().createElement("pre",{style:{width:"100%",height:"100%",overflow:"auto",padding:16,margin:0,fontSize:13,lineHeight:1.6,whiteSpace:"pre-wrap",wordWrap:"break-word",background:"#f5f5f5",border:"none"}},x)}function V(n){var r,o=n.file,l=(0,i.useAPIClient)(),c=a(),s=(null==(r=l.auth)?void 0:r.token)||"",p=(0,e.useRef)(null),m=g((0,e.useState)(!0),2),h=m[0],v=m[1],y=g((0,e.useState)(null),2),b=y[0],w=y[1];return(0,e.useEffect)(function(){var e=!1,t=R(o);if(!t||!p.current){v(!1),w("No file URL");return}return v(!0),w(null),f(function(){var n,r,i;return E(this,function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),[4,z(t,s)];case 1:if(n=o.sent(),e)return[2];return[4,u("imported_-1dm6lbf_component",d.e("395").then(d.bind(d,835)))];case 2:if(r=o.sent(),e||!p.current)return[2];return p.current.innerHTML="",[4,r.renderAsync(n,p.current,void 0,{className:"docx-preview-wrapper",inWrapper:!0,ignoreWidth:!1,ignoreHeight:!1,ignoreFonts:!1,breakPages:!0,ignoreLastRenderedPageBreak:!0,experimental:!1,trimXmlDeclaration:!0,useBase64URL:!0,renderHeaders:!0,renderFooters:!0,renderFootnotes:!0,renderEndnotes:!0})];case 3:return o.sent(),v(!1),[3,5];case 4:if(i=o.sent(),e)return[2];return w(i.message||"Failed to render DOCX"),v(!1),[3,5];case 5:return[2]}})})(),function(){e=!0}},["string"==typeof o?o:null==o?void 0:o.url,s]),t().createElement("div",{style:{width:"100%",height:"100%",position:"relative"}},h&&t().createElement(Y,{message:c("Loading preview...")}),b&&t().createElement(J,{message:c("Failed to load file preview")}),t().createElement("div",{ref:p,style:{width:"100%",height:"100%",overflow:"auto",display:h||b?"none":"block"}}))}function Z(n){var r,o=n.file,l=(0,i.useAPIClient)(),c=a(),s=(null==(r=l.auth)?void 0:r.token)||"",p=(0,e.useRef)(null),m=g((0,e.useState)(!0),2),h=m[0],v=m[1],y=g((0,e.useState)(null),2),b=y[0],w=y[1],x=g((0,e.useState)([]),2),k=x[0],O=x[1],j=g((0,e.useState)(""),2),S=j[0],P=j[1],C=g((0,e.useState)({}),2),_=C[0],L=C[1];return(0,e.useEffect)(function(){var e=!1,t=R(o);if(!t){v(!1),w("No file URL");return}return v(!0),w(null),f(function(){var n,r,i,o,l,a,c,f,p,m,h,y,b,g;return E(this,function(x){switch(x.label){case 0:return x.trys.push([0,4,,5]),[4,z(t,s)];case 1:if(n=x.sent(),e)return[2];return[4,u("imported_-1lj2ifg_component",d.e("463").then(d.bind(d,312)))];case 2:if(r=x.sent(),e)return[2];return[4,n.arrayBuffer()];case 3:if(i=x.sent(),e)return[2];l=(o=r.read(i,{type:"array"})).SheetNames,a={},c=!0,f=!1,p=void 0;try{for(m=l[Symbol.iterator]();!(c=(h=m.next()).done);c=!0)y=h.value,b=o.Sheets[y],a[y]=r.utils.sheet_to_html(b,{id:"xlsx-preview-table"})}catch(e){f=!0,p=e}finally{try{c||null==m.return||m.return()}finally{if(f)throw p}}if(e)return[2];return O(l),P(l[0]||""),L(a),v(!1),[3,5];case 4:if(g=x.sent(),e)return[2];return w(g.message||"Failed to render XLSX"),v(!1),[3,5];case 5:return[2]}})})(),function(){e=!0}},["string"==typeof o?o:null==o?void 0:o.url,s]),t().createElement("div",{style:{width:"100%",height:"100%",display:"flex",flexDirection:"column"}},h&&t().createElement(Y,{message:c("Loading preview...")}),b&&t().createElement(J,{message:c("Failed to load file preview")}),!h&&!b&&t().createElement(t().Fragment,null,k.length>1&&t().createElement("div",{style:{display:"flex",gap:0,borderBottom:"1px solid #e8e8e8",background:"#fafafa",padding:"0 8px",flexShrink:0,overflowX:"auto"}},k.map(function(e){return t().createElement("button",{key:e,onClick:function(){return P(e)},style:{padding:"8px 16px",border:"none",borderBottom:S===e?"2px solid #1890ff":"2px solid transparent",background:S===e?"#fff":"transparent",color:S===e?"#1890ff":"#666",fontWeight:S===e?600:400,cursor:"pointer",fontSize:13,whiteSpace:"nowrap",transition:"all 0.2s"}},e)})),t().createElement("div",{ref:p,style:{flex:1,overflow:"auto",padding:0},dangerouslySetInnerHTML:{__html:_[S]||""}}),t().createElement("style",null,"\n #xlsx-preview-table {\n border-collapse: collapse;\n width: 100%;\n font-size: 13px;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n }\n #xlsx-preview-table td,\n #xlsx-preview-table th {\n border: 1px solid #e8e8e8;\n padding: 6px 10px;\n text-align: left;\n white-space: nowrap;\n }\n #xlsx-preview-table tr:first-child td,\n #xlsx-preview-table tr:first-child th {\n background: #fafafa;\n font-weight: 600;\n position: sticky;\n top: 0;\n z-index: 1;\n }\n #xlsx-preview-table tr:nth-child(even) {\n background: #fafafa;\n }\n #xlsx-preview-table tr:hover {\n background: #f0f7ff;\n }\n ")))}var ee=function(o){return function(l){var u,c=l.open,s=l.onOpenChange,p=l.onClose,d=l.file,m=l.index,h=l.list,b=l.onSwitchIndex;l.onDownload;var g=(0,i.useAPIClient)(),w=a(),x=(0,e.useCallback)((u=f(function(e){var t,n,i;return E(this,function(o){switch(o.label){case 0:if(!(n=e||d))return[2];i=(null==(t=g.auth)?void 0:t.token)||"",o.label=1;case 1:return o.trys.push([1,3,,4]),[4,H(n,i)];case 2:return o.sent(),[3,4];case 3:return o.sent(),r.message.error(w("Failed to download file")),[3,4];case 4:return[2]}})}),function(e){return u.apply(this,arguments)}),[d,g,w]);if("boolean"!=typeof c)return t().createElement(o,y(v({},l),{onDownload:x}));var k=q(d),O="number"==typeof m&&!!b&&m>0,j="number"==typeof m&&!!b&&m<h.length-1;return t().createElement(r.Modal,{open:c,title:k,onCancel:function(){null==s||s(!1),null==p||p()},footer:t().createElement(r.Space,{size:14,style:{fontSize:"20px"}},t().createElement(n.LeftOutlined,{style:{cursor:O?"pointer":"not-allowed"},onClick:function(){return O&&(null==b?void 0:b(m-1))}}),t().createElement(n.RightOutlined,{style:{cursor:j?"pointer":"not-allowed"},onClick:function(){return j&&(null==b?void 0:b(m+1))}}),t().createElement(n.DownloadOutlined,{onClick:function(){return x(d)}})),width:"90vw",centered:!0},t().createElement("div",{style:{maxWidth:"100%",maxHeight:"calc(100vh - 256px)",height:"80vh",width:"100%",background:"white",display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",overflowY:"auto"}},t().createElement(o,y(v({},l),{onDownload:x}))))}};function et(n){var o,l,u=n.index,c=n.list,s=n.onSwitchIndex,p=a(),d=(0,i.useAPIClient)(),m=c[u],h=g((0,e.useState)(!1),2),v=h[0],y=h[1],b=(0,e.useCallback)((o=f(function(e){var t,n,i,o;return E(this,function(l){switch(l.label){case 0:null==e||null==(t=e.preventDefault)||t.call(e),null==e||null==(n=e.stopPropagation)||n.call(e),o=(null==(i=d.auth)?void 0:i.token)||"",y(!0),l.label=1;case 1:return l.trys.push([1,3,4,5]),[4,H(m,o)];case 2:return l.sent(),[3,5];case 3:return l.sent(),r.message.error(p("Failed to download file")),[3,5];case 4:return y(!1),[7];case 5:return[2]}})}),function(e){return o.apply(this,arguments)}),[m,d,p]),w=(0,e.useCallback)((l=f(function(e){var t,n,i,o,l,a,u;return E(this,function(c){switch(c.label){case 0:if(null==e||null==(t=e.preventDefault)||t.call(e),null==e||null==(n=e.stopPropagation)||n.call(e),o=(null==(i=d.auth)?void 0:i.token)||"",!(l=R(m)))return[2];c.label=1;case 1:return c.trys.push([1,3,,4]),[4,z(l,o)];case 2:return a=c.sent(),u=URL.createObjectURL(a),window.open(u),[3,4];case 3:return c.sent(),r.message.error(p("Failed to load file preview")),[3,4];case 4:return[2]}})}),function(e){return l.apply(this,arguments)}),[m,d,p]),x=(0,e.useCallback)(function(){s(null)},[s]),k=(0,e.useMemo)(function(){return I(m)?$:U(m)?K:D(m)?Q:B(m)?V:M(m)?Z:null},[m]),O=null!=k;return t().createElement(r.Modal,{open:null!=u,title:(null==m?void 0:m.title)||(null==m?void 0:m.filename)||(null==m?void 0:m.name)||"File",onCancel:x,footer:[O&&t().createElement(r.Button,{key:"open",onClick:w},p("Open in new window")),t().createElement(r.Button,{key:"download",onClick:b,loading:v},p("Download")),t().createElement(r.Button,{key:"close",onClick:x},p("Close"))].filter(Boolean),width:O?"85vw":520,centered:!0},t().createElement("div",{style:{maxWidth:"100%",maxHeight:O?"calc(100vh - 256px)":"auto",height:O?"70vh":"auto",width:"100%",background:"white",display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",overflowY:"auto"}},O?t().createElement(k,{file:m}):t().createElement(r.Alert,{type:"info",style:{width:"100%"},description:p("This file type cannot be previewed. Click Download to save the file."),showIcon:!0})))}function en(n){var o=n.file,l=(0,i.useAPIClient)(),u=a(),c=(0,e.useCallback)(f(function(){var e,t;return E(this,function(n){switch(n.label){case 0:t=(null==(e=l.auth)?void 0:e.token)||"",n.label=1;case 1:return n.trys.push([1,3,,4]),[4,H(o,t)];case 2:return n.sent(),[3,4];case 3:return n.sent(),r.message.error(u("Failed to download file")),[3,4];case 4:return[2]}})}),[o,l,u]);return t().createElement(r.Alert,{type:"info",style:{width:"100%"},description:t().createElement("span",null,u("This file type cannot be previewed. ")," ",t().createElement("a",{onClick:c,style:{textDecoration:"underline",cursor:"pointer"}},u("Download"))),showIcon:!0})}var er=function(e){var t;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function n(){var e,t;if(!(this instanceof n))throw TypeError("Cannot call a class as a function");return e=n,t=arguments,e=h(e),function(e,t){var n;if(t&&("object"==((n=t)&&"undefined"!=typeof Symbol&&n.constructor===Symbol?"symbol":typeof n)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,x()?Reflect.construct(e,t||[],h(this).constructor):e.apply(this,t))}return n.prototype=Object.create(e&&e.prototype,{constructor:{value:n,writable:!0,configurable:!0}}),e&&b(n,e),t=[{key:"load",value:function(){return f(function(){return E(this,function(e){return i.attachmentFileTypes.add({match:function(){return!0},Previewer:et}),o.filePreviewTypes.add({match:function(){return!0},Previewer:ee(en)}),o.filePreviewTypes.add({match:I,Previewer:ee($)}),o.filePreviewTypes.add({match:U,getThumbnailURL:function(e){return(null==e?void 0:e.url)||(null==e?void 0:e.preview)||null},Previewer:ee(K)}),o.filePreviewTypes.add({match:D,Previewer:ee(Q)}),o.filePreviewTypes.add({match:B,Previewer:ee(V)}),o.filePreviewTypes.add({match:M,Previewer:ee(Z)}),[2]})})()}}],function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(n.prototype,t),n}(w(i.Plugin)),ei=er}(),m}()});
10
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@nocobase/plugin-file-manager/client"),require("@nocobase/client"),require("react"),require("@ant-design/icons"),require("antd")):"function"==typeof define&&define.amd?define("plugin-file-preview-auth",["@nocobase/plugin-file-manager/client","@nocobase/client","react","@ant-design/icons","antd"],t):"object"==typeof exports?exports["plugin-file-preview-auth"]=t(require("@nocobase/plugin-file-manager/client"),require("@nocobase/client"),require("react"),require("@ant-design/icons"),require("antd")):e["plugin-file-preview-auth"]=t(e["@nocobase/plugin-file-manager/client"],e["@nocobase/client"],e.react,e["@ant-design/icons"],e.antd)}(self,function(e,t,n,r,i){return function(){var o,l,a,u,c,s,f={581:function(e){e.exports=function(e,t){return"undefined"!=typeof __deoptimization_sideEffect__&&__deoptimization_sideEffect__(e,t),t}},482:function(e){"use strict";e.exports=r},772:function(e){"use strict";e.exports=t},183:function(t){"use strict";t.exports=e},721:function(e){"use strict";e.exports=i},156:function(e){"use strict";e.exports=n}},p={};function d(e){var t=p[e];if(void 0!==t)return t.exports;var n=p[e]={exports:{}};return f[e](n,n.exports,d),n.exports}d.m=f,d.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return d.d(t,{a:t}),t},d.d=function(e,t){for(var n in t)d.o(t,n)&&!d.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},d.f={},d.e=function(e){return Promise.all(Object.keys(d.f).reduce(function(t,n){return d.f[n](e,t),t},[]))},d.u=function(e){return""+({395:"02dcfcac51f80d8d",463:"348b1a931814844c"})[e]+".js"},d.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),d.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o={},l="plugin-file-preview-auth:",d.l=function(e,t,n,r){if(o[e])return void o[e].push(t);if(void 0!==n)for(var i,a,u=document.getElementsByTagName("script"),c=0;c<u.length;c++){var s=u[c];if(s.getAttribute("src")==e||s.getAttribute("data-webpack")==l+n){i=s;break}}i||(a=!0,(i=document.createElement("script")).charset="utf-8",i.timeout=120,d.nc&&i.setAttribute("nonce",d.nc),i.setAttribute("data-webpack",l+n),i.src=e),o[e]=[t];var f=function(t,n){i.onerror=i.onload=null,clearTimeout(p);var r=o[e];if(delete o[e],i.parentNode&&i.parentNode.removeChild(i),r&&r.forEach(function(e){return e(n)}),t)return t(n)},p=setTimeout(f.bind(null,void 0,{type:"timeout",target:i}),12e4);i.onerror=f.bind(null,i.onerror),i.onload=f.bind(null,i.onload),a&&document.head.appendChild(i)},d.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(a=window.__webpack_public_path__||"/").endsWith("/")||(a+="/"),d.p=a+"static/plugins/plugin-file-preview-auth/dist/client/",u={909:0},d.f.j=function(e,t){var n=d.o(u,e)?u[e]:void 0;if(0!==n)if(n)t.push(n[2]);else{var r=new Promise(function(t,r){n=u[e]=[t,r]});t.push(n[2]=r);var i=d.p+d.u(e),o=Error();d.l(i,function(t){if(d.o(u,e)&&(0!==(n=u[e])&&(u[e]=void 0),n)){var r=t&&("load"===t.type?"missing":t.type),i=t&&t.target&&t.target.src;o.message="Loading chunk "+e+" failed.\n("+r+": "+i+")",o.name="ChunkLoadError",o.type=r,o.request=i,n[1](o)}},"chunk-"+e,e)}},c=function(e,t){var n,r,i=t[0],o=t[1],l=t[2],a=0;if(i.some(function(e){return 0!==u[e]})){for(n in o)d.o(o,n)&&(d.m[n]=o[n]);l&&l(d)}for(e&&e(t);a<i.length;a++)r=i[a],d.o(u,r)&&u[r]&&u[r][0](),u[r]=0},(s=self.webpackChunkplugin_file_preview_auth=self.webpackChunkplugin_file_preview_auth||[]).forEach(c.bind(null,0)),s.push=c.bind(null,s.push.bind(s));var m={};return!function(){"use strict";d.r(m),d.d(m,{default:function(){return ei},PluginFilePreviewAuthClient:function(){return er}});var e=d(156),t=d.n(e),n=d(482),r=d(721),i=d(772),o=d(183),l=JSON.parse('{"u2":"plugin-file-preview-auth"}');function a(){var e=(0,i.useApp)();return function(t){return e.i18n.t(t,{ns:[l.u2,"client"]})}}var u=d(581);function c(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function s(e,t,n,r,i,o,l){try{var a=e[o](l),u=a.value}catch(e){n(e);return}a.done?t(u):Promise.resolve(u).then(r,i)}function f(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var o=e.apply(t,n);function l(e){s(o,r,i,l,a,"next",e)}function a(e){s(o,r,i,l,a,"throw",e)}l(void 0)})}}function p(e,t,n){return(p=x()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&b(i,n.prototype),i}).apply(null,arguments)}function h(e){return(h=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function v(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}function y(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n.push.apply(n,r)}return n})(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}function b(e,t){return(b=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function g(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,i=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=i){var o=[],l=!0,a=!1;try{for(i=i.call(e);!(l=(n=i.next()).done)&&(o.push(n.value),!t||o.length!==t);l=!0);}catch(e){a=!0,r=e}finally{try{l||null==i.return||i.return()}finally{if(a)throw r}}return o}}(e,t)||function(e,t){if(e){if("string"==typeof e)return c(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return c(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function w(e){var t="function"==typeof Map?new Map:void 0;return(w=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return p(e,arguments,h(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),b(n,e)})(e)}function x(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(x=function(){return!!e})()}function k(e,t){var n,r,i,o,l={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){var u=[o,a];if(n)throw TypeError("Generator is already executing.");for(;l;)try{if(n=1,r&&(i=2&u[0]?r.return:u[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,u[1])).done)return i;switch(r=0,i&&(u=[2&u[0],i.value]),u[0]){case 0:case 1:i=u;break;case 4:return l.label++,{value:u[1],done:!1};case 5:l.label++,r=u[1],u=[0];continue;case 7:u=l.ops.pop(),l.trys.pop();continue;default:if(!(i=(i=l.trys).length>0&&i[i.length-1])&&(6===u[0]||2===u[0])){l=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){l.label=u[1];break}if(6===u[0]&&l.label<i[1]){l.label=i[1],i=u;break}if(i&&l.label<i[2]){l.label=i[2],l.ops.push(u);break}i[2]&&l.ops.pop(),l.trys.pop();continue}u=t.call(e,l)}catch(e){u=[6,e],r=0}finally{n=i=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}var E=["application/pdf"],O=["image/png","image/jpeg","image/gif","image/webp","image/svg+xml","image/bmp"],j=["text/plain","text/csv","text/html","text/css","text/javascript","application/json","application/xml","text/xml","text/yaml","application/x-yaml"],S=["application/vnd.openxmlformats-officedocument.wordprocessingml.document"],P=["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.ms-excel"],C=["pdf"],_=["png","jpg","jpeg","gif","webp","svg","bmp"],L=["txt","csv","html","css","js","json","xml","log","md","yaml","yml","xaml"],T=["docx"],F=["xlsx","xls"],A=function(e){var t=("string"==typeof e?e:(null==e?void 0:e.extname)||(null==e?void 0:e.name)||(null==e?void 0:e.filename)||(null==e?void 0:e.url)||"").split("?")[0].split("#")[0],n=t.lastIndexOf(".");return -1!==n?t.slice(n+1).toLowerCase().replace(/^\./,""):""},R=function(e){var t="string"==typeof e?e:null==e?void 0:e.url;return t?t.startsWith("https://")||t.startsWith("http://")?t:"".concat(location.origin,"/").concat(t.replace(/^\//,"")):""},I=function(e){if((null==e?void 0:e.mimetype)&&E.includes(e.mimetype))return!0;var t=A(e);return!!t&&C.includes(t)},U=function(e){if((null==e?void 0:e.mimetype)&&O.includes(e.mimetype)||(null==e?void 0:e.mimetype)&&(0,i.matchMimetype)(e,"image/*"))return!0;var t=A(e);return!!t&&_.includes(t)},D=function(e){if((null==e?void 0:e.mimetype)&&j.includes(e.mimetype))return!0;var t=A(e);return!!t&&L.includes(t)},B=function(e){if((null==e?void 0:e.mimetype)&&S.includes(e.mimetype))return!0;var t=A(e);return!!t&&T.includes(t)},M=function(e){if((null==e?void 0:e.mimetype)&&P.includes(e.mimetype))return!0;var t=A(e);return!!t&&F.includes(t)},q=function(e){return e?e.title&&e.extname?"".concat(e.title).concat(e.extname):e.filename||e.name||e.title||"download":"download"};function z(e,t){return N.apply(this,arguments)}function N(){return(N=f(function(e,t){var n,r;return k(this,function(i){switch(i.label){case 0:return n={},t&&(n.Authorization="Bearer ".concat(t)),[4,fetch(e,{method:"GET",headers:n,credentials:"include"})];case 1:if(!(r=i.sent()).ok)throw Error("Failed to fetch file: ".concat(r.status," ").concat(r.statusText));return[2,r.blob()]}})})).apply(this,arguments)}function W(){return(W=f(function(e,t){var n,r;return k(this,function(i){switch(i.label){case 0:return n={},t&&(n.Authorization="Bearer ".concat(t)),[4,fetch(e,{method:"GET",headers:n,credentials:"include"})];case 1:if(!(r=i.sent()).ok)throw Error("Failed to fetch file: ".concat(r.status," ").concat(r.statusText));return[2,r.text()]}})})).apply(this,arguments)}function H(e,t){return X.apply(this,arguments)}function X(){return(X=f(function(e,t){var n,r,i,o,l;return k(this,function(a){switch(a.label){case 0:if(!(n=R(e)))return[2];return[4,z(n,t)];case 1:return r=a.sent(),i=q(e),(o=document.createElement("a")).href=l=URL.createObjectURL(r),o.download=i,document.body.appendChild(o),o.click(),document.body.removeChild(o),setTimeout(function(){return URL.revokeObjectURL(l)},1e3),[2]}})})).apply(this,arguments)}function G(t,n){var r=g((0,e.useState)(null),2),i=r[0],o=r[1],l=g((0,e.useState)(!0),2),a=l[0],u=l[1],c=g((0,e.useState)(null),2),s=c[0],f=c[1],p=(0,e.useRef)(null);return(0,e.useEffect)(function(){var e=!1,r=R(t);if(!r){u(!1),f("No file URL");return}return u(!0),f(null),z(r,n).then(function(t){if(!e){var n=URL.createObjectURL(t);p.current=n,o(n),u(!1)}}).catch(function(t){e||(f(t.message||"Failed to load"),u(!1))}),function(){e=!0,p.current&&(URL.revokeObjectURL(p.current),p.current=null)}},["string"==typeof t?t:null==t?void 0:t.url,n]),{blobUrl:i,loading:a,error:s}}function Y(e){var n=e.message;return t().createElement("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%",width:"100%"}},t().createElement(r.Spin,{tip:n}))}function J(e){var n=e.message;return t().createElement("div",{style:{padding:20,textAlign:"center",color:"#ff4d4f"}},n)}function $(e){var n,r=e.file,o=(0,i.useAPIClient)(),l=a(),u=G(r,(null==(n=o.auth)?void 0:n.token)||""),c=u.blobUrl,s=u.loading,f=u.error;return s?t().createElement(Y,{message:l("Loading preview...")}):f||!c?t().createElement(J,{message:l("Failed to load file preview")}):t().createElement("iframe",{src:c,width:"100%",height:"100%",style:{border:"none"}})}function K(e){var n,r=e.file,o=(0,i.useAPIClient)(),l=a(),u=G(r,(null==(n=o.auth)?void 0:n.token)||""),c=u.blobUrl,s=u.loading,f=u.error;return s?t().createElement(Y,{message:l("Loading preview...")}):f||!c?t().createElement(J,{message:l("Failed to load file preview")}):t().createElement("img",{src:c,style:{maxWidth:"100%",maxHeight:"100%",objectFit:"contain"},alt:(null==r?void 0:r.title)||(null==r?void 0:r.filename)||""})}function Q(n){var r,o,l,u,c,s,f,p,d,m,h=n.file,v=(0,i.useAPIClient)(),y=a(),b=(null==(m=v.auth)?void 0:m.token)||"",w=(o=(r=g((0,e.useState)(null),2))[0],l=r[1],c=(u=g((0,e.useState)(!0),2))[0],s=u[1],p=(f=g((0,e.useState)(null),2))[0],d=f[1],(0,e.useEffect)(function(){var e=!1,t=R(h);if(!t){s(!1),d("No file URL");return}return s(!0),d(null),(function(e,t){return W.apply(this,arguments)})(t,b).then(function(t){e||(l(t),s(!1))}).catch(function(t){e||(d(t.message||"Failed to load"),s(!1))}),function(){e=!0}},["string"==typeof h?h:null==h?void 0:h.url,b]),{text:o,loading:c,error:p}),x=w.text,k=w.loading,E=w.error;return k?t().createElement(Y,{message:y("Loading preview...")}):E||null===x?t().createElement(J,{message:y("Failed to load file preview")}):t().createElement("pre",{style:{width:"100%",height:"100%",overflow:"auto",padding:16,margin:0,fontSize:13,lineHeight:1.6,whiteSpace:"pre-wrap",wordWrap:"break-word",background:"#f5f5f5",border:"none"}},x)}function V(n){var r,o=n.file,l=(0,i.useAPIClient)(),c=a(),s=(null==(r=l.auth)?void 0:r.token)||"",p=(0,e.useRef)(null),m=g((0,e.useState)(!0),2),h=m[0],v=m[1],y=g((0,e.useState)(null),2),b=y[0],w=y[1];return(0,e.useEffect)(function(){var e=!1,t=R(o);if(!t||!p.current){v(!1),w("No file URL");return}return v(!0),w(null),f(function(){var n,r,i;return k(this,function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),[4,z(t,s)];case 1:if(n=o.sent(),e)return[2];return[4,u("imported_-1dm6lbf_component",d.e("395").then(d.bind(d,835)))];case 2:if(r=o.sent(),e||!p.current)return[2];return p.current.innerHTML="",[4,r.renderAsync(n,p.current,void 0,{className:"docx-preview-wrapper",inWrapper:!0,ignoreWidth:!1,ignoreHeight:!1,ignoreFonts:!1,breakPages:!0,ignoreLastRenderedPageBreak:!0,experimental:!1,trimXmlDeclaration:!0,useBase64URL:!0,renderHeaders:!0,renderFooters:!0,renderFootnotes:!0,renderEndnotes:!0})];case 3:return o.sent(),v(!1),[3,5];case 4:if(i=o.sent(),e)return[2];return w(i.message||"Failed to render DOCX"),v(!1),[3,5];case 5:return[2]}})})(),function(){e=!0}},["string"==typeof o?o:null==o?void 0:o.url,s]),t().createElement("div",{style:{width:"100%",height:"100%",position:"relative"}},h&&t().createElement(Y,{message:c("Loading preview...")}),b&&t().createElement(J,{message:c("Failed to load file preview")}),t().createElement("div",{ref:p,style:{width:"100%",height:"100%",overflow:"auto",display:h||b?"none":"block"}}))}function Z(n){var r,o=n.file,l=(0,i.useAPIClient)(),c=a(),s=(null==(r=l.auth)?void 0:r.token)||"",p=(0,e.useRef)(null),m=g((0,e.useState)(!0),2),h=m[0],v=m[1],y=g((0,e.useState)(null),2),b=y[0],w=y[1],x=g((0,e.useState)([]),2),E=x[0],O=x[1],j=g((0,e.useState)(""),2),S=j[0],P=j[1],C=g((0,e.useState)({}),2),_=C[0],L=C[1];return(0,e.useEffect)(function(){var e=!1,t=R(o);if(!t){v(!1),w("No file URL");return}return v(!0),w(null),f(function(){var n,r,i,o,l,a,c,f,p,m,h,y,b,g;return k(this,function(x){switch(x.label){case 0:return x.trys.push([0,4,,5]),[4,z(t,s)];case 1:if(n=x.sent(),e)return[2];return[4,u("imported_-1lj2ifg_component",d.e("463").then(d.bind(d,312)))];case 2:if(r=x.sent(),e)return[2];return[4,n.arrayBuffer()];case 3:if(i=x.sent(),e)return[2];l=(o=r.read(i,{type:"array"})).SheetNames,a={},c=!0,f=!1,p=void 0;try{for(m=l[Symbol.iterator]();!(c=(h=m.next()).done);c=!0)y=h.value,b=o.Sheets[y],a[y]=r.utils.sheet_to_html(b,{id:"xlsx-preview-table"})}catch(e){f=!0,p=e}finally{try{c||null==m.return||m.return()}finally{if(f)throw p}}if(e)return[2];return O(l),P(l[0]||""),L(a),v(!1),[3,5];case 4:if(g=x.sent(),e)return[2];return w(g.message||"Failed to render XLSX"),v(!1),[3,5];case 5:return[2]}})})(),function(){e=!0}},["string"==typeof o?o:null==o?void 0:o.url,s]),t().createElement("div",{style:{width:"100%",height:"100%",display:"flex",flexDirection:"column"}},h&&t().createElement(Y,{message:c("Loading preview...")}),b&&t().createElement(J,{message:c("Failed to load file preview")}),!h&&!b&&t().createElement(t().Fragment,null,E.length>1&&t().createElement("div",{style:{display:"flex",gap:0,borderBottom:"1px solid #e8e8e8",background:"#fafafa",padding:"0 8px",flexShrink:0,overflowX:"auto"}},E.map(function(e){return t().createElement("button",{key:e,onClick:function(){return P(e)},style:{padding:"8px 16px",border:"none",borderBottom:S===e?"2px solid #1890ff":"2px solid transparent",background:S===e?"#fff":"transparent",color:S===e?"#1890ff":"#666",fontWeight:S===e?600:400,cursor:"pointer",fontSize:13,whiteSpace:"nowrap",transition:"all 0.2s"}},e)})),t().createElement("div",{ref:p,style:{flex:1,overflow:"auto",padding:0},dangerouslySetInnerHTML:{__html:_[S]||""}}),t().createElement("style",null,"\n #xlsx-preview-table {\n border-collapse: collapse;\n width: 100%;\n font-size: 13px;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n }\n #xlsx-preview-table td,\n #xlsx-preview-table th {\n border: 1px solid #e8e8e8;\n padding: 6px 10px;\n text-align: left;\n max-width: 33vw;\n white-space: normal;\n word-break: break-word;\n }\n #xlsx-preview-table tr:first-child td,\n #xlsx-preview-table tr:first-child th {\n background: #fafafa;\n font-weight: 600;\n position: sticky;\n top: 0;\n z-index: 1;\n }\n #xlsx-preview-table tr:nth-child(even) {\n background: #fafafa;\n }\n #xlsx-preview-table tr:hover {\n background: #f0f7ff;\n }\n ")))}var ee=function(o){return function(l){var u,c=l.open,s=l.onOpenChange,p=l.onClose,d=l.file,m=l.index,h=l.list,b=l.onSwitchIndex;l.onDownload;var g=(0,i.useAPIClient)(),w=a(),x=(0,e.useCallback)((u=f(function(e){var t,n,i;return k(this,function(o){switch(o.label){case 0:if(!(n=e||d))return[2];i=(null==(t=g.auth)?void 0:t.token)||"",o.label=1;case 1:return o.trys.push([1,3,,4]),[4,H(n,i)];case 2:return o.sent(),[3,4];case 3:return o.sent(),r.message.error(w("Failed to download file")),[3,4];case 4:return[2]}})}),function(e){return u.apply(this,arguments)}),[d,g,w]);if("boolean"!=typeof c)return t().createElement(o,y(v({},l),{onDownload:x}));var E=q(d),O="number"==typeof m&&!!b&&m>0,j="number"==typeof m&&!!b&&m<h.length-1;return t().createElement(r.Modal,{open:c,title:E,onCancel:function(){null==s||s(!1),null==p||p()},footer:t().createElement(r.Space,{size:14,style:{fontSize:"20px"}},t().createElement(n.LeftOutlined,{style:{cursor:O?"pointer":"not-allowed"},onClick:function(){return O&&(null==b?void 0:b(m-1))}}),t().createElement(n.RightOutlined,{style:{cursor:j?"pointer":"not-allowed"},onClick:function(){return j&&(null==b?void 0:b(m+1))}}),t().createElement(n.DownloadOutlined,{onClick:function(){return x(d)}})),width:"90vw",centered:!0},t().createElement("div",{style:{maxWidth:"100%",maxHeight:"calc(100vh - 256px)",height:"80vh",width:"100%",background:"white",display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",overflowY:"auto"}},t().createElement(o,y(v({},l),{onDownload:x}))))}};function et(n){var o,l,u=n.index,c=n.list,s=n.onSwitchIndex,p=a(),d=(0,i.useAPIClient)(),m=c[u],h=g((0,e.useState)(!1),2),v=h[0],y=h[1],b=(0,e.useCallback)((o=f(function(e){var t,n,i,o;return k(this,function(l){switch(l.label){case 0:null==e||null==(t=e.preventDefault)||t.call(e),null==e||null==(n=e.stopPropagation)||n.call(e),o=(null==(i=d.auth)?void 0:i.token)||"",y(!0),l.label=1;case 1:return l.trys.push([1,3,4,5]),[4,H(m,o)];case 2:return l.sent(),[3,5];case 3:return l.sent(),r.message.error(p("Failed to download file")),[3,5];case 4:return y(!1),[7];case 5:return[2]}})}),function(e){return o.apply(this,arguments)}),[m,d,p]),w=(0,e.useCallback)((l=f(function(e){var t,n,i,o,l,a,u;return k(this,function(c){switch(c.label){case 0:if(null==e||null==(t=e.preventDefault)||t.call(e),null==e||null==(n=e.stopPropagation)||n.call(e),o=(null==(i=d.auth)?void 0:i.token)||"",!(l=R(m)))return[2];c.label=1;case 1:return c.trys.push([1,3,,4]),[4,z(l,o)];case 2:return a=c.sent(),u=URL.createObjectURL(a),window.open(u),[3,4];case 3:return c.sent(),r.message.error(p("Failed to load file preview")),[3,4];case 4:return[2]}})}),function(e){return l.apply(this,arguments)}),[m,d,p]),x=(0,e.useCallback)(function(){s(null)},[s]),E=(0,e.useMemo)(function(){return I(m)?$:U(m)?K:D(m)?Q:B(m)?V:M(m)?Z:null},[m]),O=null!=E;return t().createElement(r.Modal,{open:null!=u,title:(null==m?void 0:m.title)||(null==m?void 0:m.filename)||(null==m?void 0:m.name)||"File",onCancel:x,footer:[O&&t().createElement(r.Button,{key:"open",onClick:w},p("Open in new window")),t().createElement(r.Button,{key:"download",onClick:b,loading:v},p("Download")),t().createElement(r.Button,{key:"close",onClick:x},p("Close"))].filter(Boolean),width:O?"85vw":520,centered:!0},t().createElement("div",{style:{maxWidth:"100%",maxHeight:O?"calc(100vh - 256px)":"auto",height:O?"70vh":"auto",width:"100%",background:"white",display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",overflowY:"auto"}},O?t().createElement(E,{file:m}):t().createElement(r.Alert,{type:"info",style:{width:"100%"},description:p("This file type cannot be previewed. Click Download to save the file."),showIcon:!0})))}function en(n){var o=n.file,l=(0,i.useAPIClient)(),u=a(),c=(0,e.useCallback)(f(function(){var e,t;return k(this,function(n){switch(n.label){case 0:t=(null==(e=l.auth)?void 0:e.token)||"",n.label=1;case 1:return n.trys.push([1,3,,4]),[4,H(o,t)];case 2:return n.sent(),[3,4];case 3:return n.sent(),r.message.error(u("Failed to download file")),[3,4];case 4:return[2]}})}),[o,l,u]);return t().createElement(r.Alert,{type:"info",style:{width:"100%"},description:t().createElement("span",null,u("This file type cannot be previewed. ")," ",t().createElement("a",{onClick:c,style:{textDecoration:"underline",cursor:"pointer"}},u("Download"))),showIcon:!0})}var er=function(e){var t;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function n(){var e,t;if(!(this instanceof n))throw TypeError("Cannot call a class as a function");return e=n,t=arguments,e=h(e),function(e,t){var n;if(t&&("object"==((n=t)&&"undefined"!=typeof Symbol&&n.constructor===Symbol?"symbol":typeof n)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,x()?Reflect.construct(e,t||[],h(this).constructor):e.apply(this,t))}return n.prototype=Object.create(e&&e.prototype,{constructor:{value:n,writable:!0,configurable:!0}}),e&&b(n,e),t=[{key:"load",value:function(){return f(function(){return k(this,function(e){return i.attachmentFileTypes.add({match:function(){return!0},Previewer:et}),o.filePreviewTypes.add({match:function(){return!0},Previewer:ee(en)}),o.filePreviewTypes.add({match:I,Previewer:ee($)}),o.filePreviewTypes.add({match:U,getThumbnailURL:function(e){return(null==e?void 0:e.url)||(null==e?void 0:e.preview)||null},Previewer:ee(K)}),o.filePreviewTypes.add({match:D,Previewer:ee(Q)}),o.filePreviewTypes.add({match:B,Previewer:ee(V)}),o.filePreviewTypes.add({match:M,Previewer:ee(Z)}),[2]})})()}}],function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(n.prototype,t),n}(w(i.Plugin)),ei=er}(),m}()});
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ export declare function useT(): (str: string) => string;
10
+ export declare function tStr(key: string): string;
@@ -11,7 +11,8 @@ module.exports = {
11
11
  "react": "18.2.0",
12
12
  "@ant-design/icons": "5.6.1",
13
13
  "antd": "5.24.2",
14
- "@nocobase/client": "2.0.15",
15
- "@nocobase/plugin-file-manager": "2.0.15",
16
- "@nocobase/server": "2.0.15"
14
+ "@nocobase/client": "2.0.32",
15
+ "@nocobase/plugin-file-manager": "2.0.32",
16
+ "@nocobase/actions": "2.0.32",
17
+ "@nocobase/server": "2.0.32"
17
18
  };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ export * from './server';
10
+ export { default } from './server';
@@ -0,0 +1,60 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import type { Context } from '@nocobase/actions';
10
+ interface AttachmentLike {
11
+ id?: string | number;
12
+ filename?: string;
13
+ name?: string;
14
+ mimetype?: string;
15
+ extname?: string;
16
+ url?: string;
17
+ storageId?: number;
18
+ size?: number;
19
+ meta?: Record<string, any>;
20
+ [key: string]: any;
21
+ }
22
+ interface InternalParseResult {
23
+ text: string;
24
+ handled: boolean;
25
+ }
26
+ export interface InternalParserHandler {
27
+ name: string;
28
+ supports(attachment: AttachmentLike): boolean;
29
+ parse(attachment: AttachmentLike, ctx: Context): Promise<InternalParseResult>;
30
+ }
31
+ /**
32
+ * Server-side Excel parser handler.
33
+ *
34
+ * Uses SheetJS (xlsx) — the same library already bundled by this plugin for
35
+ * client-side XLSX preview — to extract plain text from .xlsx/.xls files on
36
+ * the server.
37
+ *
38
+ * Each worksheet is converted to CSV and separated by a section header so LLMs
39
+ * can distinguish sheet boundaries:
40
+ *
41
+ * === Sheet: Sheet1 ===
42
+ * col1,col2,col3
43
+ * val1,val2,val3
44
+ *
45
+ * === Sheet: Sheet2 ===
46
+ * ...
47
+ *
48
+ * This handler is registered into plugin-document-parser's InternalParserRegistry
49
+ * by PluginFilePreviewAuthServer with `prepend: true` so it takes priority over
50
+ * any other handlers that might be registered later.
51
+ *
52
+ * File bytes are fetched via plugin-document-parser's public `fetchFileBuffer`
53
+ * helper, which transparently handles both S3 URLs and local file paths.
54
+ */
55
+ export declare class ExcelParserHandler implements InternalParserHandler {
56
+ readonly name = "file-preview-auth-excel-parser";
57
+ supports(attachment: AttachmentLike): boolean;
58
+ parse(attachment: AttachmentLike, ctx: Context): Promise<InternalParseResult>;
59
+ }
60
+ export {};
@@ -0,0 +1,96 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
27
+ };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+ var excel_parser_handler_exports = {};
38
+ __export(excel_parser_handler_exports, {
39
+ ExcelParserHandler: () => ExcelParserHandler
40
+ });
41
+ module.exports = __toCommonJS(excel_parser_handler_exports);
42
+ var XLSX = __toESM(require("xlsx"));
43
+ const XLSX_EXTNAMES = /* @__PURE__ */ new Set([".xlsx", ".xls"]);
44
+ const XLSX_MIMETYPES = /* @__PURE__ */ new Set([
45
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
46
+ "application/vnd.ms-excel"
47
+ ]);
48
+ function resolveExtname(attachment) {
49
+ if (attachment.extname) return attachment.extname.toLowerCase();
50
+ const name = attachment.filename ?? attachment.name ?? "";
51
+ const idx = name.lastIndexOf(".");
52
+ return idx >= 0 ? name.slice(idx).toLowerCase() : "";
53
+ }
54
+ class ExcelParserHandler {
55
+ name = "file-preview-auth-excel-parser";
56
+ supports(attachment) {
57
+ if (attachment.mimetype && XLSX_MIMETYPES.has(attachment.mimetype)) return true;
58
+ return XLSX_EXTNAMES.has(resolveExtname(attachment));
59
+ }
60
+ async parse(attachment, ctx) {
61
+ var _a, _b, _c;
62
+ const docParserPlugin = (_a = ctx.app.pm) == null ? void 0 : _a.get("@nocobase/plugin-document-parser");
63
+ if (!(docParserPlugin == null ? void 0 : docParserPlugin.fetchFileBuffer)) {
64
+ (_c = (_b = ctx.log) == null ? void 0 : _b.warn) == null ? void 0 : _c.call(_b, "[ExcelParser] plugin-document-parser not available \u2014 cannot fetch file bytes");
65
+ return { text: "", handled: false };
66
+ }
67
+ const { buffer } = await docParserPlugin.fetchFileBuffer(ctx, attachment);
68
+ const workbook = XLSX.read(buffer, { type: "buffer" });
69
+ const parts = [];
70
+ for (const sheetName of workbook.SheetNames) {
71
+ const sheet = workbook.Sheets[sheetName];
72
+ const rows = XLSX.utils.sheet_to_json(sheet, { header: 1, defval: "" });
73
+ while (rows.length > 0 && rows[rows.length - 1].every((c) => String(c).trim() === "")) {
74
+ rows.pop();
75
+ }
76
+ if (rows.length === 0) continue;
77
+ const escape = (v) => String(v ?? "").replace(/\|/g, "\\|").replace(/\n/g, " ");
78
+ const toRow = (cells, colCount2) => {
79
+ const padded = Array.from({ length: colCount2 }, (_, i) => escape(cells[i] ?? ""));
80
+ return `| ${padded.join(" | ")} |`;
81
+ };
82
+ const colCount = Math.max(...rows.map((r) => r.length));
83
+ const header = toRow(rows[0], colCount);
84
+ const separator = `| ${Array(colCount).fill("---").join(" | ")} |`;
85
+ const body = rows.slice(1).map((r) => toRow(r, colCount));
86
+ parts.push(`### Sheet: ${sheetName}
87
+
88
+ ${[header, separator, ...body].join("\n")}`);
89
+ }
90
+ return { text: parts.join("\n\n"), handled: true };
91
+ }
92
+ }
93
+ // Annotate the CommonJS export names for ESM import in node:
94
+ 0 && (module.exports = {
95
+ ExcelParserHandler
96
+ });
@@ -0,0 +1,9 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ export { default } from './plugin';
@@ -0,0 +1,19 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import { Plugin } from '@nocobase/server';
10
+ export declare class PluginFilePreviewAuthServer extends Plugin {
11
+ load(): Promise<void>;
12
+ /**
13
+ * Register Excel handler into plugin-document-parser's InternalParserRegistry.
14
+ * Uses prepend:true so SheetJS takes priority over the AI-loader fallback.
15
+ * Silent no-op when plugin-document-parser is not loaded.
16
+ */
17
+ private registerExcelParser;
18
+ }
19
+ export default PluginFilePreviewAuthServer;
@@ -31,20 +31,28 @@ __export(plugin_exports, {
31
31
  });
32
32
  module.exports = __toCommonJS(plugin_exports);
33
33
  var import_server = require("@nocobase/server");
34
+ var import_excel_parser_handler = require("./excel-parser-handler");
34
35
  class PluginFilePreviewAuthServer extends import_server.Plugin {
35
- async afterAdd() {
36
- }
37
- async beforeLoad() {
38
- }
39
36
  async load() {
40
- }
41
- async install() {
42
- }
43
- async afterEnable() {
44
- }
45
- async afterDisable() {
46
- }
47
- async remove() {
37
+ this.registerExcelParser();
38
+ }
39
+ /**
40
+ * Register Excel handler into plugin-document-parser's InternalParserRegistry.
41
+ * Uses prepend:true so SheetJS takes priority over the AI-loader fallback.
42
+ * Silent no-op when plugin-document-parser is not loaded.
43
+ */
44
+ registerExcelParser() {
45
+ const docParserPlugin = this.pm.get("@nocobase/plugin-document-parser");
46
+ if (!(docParserPlugin == null ? void 0 : docParserPlugin.internalParserRegistry)) {
47
+ this.log.debug("[FilePreviewAuth] plugin-document-parser not found \u2014 Excel parser registration skipped");
48
+ return;
49
+ }
50
+ try {
51
+ docParserPlugin.internalParserRegistry.register(new import_excel_parser_handler.ExcelParserHandler(), { prepend: true });
52
+ this.log.info("[FilePreviewAuth] Excel parser handler registered into plugin-document-parser");
53
+ } catch (err) {
54
+ this.log.warn(`[FilePreviewAuth] Excel parser registration skipped: ${err}`);
55
+ }
48
56
  }
49
57
  }
50
58
  var plugin_default = PluginFilePreviewAuthServer;
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "description": "Preview PDF, image, and text files with Bearer token authentication via blob URLs.",
7
7
  "description.vi-VN": "Xem trước file PDF, hình ảnh và văn bản với xác thực Bearer token qua blob URL.",
8
8
  "description.zh-CN": "通过 Bearer 令牌认证和 Blob URL 预览 PDF、图片和文本文件。",
9
- "version": "1.1.0",
9
+ "version": "1.1.2",
10
10
  "main": "dist/server/index.js",
11
11
  "peerDependencies": {
12
12
  "@nocobase/client": "2.x",
Binary file