plugin-file-preview-auth 1.3.1 → 1.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.
@@ -28,6 +28,11 @@ export declare function createFilePreviewWorkContext(file: any): {
28
28
  size: any;
29
29
  path: any;
30
30
  storageId: any;
31
+ storage_id: any;
32
+ storageType: any;
33
+ storageName: any;
34
+ storage: any;
35
+ collectionName: any;
31
36
  };
32
37
  };
33
38
  };
@@ -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-ai/client"),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-ai/client","@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-ai/client"),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-ai/client"],e["@nocobase/plugin-file-manager/client"],e["@nocobase/client"],e.react,e["@ant-design/icons"],e.antd)}(self,function(e,t,n,r,i,l){return function(){var o,a,u,c,s,f,d={41:function(e){e.exports=function(e,t){return"undefined"!=typeof __deoptimization_sideEffect__&&__deoptimization_sideEffect__(e,t),t}},482:function(e){"use strict";e.exports=i},772:function(e){"use strict";e.exports=n},645:function(t){"use strict";t.exports=e},183:function(e){"use strict";e.exports=t},721:function(e){"use strict";e.exports=l},156:function(e){"use strict";e.exports=r}},p={};function m(e){var t=p[e];if(void 0!==t)return t.exports;var n=p[e]={exports:{}};return d[e](n,n.exports,m),n.exports}m.m=d,m.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return m.d(t,{a:t}),t},m.d=function(e,t){for(var n in t)m.o(t,n)&&!m.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},m.f={},m.e=function(e){return Promise.all(Object.keys(m.f).reduce(function(t,n){return m.f[n](e,t),t},[]))},m.u=function(e){return""+e+"."+({166:"17caa11c2ba40313",351:"0f0ce45c92425c8f",374:"96762d13b15e7467",514:"2a8b6aa0d2fcd4b2"})[e]+".js"},m.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),m.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o={},a="plugin-file-preview-auth:",m.l=function(e,t,n,r){if(o[e])return void o[e].push(t);if(void 0!==n)for(var i,l,u=document.getElementsByTagName("script"),c=0;c<u.length;c++){var s=u[c];if(s.getAttribute("src")==e||s.getAttribute("data-webpack")==a+n){i=s;break}}i||(l=!0,(i=document.createElement("script")).charset="utf-8",i.timeout=120,m.nc&&i.setAttribute("nonce",m.nc),i.setAttribute("data-webpack",a+n),i.src=e),o[e]=[t];var f=function(t,n){i.onerror=i.onload=null,clearTimeout(d);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)},d=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),l&&document.head.appendChild(i)},m.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(u=window.__webpack_public_path__||"/").endsWith("/")||(u+="/"),m.p=u+"static/plugins/plugin-file-preview-auth/dist/client/",c={909:0},m.f.j=function(e,t){var n=m.o(c,e)?c[e]:void 0;if(0!==n)if(n)t.push(n[2]);else{var r=new Promise(function(t,r){n=c[e]=[t,r]});t.push(n[2]=r);var i=m.p+m.u(e),l=Error();m.l(i,function(t){if(m.o(c,e)&&(0!==(n=c[e])&&(c[e]=void 0),n)){var r=t&&("load"===t.type?"missing":t.type),i=t&&t.target&&t.target.src;l.message="Loading chunk "+e+" failed.\n("+r+": "+i+")",l.name="ChunkLoadError",l.type=r,l.request=i,n[1](l)}},"chunk-"+e,e)}},s=function(e,t){var n,r,i=t[0],l=t[1],o=t[2],a=0;if(i.some(function(e){return 0!==c[e]})){for(n in l)m.o(l,n)&&(m.m[n]=l[n]);o&&o(m)}for(e&&e(t);a<i.length;a++)r=i[a],m.o(c,r)&&c[r]&&c[r][0](),c[r]=0},(f=self.webpackChunkplugin_file_preview_auth=self.webpackChunkplugin_file_preview_auth||[]).forEach(s.bind(null,0)),f.push=s.bind(null,f.push.bind(f));var v={};return!function(){"use strict";m.r(v),m.d(v,{default:function(){return eR},PluginFilePreviewAuthClient:function(){return eA}});var e=m(156),t=m.n(e),n=m(482),r=m(721),i=m(772),l=m(183),o=JSON.parse('{"u2":"plugin-file-preview-auth"}');function a(){var e=(0,i.useApp)();return function(t){return e.i18n.t(t,{ns:[o.u2,"client"]})}}var u=m(645);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,l,o){try{var a=e[l](o),u=a.value}catch(e){n(e);return}a.done?t(u):Promise.resolve(u).then(r,i)}function f(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)}}function d(e){return(d=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function p(e,t){return(p=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function h(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 l=[],o=!0,a=!1;try{for(i=i.call(e);!(o=(n=i.next()).done)&&(l.push(n.value),!t||l.length!==t);o=!0);}catch(e){a=!0,r=e}finally{try{o||null==i.return||i.return()}finally{if(a)throw r}}return l}}(e,t)||g(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 y(e){return function(e){if(Array.isArray(e))return c(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||g(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(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)}}function b(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(b=function(){return!!e})()}var w="file-preview",x="plugin-file-preview-auth.aiEmployee";function E(e){return e?e.title&&e.extname?"".concat(e.title).concat(e.extname):e.filename||e.name||e.title||"file":"file"}var k=function(e){var t,n;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function r(e){var t,n,i;if(!(this instanceof r))throw TypeError("Cannot call a class as a function");return n=r,i=[e],n=d(n),(t=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,b()?Reflect.construct(n,i||[],d(this).constructor):n.apply(this,i))).state={hasError:!1},t}return r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),e&&p(r,e),n=[{key:"getDerivedStateFromError",value:function(){return{hasError:!0}}}],t=[{key:"render",value:function(){return this.state.hasError?null:this.props.children}}],f(r.prototype,t),n&&f(r,n),r}(t().Component),S=function(i){var l,o,c=i.file,f=a(),d=(0,u.useAIConfigRepository)(),p=(0,u.useChatBoxActions)().triggerTask,m=h((0,e.useState)([]),2),v=m[0],g=m[1],b=h((0,e.useState)(!1),2),k=b[0],S=b[1],C=h((0,e.useState)(!1),2),O=C[0],P=C[1];(0,e.useEffect)(function(){var e=!1;if(null==d?void 0:d.getAIEmployees){var t=d.aiEmployees||[];return t.length?void g(y(t)):(S(!0),d.getAIEmployees().then(function(t){e||g(y(t||[]))}).catch(function(){e||g([])}).finally(function(){e||S(!1)}),function(){e=!0})}},[d]);var j=(0,e.useMemo)(function(){var e=function(){try{return window.localStorage.getItem(x)||""}catch(e){return""}}();return e?y(v).sort(function(t,n){return t.username===e?-1:+(n.username===e)}):v},[v]),T=(0,e.useCallback)((l=function(e){return function(e,t){var n,r,i,l,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return l={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function a(l){return function(a){var u=[l,a];if(n)throw TypeError("Generator is already executing.");for(;o;)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 o.label++,{value:u[1],done:!1};case 5:o.label++,r=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(i=(i=o.trys).length>0&&i[i.length-1])&&(6===u[0]||2===u[0])){o=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){o.label=u[1];break}if(6===u[0]&&o.label<i[1]){o.label=i[1],i=u;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(u);break}i[2]&&o.ops.pop(),o.trys.pop();continue}u=t.call(e,o)}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}}}}(this,function(t){switch(t.label){case 0:if(!e||!c)return[2];P(!0),t.label=1;case 1:t.trys.push([1,3,4,5]);var n,i,l,o,a,u=e.username;try{window.localStorage.setItem(x,u)}catch(e){}return[4,p({aiEmployee:e,tasks:[{title:E(c),message:{user:f("Please help me analyze the file currently open in preview."),workContext:[{type:w,uid:(a=null!=(o=null!=(l=null!=(i=null!=(n=null==c?void 0:c.id)?n:null==c?void 0:c.uid)?i:null==c?void 0:c.url)?l:null==c?void 0:c.path)?o:E(c),"file-preview:".concat(String(a))),title:E(c),content:{source:"plugin-file-preview-auth",file:{id:null==c?void 0:c.id,uid:null==c?void 0:c.uid,url:null==c?void 0:c.url,preview:null==c?void 0:c.preview,filename:(null==c?void 0:c.filename)||(null==c?void 0:c.name),name:(null==c?void 0:c.name)||(null==c?void 0:c.filename),title:null==c?void 0:c.title,extname:null==c?void 0:c.extname,mimetype:null==c?void 0:c.mimetype,size:null==c?void 0:c.size,path:null==c?void 0:c.path,storageId:null==c?void 0:c.storageId}}}]},autoSend:!1}]})];case 2:return t.sent(),[3,5];case 3:return t.sent(),r.message.error(f("Failed to open AI chat")),[3,5];case 4:return P(!1),[7];case 5:return[2]}})},o=function(){var e=this,t=arguments;return new Promise(function(n,r){var i=l.apply(e,t);function o(e){s(i,n,r,o,a,"next",e)}function a(e){s(i,n,r,o,a,"throw",e)}o(void 0)})},function(e){return o.apply(this,arguments)}),[c,f,p]),A=j.map(function(e){return{key:e.username,label:(null==e?void 0:e.nickname)||(null==e?void 0:e.username)||"",onClick:function(){return T(e)}}});return k||j.length?1===j.length?t().createElement(r.Tooltip,{title:f("Ask AI")},t().createElement(r.Button,{type:"text",size:"small",icon:t().createElement(n.RobotOutlined,null),loading:O||k,onClick:function(e){e.stopPropagation(),T(j[0])}},f("Ask AI"))):t().createElement(r.Tooltip,{title:f("Ask AI")},t().createElement(r.Dropdown,{menu:{items:A},trigger:["click"],placement:"bottomRight",disabled:O||k},t().createElement(r.Button,{type:"text",size:"small",icon:t().createElement(n.RobotOutlined,null),loading:O||k,onClick:function(e){return e.stopPropagation()}},f("Ask AI")))):null},C=function(e){var n=e.file;return t().createElement(k,null,t().createElement(S,{file:n}))},O=m(41);function P(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 j(e,t,n,r,i,l,o){try{var a=e[l](o),u=a.value}catch(e){n(e);return}a.done?t(u):Promise.resolve(u).then(r,i)}function T(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var l=e.apply(t,n);function o(e){j(l,r,i,o,a,"next",e)}function a(e){j(l,r,i,o,a,"throw",e)}o(void 0)})}}function A(e,t,n){return(A=z()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&F(i,n.prototype),i}).apply(null,arguments)}function R(e){return(R=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function I(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 _(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 F(e,t){return(F=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function B(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 l=[],o=!0,a=!1;try{for(i=i.call(e);!(o=(n=i.next()).done)&&(l.push(n.value),!t||l.length!==t);o=!0);}catch(e){a=!0,r=e}finally{try{o||null==i.return||i.return()}finally{if(a)throw r}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return P(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 P(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 L(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function D(e){var t="function"==typeof Map?new Map:void 0;return(D=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 A(e,arguments,R(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),F(n,e)})(e)}function z(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(z=function(){return!!e})()}function U(e,t){var n,r,i,l,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return l={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function a(l){return function(a){var u=[l,a];if(n)throw TypeError("Generator is already executing.");for(;o;)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 o.label++,{value:u[1],done:!1};case 5:o.label++,r=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(i=(i=o.trys).length>0&&i[i.length-1])&&(6===u[0]||2===u[0])){o=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){o.label=u[1];break}if(6===u[0]&&o.label<i[1]){o.label=i[1],i=u;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(u);break}i[2]&&o.ops.pop(),o.trys.pop();continue}u=t.call(e,o)}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 M=["application/pdf"],W=["image/png","image/jpeg","image/gif","image/webp","image/svg+xml","image/bmp"],N=["text/plain","text/csv","text/html","text/css","text/javascript","application/json","application/xml","text/xml","text/yaml","application/x-yaml"],q=["application/vnd.openxmlformats-officedocument.wordprocessingml.document"],V=["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.ms-excel"],H=["pdf"],X=["png","jpg","jpeg","gif","webp","svg","bmp"],G=["txt","csv","html","css","js","json","xml","log","md","yaml","yml","xaml"],J=["docx"],Y=["xlsx","xls"],$=["application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.ms-powerpoint"],K=["pptx","ppt"];function Q(e){if(!e||"string"==typeof e)return e;var t,n,r,i,l,o,a,u,c,s,f,d,p,m=e.response;return m&&(void 0===m?"undefined":L(m))==="object"?_(I({},m,e),{id:null!=(t=e.id)?t:m.id,uid:null!=(n=e.uid)?n:m.uid,url:null!=(r=e.url)?r:m.url,preview:e.preview||m.preview,filename:null!=(i=e.filename)?i:m.filename,name:null!=(l=e.name)?l:m.name,title:null!=(o=e.title)?o:m.title,extname:null!=(a=e.extname)?a:m.extname,mimetype:null!=(u=e.mimetype)?u:m.mimetype,size:null!=(c=e.size)?c:m.size,path:null!=(s=e.path)?s:m.path,storageId:null!=(f=e.storageId)?f:m.storageId,collectionName:null!=(d=e.collectionName)?d:m.collectionName,lastModified:null!=(p=e.lastModified)?p:m.lastModified}):e}var Z=function(e){var t=Q(e),n=("string"==typeof t?t:(null==t?void 0:t.extname)||(null==t?void 0:t.name)||(null==t?void 0:t.filename)||(null==t?void 0:t.url)||"").split("?")[0].split("#")[0],r=n.lastIndexOf(".");return -1!==r?n.slice(r+1).toLowerCase().replace(/^\./,""):""},ee=function(e){var t=Q(e),n="string"==typeof t?t:(null==t?void 0:t.url)||(null==t?void 0:t.preview)||(null==t?void 0:t.path);return n?n.startsWith("https://")||n.startsWith("http://")?n:"".concat(location.origin,"/").concat(n.replace(/^\//,"")):""},et=function(e){if("string"==typeof e)return e;var t=Q(e);return t?[t.id,t.uid,t.url,t.preview,t.path,t.storageId,t.collectionName,t.lastModified,t.size].filter(function(e){return null!=e&&""!==e}).join(":"):""},en=function(e){var t=Q(e);if((null==t?void 0:t.mimetype)&&M.includes(t.mimetype))return!0;var n=Z(e);return!!n&&H.includes(n)},er=function(e){var t=Q(e);if((null==t?void 0:t.mimetype)&&W.includes(t.mimetype)||(null==t?void 0:t.mimetype)&&(0,i.matchMimetype)(t,"image/*"))return!0;var n=Z(e);return!!n&&X.includes(n)},ei=function(e){var t=Q(e);if((null==t?void 0:t.mimetype)&&N.includes(t.mimetype))return!0;var n=Z(e);return!!n&&G.includes(n)},el=function(e){var t=Q(e);if((null==t?void 0:t.mimetype)&&q.includes(t.mimetype))return!0;var n=Z(e);return!!n&&J.includes(n)},eo=function(e){var t=Q(e);if((null==t?void 0:t.mimetype)&&V.includes(t.mimetype))return!0;var n=Z(e);return!!n&&Y.includes(n)},ea=function(e){var t=Q(e);if((null==t?void 0:t.mimetype)&&$.includes(t.mimetype))return!0;var n=Z(e);return!!n&&K.includes(n)},eu=function(e){var t=Q(e);return t?t.title&&t.extname?"".concat(t.title).concat(t.extname):t.filename||t.name||t.title||"download":"download"},ec=new Map;function es(e){var t=Q(e);return{id:null==t?void 0:t.id,uid:null==t?void 0:t.uid,url:null==t?void 0:t.url,preview:null==t?void 0:t.preview,filename:(null==t?void 0:t.filename)||(null==t?void 0:t.name),name:(null==t?void 0:t.name)||(null==t?void 0:t.filename),title:null==t?void 0:t.title,extname:null==t?void 0:t.extname,mimetype:null==t?void 0:t.mimetype,size:null==t?void 0:t.size,path:null==t?void 0:t.path,storageId:null==t?void 0:t.storageId,collectionName:null==t?void 0:t.collectionName,lastModified:null==t?void 0:t.lastModified}}function ef(){return(ef=T(function(e,t){var n,r;return U(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 ed(e,t){return ep.apply(this,arguments)}function ep(){return(ep=T(function(e,t){var n,r,i;return U(this,function(l){if(!(n=function(e){var t=es("string"==typeof e?{url:e}:e||{}),n=ee(e);if(n&&function(e){if(!e)return!1;try{var t=new URL(e,location.origin);if(t.origin!==location.origin)return!1;return["/api/filePreviewAuth:download","/api/extStorage:download","/api/skillHub:download","/api/worker-monitor","/api/carboneTemplates:download","/api/attachments:stream"].some(function(e){return t.pathname===e||t.pathname.startsWith("".concat(e,"/"))||t.pathname.startsWith("".concat(e,":"))})}catch(e){return!1}}(n))return n;var r=t.id||t.uid;if(null!=r){var i=t.collectionName||"attachments";return"/api/attachments:stream?filterByTk=".concat(r,"&collection=").concat(i)}return n||""}(e))||n.endsWith("?"))throw Error("No file URL");return r="".concat(t?"auth":"anon",":").concat(t||"",":").concat(et(e)||n),(i=ec.get(r))||(i=(function(e,t){return ef.apply(this,arguments)})(n,t).catch(function(e){throw ec.delete(r),e}),ec.set(r,i)),[2,i]})})).apply(this,arguments)}function em(e,t){return ev.apply(this,arguments)}function ev(){return(ev=T(function(e,t){var n,r,i,l;return U(this,function(o){switch(o.label){case 0:return[4,ed(e,t)];case 1:return n=o.sent(),r=eu(e),(i=document.createElement("a")).href=l=URL.createObjectURL(n),i.download=r,document.body.appendChild(i),i.click(),document.body.removeChild(i),setTimeout(function(){return URL.revokeObjectURL(l)},1e3),[2]}})})).apply(this,arguments)}function eh(t,n){var r=B((0,e.useState)(null),2),i=r[0],l=r[1],o=B((0,e.useState)(!0),2),a=o[0],u=o[1],c=B((0,e.useState)(null),2),s=c[0],f=c[1],d=(0,e.useRef)(null),p=(0,e.useRef)(t);p.current=t;var m=et(t);return(0,e.useEffect)(function(){var e=!1,t=p.current;if(!(ee(t)||"string"!=typeof t&&((null==t?void 0:t.id)||(null==t?void 0:t.uid)))){u(!1),f("No file URL");return}return u(!0),f(null),ed(t,n).then(function(t){if(!e){var n=URL.createObjectURL(t);d.current=n,l(n),u(!1)}}).catch(function(t){e||(f(t.message||"Failed to load"),u(!1))}),function(){e=!0,d.current&&(URL.revokeObjectURL(d.current),d.current=null)}},[m,n]),{blobUrl:i,loading:a,error:s}}function ey(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 eg(e){var n=e.message;return t().createElement("div",{style:{padding:20,textAlign:"center",color:"#ff4d4f"}},n)}function eb(e){var i=e.file,l=e.title,o=e.ocrStatus,u=e.isOcrSupported,c=a();return t().createElement("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,paddingRight:40}},t().createElement(r.Space,{size:8,style:{minWidth:0,overflow:"hidden"}},t().createElement("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:600},title:l},l),function(){if(!u||!o)return null;switch(o){case"pending-ocr":return t().createElement(r.Tag,{color:"processing",icon:t().createElement(n.SyncOutlined,{spin:!0})},c("OCR Pending"));case"waiting-verify":return t().createElement(r.Tag,{color:"warning",icon:t().createElement(n.ClockCircleOutlined,null)},c("Waiting Verify"));case"verified":return t().createElement(r.Tag,{color:"success",icon:t().createElement(n.CheckCircleOutlined,null)},c("OCR Verified"));default:return t().createElement(r.Tag,{color:"default"},c("No OCR"))}}()),t().createElement(C,{file:i}))}function ew(e){var n,r=e.file,l=(0,i.useAPIClient)(),o=a(),u=eh(r,(null==(n=l.auth)?void 0:n.token)||""),c=u.blobUrl,s=u.loading,f=u.error;return s?t().createElement(ey,{message:o("Loading preview...")}):f||!c?t().createElement(eg,{message:o("Failed to load file preview")}):t().createElement("iframe",{src:c,width:"100%",height:"100%",style:{border:"none"}})}function ex(e){var n,r=e.file,l=(0,i.useAPIClient)(),o=a(),u=eh(r,(null==(n=l.auth)?void 0:n.token)||""),c=u.blobUrl,s=u.loading,f=u.error;return s?t().createElement(ey,{message:o("Loading preview...")}):f||!c?t().createElement(eg,{message:o("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 eE(n){var r,l,o,u,c,s,f,d,p,m,v,h,y=n.file,g=(0,i.useAPIClient)(),b=a(),w=(null==(h=g.auth)?void 0:h.token)||"",x=(l=(r=B((0,e.useState)(null),2))[0],o=r[1],c=(u=B((0,e.useState)(!0),2))[0],s=u[1],d=(f=B((0,e.useState)(null),2))[0],p=f[1],(m=(0,e.useRef)(y)).current=y,v=et(y),(0,e.useEffect)(function(){var e=!1,t=m.current;if(!(ee(t)||"string"!=typeof t&&((null==t?void 0:t.id)||(null==t?void 0:t.uid)))){s(!1),p("No file URL");return}return s(!0),p(null),ed(t,w).then(function(e){return e.text()}).then(function(t){e||(o(t),s(!1))}).catch(function(t){e||(p(t.message||"Failed to load"),s(!1))}),function(){e=!0}},[v,w]),{text:l,loading:c,error:d}),E=x.text,k=x.loading,S=x.error;return k?t().createElement(ey,{message:b("Loading preview...")}):S||null===E?t().createElement(eg,{message:b("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"}},E)}function ek(n){var r,l=n.file,o=(0,i.useAPIClient)(),u=a(),c=(null==(r=o.auth)?void 0:r.token)||"",s=(0,e.useRef)(null),f=(0,e.useRef)(l);f.current=l;var d=et(l),p=B((0,e.useState)(!0),2),v=p[0],h=p[1],y=B((0,e.useState)(null),2),g=y[0],b=y[1];return(0,e.useEffect)(function(){var e=!1,t=f.current;if(!(ee(t)||"string"!=typeof t&&((null==t?void 0:t.id)||(null==t?void 0:t.uid)))||!s.current){h(!1),b("No file URL");return}return h(!0),b(null),T(function(){var n,r,i;return U(this,function(l){switch(l.label){case 0:return l.trys.push([0,4,,5]),[4,ed(t,c)];case 1:if(n=l.sent(),e)return[2];return[4,O("imported_-1dm6lbf_component",m.e("374").then(m.bind(m,335)))];case 2:if(r=l.sent(),e||!s.current)return[2];return s.current.innerHTML="",[4,r.renderAsync(n,s.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 l.sent(),h(!1),[3,5];case 4:if(i=l.sent(),e)return[2];return b(i.message||"Failed to render DOCX"),h(!1),[3,5];case 5:return[2]}})})(),function(){e=!0}},[d,c]),t().createElement("div",{style:{width:"100%",height:"100%",position:"relative"}},v&&t().createElement(ey,{message:u("Loading preview...")}),g&&t().createElement(eg,{message:u("Failed to load file preview")}),t().createElement("div",{ref:s,style:{width:"100%",height:"100%",overflow:"auto",display:v||g?"none":"block"}}))}function eS(n){var r,l=n.file,o=(0,i.useAPIClient)(),u=a(),c=(null==(r=o.auth)?void 0:r.token)||"",s=(0,e.useRef)(null),f=(0,e.useRef)(l);f.current=l;var d=et(l),p=B((0,e.useState)(!0),2),v=p[0],h=p[1],y=B((0,e.useState)(null),2),g=y[0],b=y[1],w=B((0,e.useState)([]),2),x=w[0],E=w[1],k=B((0,e.useState)(""),2),S=k[0],C=k[1],P=B((0,e.useState)({}),2),j=P[0],A=P[1];return(0,e.useEffect)(function(){var e=!1,t=f.current;if(!(ee(t)||"string"!=typeof t&&((null==t?void 0:t.id)||(null==t?void 0:t.uid)))){h(!1),b("No file URL");return}return h(!0),b(null),T(function(){var n,r,i,l,o,a,u,s,f,d,p,v,y,g;return U(this,function(w){switch(w.label){case 0:return w.trys.push([0,4,,5]),[4,ed(t,c)];case 1:if(n=w.sent(),e)return[2];return[4,O("imported_-1lj2ifg_component",m.e("166").then(m.bind(m,907)))];case 2:if(r=w.sent(),e)return[2];return[4,n.arrayBuffer()];case 3:if(i=w.sent(),e)return[2];o=(l=r.read(i,{type:"array"})).SheetNames,a={},u=!0,s=!1,f=void 0;try{for(d=o[Symbol.iterator]();!(u=(p=d.next()).done);u=!0)v=p.value,y=l.Sheets[v],a[v]=r.utils.sheet_to_html(y,{id:"xlsx-preview-table"})}catch(e){s=!0,f=e}finally{try{u||null==d.return||d.return()}finally{if(s)throw f}}if(e)return[2];return E(o),C(o[0]||""),A(a),h(!1),[3,5];case 4:if(g=w.sent(),e)return[2];return b(g.message||"Failed to render XLSX"),h(!1),[3,5];case 5:return[2]}})})(),function(){e=!0}},[d,c]),t().createElement("div",{style:{width:"100%",height:"100%",display:"flex",flexDirection:"column"}},v&&t().createElement(ey,{message:u("Loading preview...")}),g&&t().createElement(eg,{message:u("Failed to load file preview")}),!v&&!g&&t().createElement(t().Fragment,null,x.length>1&&t().createElement("div",{style:{display:"flex",gap:0,borderBottom:"1px solid #e8e8e8",background:"#fafafa",padding:"0 8px",flexShrink:0,overflowX:"auto"}},x.map(function(e){return t().createElement("button",{key:e,onClick:function(){return C(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:s,style:{flex:1,overflow:"auto",padding:0},dangerouslySetInnerHTML:{__html:j[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 ")))}function eC(n){var r,l=n.file,o=(0,i.useAPIClient)(),u=a(),c=(null==(r=o.auth)?void 0:r.token)||"",s=B((0,e.useState)(!0),2),f=s[0],d=s[1],p=B((0,e.useState)(null),2),v=p[0],h=p[1],y=B((0,e.useState)(null),2),g=y[0],b=y[1],w=B((0,e.useState)(null),2),x=w[0],E=w[1],k=(0,e.useRef)(l);k.current=l;var S=et(l);return(0,e.useEffect)(function(){var e=!1,t=k.current;if(!(ee(t)||"string"!=typeof t&&((null==t?void 0:t.id)||(null==t?void 0:t.uid)))){d(!1),h("No file URL");return}return d(!0),h(null),T(function(){var n,r,i,l;return U(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,Promise.all([ed(t,c),O("imported_tpp3om_component",m.e("514").then(m.bind(m,581)))])];case 1:if(r=(n=B.apply(void 0,[o.sent(),2]))[0],i=n[1],e)return[2];return b(r),E(function(){return i.PptxPreview}),d(!1),[3,3];case 2:if(l=o.sent(),e)return[2];return h(l.message||"Failed to render PPTX"),d(!1),[3,3];case 3:return[2]}})})(),function(){e=!0}},[S,c]),t().createElement("div",{style:{width:"100%",height:"100%",position:"relative"}},f&&t().createElement(ey,{message:u("Loading preview...")}),v&&t().createElement(eg,{message:u("Failed to load file preview")}),!f&&!v&&x&&t().createElement("div",{style:{width:"100%",height:"100%",overflow:"auto"}},t().createElement(x,{file:g})))}var eO=function(l){return function(o){var u,c=o.open,s=o.onOpenChange,f=o.onClose,d=o.file,p=o.index,m=o.list,v=o.onSwitchIndex;o.onDownload;var h=(0,i.useAPIClient)(),y=a(),g=B((0,e.useState)("visual"),2),b=g[0],w=g[1],x=(0,e.useCallback)((u=T(function(e){var t,n,i;return U(this,function(l){switch(l.label){case 0:if(!(n=e||d))return[2];i=(null==(t=h.auth)?void 0:t.token)||"",l.label=1;case 1:return l.trys.push([1,3,,4]),[4,em(n,i)];case 2:return l.sent(),[3,4];case 3:return l.sent(),r.message.error(y("Failed to download file")),[3,4];case 4:return[2]}})}),function(e){return u.apply(this,arguments)}),[d,h,y]);if("boolean"!=typeof c)return t().createElement(l,_(I({},o),{onDownload:x}));var E=eu(d),k="number"==typeof p&&!!v&&p>0,S="number"==typeof p&&!!v&&p<m.length-1;return t().createElement(r.Modal,{open:c,title:t().createElement(eb,{file:d,title:E}),onCancel:function(){null==s||s(!1),null==f||f(),w("visual")},footer:t().createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",width:"100%"}},t().createElement("div",{key:"left-actions"},t().createElement(r.Button,{onClick:function(){return w(function(e){return"visual"===e?"raw":"visual"})}},"visual"===b?y("View Raw Parsed Text"):y("View Visual Preview"))),t().createElement(r.Space,{size:14,style:{fontSize:"20px"}},t().createElement(n.LeftOutlined,{style:{cursor:k?"pointer":"not-allowed"},onClick:function(){return k&&(null==v?void 0:v(p-1))}}),t().createElement(n.RightOutlined,{style:{cursor:S?"pointer":"not-allowed"},onClick:function(){return S&&(null==v?void 0:v(p+1))}}),t().createElement(n.DownloadOutlined,{onClick:function(){return x(d)}}))),width:"90%",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"}},"raw"===b?t().createElement(eP,{file:d}):t().createElement(l,_(I({},o),{onDownload:x}))))}};function eP(l){var o=l.file,u=(0,i.useAPIClient)(),c=a(),s=B((0,e.useState)(""),2),f=s[0],d=s[1],p=B((0,e.useState)(!0),2),m=p[0],v=p[1],h=B((0,e.useState)(null),2),y=h[0],g=h[1],b=(0,i.useComponent)("MarkdownVditor"),w=(0,i.useComponent)("Markdown.Void");return((0,e.useEffect)(function(){var e=!1;return T(function(){var t,n,r,i,l,a,c,s,f,p;return U(this,function(m){switch(m.label){case 0:v(!0),g(null),m.label=1;case 1:return m.trys.push([1,4,,5]),[4,ed(o,(null==(t=u.auth)?void 0:t.token)||"")];case 2:if(i=m.sent(),e)return[2];return(l=new FormData).append("file",i,eu(o)),l.append("attachment",JSON.stringify(es(o))),[4,u.request({url:"filePreviewAuth:getContent",method:"post",data:l,headers:{"Content-Type":"multipart/form-data"}})];case 3:if(a=m.sent(),e)return[2];return s=c=(null==a||null==(r=a.data)||null==(n=r.data)?void 0:n.content)||"",(f=c.match(/<file_preview[^>]*>([\s\S]*?)<\/file_preview>/i))&&(s=f[1].trim()),d(s),v(!1),[3,5];case 4:if(p=m.sent(),e)return[2];return g(p.message||"Failed to fetch raw text"),v(!1),[3,5];case 5:return[2]}})})(),function(){e=!0}},[o,u]),m)?t().createElement(r.Spin,{size:"large",tip:c("Extracting raw text..."),style:{marginTop:"40px"}}):y?t().createElement(r.Alert,{type:"error",message:y,style:{width:"100%",margin:"20px"}}):f?t().createElement("div",{style:{width:"100%",height:"100%",display:"flex",flexDirection:"column",position:"relative"}},t().createElement("span",{onClick:function(){if(navigator.clipboard&&navigator.clipboard.writeText)navigator.clipboard.writeText(f).then(function(){r.message.success(c("Copied to clipboard"))}).catch(function(e){r.message.error(c("Failed to copy")),console.error("Copy error",e)});else{var e=document.createElement("textarea");e.value=f,document.body.appendChild(e),e.select();try{document.execCommand("copy"),r.message.success(c("Copied to clipboard"))}catch(e){r.message.error(c("Failed to copy"))}document.body.removeChild(e)}},style:{position:"absolute",top:"20px",right:"25px",zIndex:10,cursor:"pointer",padding:"4px 10px",background:"rgba(255, 255, 255, 0.85)",border:"1px solid #e8e8e8",borderRadius:"4px",color:"#1890ff",display:"flex",alignItems:"center",gap:"6px",boxShadow:"0 2px 4px rgba(0,0,0,0.05)",fontSize:"13px"},title:c("Copy")},t().createElement(n.CopyOutlined,null),c("Copy")),t().createElement("div",{style:{flex:1,overflow:"auto",padding:"20px",textAlign:"left"}},t().createElement("style",null,"\n .hide-vditor-toolbar .vditor-toolbar {\n display: none !important;\n }\n .hide-vditor-toolbar .vditor {\n border: none !important;\n }\n "),t().createElement("div",{className:"hide-vditor-toolbar",style:{height:"100%"}},b?t().createElement(b,{value:f,disabled:!1}):w?t().createElement(w,{content:f}):t().createElement("pre",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"monospace",fontSize:"13px"}},f)))):t().createElement(r.Alert,{type:"info",style:{width:"100%",margin:"20px"},description:c("No text content could be extracted from this file."),showIcon:!0})}function ej(l){var o,u,c=l.index,s=l.list,f=l.onSwitchIndex,d=a(),p=(0,i.useAPIClient)(),m=s[c],v=B((0,e.useState)(!1),2),h=v[0],y=v[1],g=B((0,e.useState)("visual"),2),b=g[0],w=g[1],x=B((0,e.useState)("preview"),2),E=x[0],k=x[1],S=B((0,e.useState)("no-ocr"),2),C=S[0],O=S[1],P=B((0,e.useState)(null),2),j=(P[0],P[1]),A=(0,e.useMemo)(function(){return!!m&&(en(m)||er(m))},[m]),R=(0,i.useComponent)("OcrVerifyBlock");(0,e.useEffect)(function(){if(null==m?void 0:m.id){var e=!1;return O(m.ocrStatus||"no-ocr"),j(m.ocrData||null),p.resource("attachments").get({filterByTk:m.id}).then(function(t){if(!e){var n,r=null==t||null==(n=t.data)?void 0:n.data;r&&(O(r.ocrStatus||"no-ocr"),j(r.ocrData||null))}}).catch(console.error),function(){e=!0}}},[null==m?void 0:m.id,null==m?void 0:m.ocrData,null==m?void 0:m.ocrStatus,p]),(0,e.useEffect)(function(){if("pending-ocr"===C&&(null==m?void 0:m.id)){var e,t=null,n=!1,i=(e=T(function(){var e,l,o;return U(this,function(a){switch(a.label){case 0:return a.trys.push([0,2,,3]),[4,p.resource("attachments").get({filterByTk:m.id})];case 1:if(l=a.sent(),n)return[2];return(o=null==l||null==(e=l.data)?void 0:e.data)&&("pending-ocr"!==o.ocrStatus?(O(o.ocrStatus||"no-ocr"),j(o.ocrData||null),r.message.success(d("OCR processing completed!"))):t=setTimeout(i,3e3)),[3,3];case 2:return console.error("Polling error",a.sent()),t=setTimeout(i,3e3),[3,3];case 3:return[2]}})}),function(){return e.apply(this,arguments)});return t=setTimeout(i,3e3),function(){n=!0,t&&clearTimeout(t)}}},[C,null==m?void 0:m.id,p,d]);var I=(o=T(function(){var e;return U(this,function(t){switch(t.label){case 0:if(!(null==m?void 0:m.id))return[2];t.label=1;case 1:return t.trys.push([1,3,,4]),O("pending-ocr"),[4,p.request({url:"filePreviewAuth:runOcr",method:"post",data:{attachmentId:m.id}})];case 2:return t.sent(),r.message.info(d("OCR process started in the background.")),[3,4];case 3:return e=t.sent(),r.message.error((null==e?void 0:e.message)||d("Failed to start OCR process.")),O("no-ocr"),[3,4];case 4:return[2]}})}),function(){return o.apply(this,arguments)}),_=(0,e.useCallback)((u=T(function(e){var t,n,i,l;return U(this,function(o){switch(o.label){case 0:null==e||null==(t=e.preventDefault)||t.call(e),null==e||null==(n=e.stopPropagation)||n.call(e),l=(null==(i=p.auth)?void 0:i.token)||"",y(!0),o.label=1;case 1:return o.trys.push([1,3,4,5]),[4,em(m,l)];case 2:return o.sent(),[3,5];case 3:return o.sent(),r.message.error(d("Failed to download file")),[3,5];case 4:return y(!1),[7];case 5:return[2]}})}),function(e){return u.apply(this,arguments)}),[m,p,d]),F=(0,e.useCallback)(function(){f(null),w("visual"),k("preview")},[f]),L=(0,e.useMemo)(function(){return en(m)?ew:er(m)?ex:ei(m)?eE:el(m)?ek:eo(m)?eS:ea(m)?eC:null},[m]),D=null!=L||"raw"===b,z=[{key:"preview",label:t().createElement("span",null,t().createElement(n.EyeOutlined,null)," ",d("Visual Preview")),children:t().createElement("div",{style:{height:"70vh",width:"100%",overflow:"auto",background:"#f5f5f5",display:"flex",justifyContent:"center",alignItems:"center"}},L?t().createElement(L,{file:m}):null)},{key:"ocr",label:t().createElement("span",null,t().createElement(n.ScanOutlined,null)," ",d("OCR & Verify")),children:t().createElement("div",{style:{height:"70vh",width:"100%",display:"flex",flexDirection:"column"}},"no-ocr"===C&&t().createElement("div",{style:{display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",height:"100%",padding:"40px",background:"#fafafa",borderRadius:"8px"}},t().createElement(n.ScanOutlined,{style:{fontSize:"64px",color:"#1890ff",marginBottom:"20px"}}),t().createElement("h3",{style:{fontSize:"18px",fontWeight:600,marginBottom:"10px"}},d("Word-level Song ngữ (English & Vietnamese) OCR")),t().createElement("p",{style:{color:"#8c8c8c",maxWidth:"480px",textAlign:"center",marginBottom:"24px"}},d("Chưa c\xf3 dữ liệu OCR cấp độ Từ (Word-level) cho tệp n\xe0y. H\xe3y chạy nhận dạng Tesseract-OCR để bắt đầu đối so\xe1t v\xe0 verify toạ độ.")),t().createElement(r.Button,{type:"primary",size:"large",icon:t().createElement(n.ThunderboltOutlined,null),onClick:I},d("Run Tesseract OCR"))),"pending-ocr"===C&&t().createElement("div",{style:{display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",height:"100%",padding:"40px"}},t().createElement(r.Spin,{size:"large",tip:d("Analyzing layout structure and running song ngữ OCR...")}),t().createElement("p",{style:{color:"#8c8c8c",marginTop:"20px",fontSize:"13px",textAlign:"center"}},d("Extracting word-level coordinates via Tesseract-OCR. This will automatically refresh when complete."))),("waiting-verify"===C||"verified"===C)&&t().createElement("div",{style:{flex:1,height:"100%",overflow:"hidden"}},R?t().createElement(R,{collection:"attachments",recordId:m.id,pdfField:"url",jsonField:"ocrData",statusField:"ocrStatus"}):t().createElement("div",{style:{padding:"20px"}},t().createElement(r.Alert,{type:"error",message:d("Plugin OCR Verify Block is not enabled"),description:d("Please enable the plugin-ocr-verify-block plugin to display the verify splitter layout."),showIcon:!0}))))}];return t().createElement(r.Modal,{open:null!=c,title:t().createElement(eb,{file:m,title:(null==m?void 0:m.title)||(null==m?void 0:m.filename)||(null==m?void 0:m.name)||"File",ocrStatus:C,isOcrSupported:A}),onCancel:F,footer:t().createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",width:"100%"}},t().createElement("div",{key:"left-actions"},!A&&t().createElement(r.Button,{onClick:function(){return w(function(e){return"visual"===e?"raw":"visual"})}},"visual"===b?d("View Raw Parsed Text"):d("View Visual Preview"))),t().createElement(r.Space,null,t().createElement(r.Button,{key:"download",onClick:_,loading:h},d("Download")),t().createElement(r.Button,{key:"close",onClick:F},d("Close")))),width:D?"90%":520,centered:!0},A?t().createElement(r.Tabs,{activeKey:E,onChange:function(e){return k(e)},items:z,style:{width:"100%",height:"100%"}}):t().createElement("div",{style:{maxWidth:"100%",maxHeight:D?"calc(100vh - 256px)":"auto",height:D?"70vh":"auto",width:"100%",background:"white",display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",overflowY:"auto"}},"raw"===b?t().createElement(eP,{file:m}):L?t().createElement(L,{file:m}):t().createElement(r.Alert,{type:"info",style:{width:"100%"},description:d("This file type cannot be previewed. Click Download to save the file."),showIcon:!0})))}function eT(n){var l=n.file,o=(0,i.useAPIClient)(),u=a(),c=(0,e.useCallback)(T(function(){var e,t;return U(this,function(n){switch(n.label){case 0:t=(null==(e=o.auth)?void 0:e.token)||"",n.label=1;case 1:return n.trys.push([1,3,,4]),[4,em(l,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]}})}),[l,o,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 eA=function(e){var o;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function a(){var e,t;if(!(this instanceof a))throw TypeError("Cannot call a class as a function");return e=a,t=arguments,e=R(e),function(e,t){if(t&&("object"===L(t)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,z()?Reflect.construct(e,t||[],R(this).constructor):e.apply(this,t))}return a.prototype=Object.create(e&&e.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),e&&F(a,e),o=[{key:"load",value:function(){var e=this;return T(function(){return U(this,function(o){return e.patchUploadPreviewBase64Fallback(),!function(e){try{i=e.pm.get("ai")}catch(e){return}var i,l,o=null==i?void 0:i.aiManager;if(null==o?void 0:o.registerWorkContext)try{(null==(l=o.getWorkContext)?void 0:l.call(o,w))||o.registerWorkContext(w,{name:w,tag:{Component:function(e){var i=e.item;return t().createElement(r.Space,null,t().createElement(n.FileTextOutlined,null),t().createElement("span",null,(null==i?void 0:i.title)||""))}},chatbox:{Component:function(e){var i=e.item;return t().createElement(r.Space,null,t().createElement(n.FileTextOutlined,null),t().createElement("span",null,(null==i?void 0:i.title)||""))}}})}catch(e){}}(e.app),i.attachmentFileTypes.add({match:function(){return!0},Previewer:ej}),l.filePreviewTypes.add({match:function(){return!0},Previewer:eO(eT)}),l.filePreviewTypes.add({match:en,Previewer:eO(ew)}),l.filePreviewTypes.add({match:er,getThumbnailURL:function(e){var t=Q(e);return(null==t?void 0:t.url)||(null==t?void 0:t.preview)||null},Previewer:eO(ex)}),l.filePreviewTypes.add({match:ei,Previewer:eO(eE)}),l.filePreviewTypes.add({match:el,Previewer:eO(ek)}),l.filePreviewTypes.add({match:eo,Previewer:eO(eS)}),l.filePreviewTypes.add({match:ea,Previewer:eO(eC)}),[2]})})()}},{key:"patchUploadPreviewBase64Fallback",value:function(){if("undefined"!=typeof window){var e,t=null==(e=window.FileReader)?void 0:e.prototype;if(t&&!t.__filePreviewAuthBase64FallbackPatched){var n=t.readAsDataURL;"function"==typeof n&&(Object.defineProperty(t,"__filePreviewAuthBase64FallbackPatched",{value:!0,configurable:!0}),t.readAsDataURL=function(e){var t=this;if(null!=e)return n.call(this,e);setTimeout(function(){var e,n;try{Object.defineProperty(t,"result",{value:"",configurable:!0})}catch(e){}null==(e=t.onload)||e.call(t,new ProgressEvent("load")),null==(n=t.onloadend)||n.call(t,new ProgressEvent("loadend"))},0)})}}}}],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)}}(a.prototype,o),a}(D(i.Plugin)),eR=eA}(),v}()});
10
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@nocobase/plugin-ai/client"),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-ai/client","@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-ai/client"),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-ai/client"],e["@nocobase/plugin-file-manager/client"],e["@nocobase/client"],e.react,e["@ant-design/icons"],e.antd)}(self,function(e,t,n,r,i,l){return function(){var o,a,u,c,s,d,f={41:function(e){e.exports=function(e,t){return"undefined"!=typeof __deoptimization_sideEffect__&&__deoptimization_sideEffect__(e,t),t}},482:function(e){"use strict";e.exports=i},772:function(e){"use strict";e.exports=n},645:function(t){"use strict";t.exports=e},183:function(e){"use strict";e.exports=t},721:function(e){"use strict";e.exports=l},156:function(e){"use strict";e.exports=r}},p={};function m(e){var t=p[e];if(void 0!==t)return t.exports;var n=p[e]={exports:{}};return f[e](n,n.exports,m),n.exports}m.m=f,m.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return m.d(t,{a:t}),t},m.d=function(e,t){for(var n in t)m.o(t,n)&&!m.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},m.f={},m.e=function(e){return Promise.all(Object.keys(m.f).reduce(function(t,n){return m.f[n](e,t),t},[]))},m.u=function(e){return""+e+"."+({166:"17caa11c2ba40313",351:"0f0ce45c92425c8f",374:"96762d13b15e7467",514:"2a8b6aa0d2fcd4b2"})[e]+".js"},m.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),m.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o={},a="plugin-file-preview-auth:",m.l=function(e,t,n,r){if(o[e])return void o[e].push(t);if(void 0!==n)for(var i,l,u=document.getElementsByTagName("script"),c=0;c<u.length;c++){var s=u[c];if(s.getAttribute("src")==e||s.getAttribute("data-webpack")==a+n){i=s;break}}i||(l=!0,(i=document.createElement("script")).charset="utf-8",i.timeout=120,m.nc&&i.setAttribute("nonce",m.nc),i.setAttribute("data-webpack",a+n),i.src=e),o[e]=[t];var d=function(t,n){i.onerror=i.onload=null,clearTimeout(f);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)},f=setTimeout(d.bind(null,void 0,{type:"timeout",target:i}),12e4);i.onerror=d.bind(null,i.onerror),i.onload=d.bind(null,i.onload),l&&document.head.appendChild(i)},m.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(u=window.__webpack_public_path__||"/").endsWith("/")||(u+="/"),m.p=u+"static/plugins/plugin-file-preview-auth/dist/client/",c={909:0},m.f.j=function(e,t){var n=m.o(c,e)?c[e]:void 0;if(0!==n)if(n)t.push(n[2]);else{var r=new Promise(function(t,r){n=c[e]=[t,r]});t.push(n[2]=r);var i=m.p+m.u(e),l=Error();m.l(i,function(t){if(m.o(c,e)&&(0!==(n=c[e])&&(c[e]=void 0),n)){var r=t&&("load"===t.type?"missing":t.type),i=t&&t.target&&t.target.src;l.message="Loading chunk "+e+" failed.\n("+r+": "+i+")",l.name="ChunkLoadError",l.type=r,l.request=i,n[1](l)}},"chunk-"+e,e)}},s=function(e,t){var n,r,i=t[0],l=t[1],o=t[2],a=0;if(i.some(function(e){return 0!==c[e]})){for(n in l)m.o(l,n)&&(m.m[n]=l[n]);o&&o(m)}for(e&&e(t);a<i.length;a++)r=i[a],m.o(c,r)&&c[r]&&c[r][0](),c[r]=0},(d=self.webpackChunkplugin_file_preview_auth=self.webpackChunkplugin_file_preview_auth||[]).forEach(s.bind(null,0)),d.push=s.bind(null,d.push.bind(d));var v={};return!function(){"use strict";m.r(v),m.d(v,{default:function(){return eF},PluginFilePreviewAuthClient:function(){return eI}});var e=m(156),t=m.n(e),n=m(482),r=m(721),i=m(772),l=m(183),o=JSON.parse('{"u2":"plugin-file-preview-auth"}');function a(){var e=(0,i.useApp)();return function(t){return e.i18n.t(t,{ns:[o.u2,"client"]})}}var u=m(645);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,l,o){try{var a=e[l](o),u=a.value}catch(e){n(e);return}a.done?t(u):Promise.resolve(u).then(r,i)}function d(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)}}function f(e){return(f=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function p(e,t){return(p=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 l=[],o=!0,a=!1;try{for(i=i.call(e);!(o=(n=i.next()).done)&&(l.push(n.value),!t||l.length!==t);o=!0);}catch(e){a=!0,r=e}finally{try{o||null==i.return||i.return()}finally{if(a)throw r}}return l}}(e,t)||y(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 h(e){return function(e){if(Array.isArray(e))return c(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||y(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function y(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)}}function b(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(b=function(){return!!e})()}var w="file-preview",x="plugin-file-preview-auth.aiEmployee";function E(e){return e?e.title&&e.extname?"".concat(e.title).concat(e.extname):e.filename||e.name||e.title||"file":"file"}var k=function(e){var t,n;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function r(e){var t,n,i;if(!(this instanceof r))throw TypeError("Cannot call a class as a function");return n=r,i=[e],n=f(n),(t=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,b()?Reflect.construct(n,i||[],f(this).constructor):n.apply(this,i))).state={hasError:!1},t}return r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),e&&p(r,e),n=[{key:"getDerivedStateFromError",value:function(){return{hasError:!0}}}],t=[{key:"render",value:function(){return this.state.hasError?null:this.props.children}}],d(r.prototype,t),n&&d(r,n),r}(t().Component),S=function(i){var l,o,c=i.file,d=a(),f=(0,u.useAIConfigRepository)(),p=(0,u.useChatBoxActions)().triggerTask,m=g((0,e.useState)([]),2),v=m[0],y=m[1],b=g((0,e.useState)(!1),2),k=b[0],S=b[1],C=g((0,e.useState)(!1),2),O=C[0],P=C[1];(0,e.useEffect)(function(){var e=!1;if(null==f?void 0:f.getAIEmployees){var t=f.aiEmployees||[];return t.length?void y(h(t)):(S(!0),f.getAIEmployees().then(function(t){e||(y(h(t||[])),S(!1))}).catch(function(){e||(y([]),S(!1))}),function(){e=!0})}},[f]);var j=(0,e.useMemo)(function(){var e=function(){try{return window.localStorage.getItem(x)||""}catch(e){return""}}();return e?h(v).sort(function(t,n){return t.username===e?-1:+(n.username===e)}):v},[v]),_=(0,e.useCallback)((l=function(e){return function(e,t){var n,r,i,l,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return l={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function a(l){return function(a){var u=[l,a];if(n)throw TypeError("Generator is already executing.");for(;o;)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 o.label++,{value:u[1],done:!1};case 5:o.label++,r=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(i=(i=o.trys).length>0&&i[i.length-1])&&(6===u[0]||2===u[0])){o=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){o.label=u[1];break}if(6===u[0]&&o.label<i[1]){o.label=i[1],i=u;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(u);break}i[2]&&o.ops.pop(),o.trys.pop();continue}u=t.call(e,o)}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}}}}(this,function(t){switch(t.label){case 0:if(!e||!c)return[2];P(!0),t.label=1;case 1:t.trys.push([1,3,4,5]);var n,i,l,o,a,u,s,f,m,v,g=e.username;try{window.localStorage.setItem(x,g)}catch(e){}return[4,p({aiEmployee:e,tasks:[{title:E(c),message:{user:d("Please help me analyze the file currently open in preview."),workContext:[{type:w,uid:(a=null!=(o=null!=(l=null!=(i=null!=(n=null==c?void 0:c.id)?n:null==c?void 0:c.uid)?i:null==c?void 0:c.url)?l:null==c?void 0:c.path)?o:E(c),"file-preview:".concat(String(a))),title:E(c),content:{source:"plugin-file-preview-auth",file:{id:null==c?void 0:c.id,uid:null==c?void 0:c.uid,url:null==c?void 0:c.url,preview:null==c?void 0:c.preview,filename:(null==c?void 0:c.filename)||(null==c?void 0:c.name),name:(null==c?void 0:c.name)||(null==c?void 0:c.filename),title:null==c?void 0:c.title,extname:null==c?void 0:c.extname,mimetype:null==c?void 0:c.mimetype,size:null==c?void 0:c.size,path:null==c?void 0:c.path,storageId:null!=(v=null!=(m=null==c?void 0:c.storageId)?m:null==c?void 0:c.storage_id)?v:null==c||null==(u=c.storage)?void 0:u.id,storage_id:null==c?void 0:c.storage_id,storageType:(null==c?void 0:c.storageType)||(null==c||null==(s=c.storage)?void 0:s.type),storageName:(null==c?void 0:c.storageName)||(null==c||null==(f=c.storage)?void 0:f.name),storage:null==c?void 0:c.storage,collectionName:null==c?void 0:c.collectionName}}}]},autoSend:!1}]})];case 2:return t.sent(),[3,5];case 3:return t.sent(),r.message.error(d("Failed to open AI chat")),[3,5];case 4:return P(!1),[7];case 5:return[2]}})},o=function(){var e=this,t=arguments;return new Promise(function(n,r){var i=l.apply(e,t);function o(e){s(i,n,r,o,a,"next",e)}function a(e){s(i,n,r,o,a,"throw",e)}o(void 0)})},function(e){return o.apply(this,arguments)}),[c,d,p]),T=j.map(function(e){return{key:e.username,label:(null==e?void 0:e.nickname)||(null==e?void 0:e.username)||"",onClick:function(){return _(e)}}});return k||j.length?1===j.length?t().createElement(r.Tooltip,{title:d("Ask AI")},t().createElement(r.Button,{type:"text",size:"small",icon:t().createElement(n.RobotOutlined,null),loading:O||k,onClick:function(e){e.stopPropagation(),_(j[0])}},d("Ask AI"))):t().createElement(r.Tooltip,{title:d("Ask AI")},t().createElement(r.Dropdown,{menu:{items:T},trigger:["click"],placement:"bottomRight",disabled:O||k},t().createElement(r.Button,{type:"text",size:"small",icon:t().createElement(n.RobotOutlined,null),loading:O||k,onClick:function(e){return e.stopPropagation()}},d("Ask AI")))):null},C=function(e){var n=e.file;return t().createElement(k,null,t().createElement(S,{file:n}))},O=m(41);function P(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 j(e,t,n,r,i,l,o){try{var a=e[l](o),u=a.value}catch(e){n(e);return}a.done?t(u):Promise.resolve(u).then(r,i)}function _(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var l=e.apply(t,n);function o(e){j(l,r,i,o,a,"next",e)}function a(e){j(l,r,i,o,a,"throw",e)}o(void 0)})}}function T(e,t,n){return(T=z()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&F(i,n.prototype),i}).apply(null,arguments)}function R(e){return(R=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function A(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 I(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 F(e,t){return(F=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function L(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 l=[],o=!0,a=!1;try{for(i=i.call(e);!(o=(n=i.next()).done)&&(l.push(n.value),!t||l.length!==t);o=!0);}catch(e){a=!0,r=e}finally{try{o||null==i.return||i.return()}finally{if(a)throw r}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return P(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 P(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 N(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function B(e){var t="function"==typeof Map?new Map:void 0;return(B=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 T(e,arguments,R(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),F(n,e)})(e)}function z(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(z=function(){return!!e})()}function U(e,t){var n,r,i,l,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return l={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function a(l){return function(a){var u=[l,a];if(n)throw TypeError("Generator is already executing.");for(;o;)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 o.label++,{value:u[1],done:!1};case 5:o.label++,r=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(i=(i=o.trys).length>0&&i[i.length-1])&&(6===u[0]||2===u[0])){o=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){o.label=u[1];break}if(6===u[0]&&o.label<i[1]){o.label=i[1],i=u;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(u);break}i[2]&&o.ops.pop(),o.trys.pop();continue}u=t.call(e,o)}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 D=["application/pdf"],M=["image/png","image/jpeg","image/gif","image/webp","image/svg+xml","image/bmp"],W=["text/plain","text/csv","text/html","text/css","text/javascript","application/json","application/xml","text/xml","text/yaml","application/x-yaml"],q=["application/vnd.openxmlformats-officedocument.wordprocessingml.document"],V=["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.ms-excel"],H=["pdf"],X=["png","jpg","jpeg","gif","webp","svg","bmp"],G=["txt","csv","html","css","js","json","xml","log","md","yaml","yml","xaml"],$=["docx"],J=["xlsx","xls"],Y=["application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.ms-powerpoint"],K=["pptx","ppt"],Q={png:"png-200-200.png",jpg:"jpeg-200-200.png",jpeg:"jpeg-200-200.png",gif:"gif-200-200.png",webp:"png-200-200.png",bmp:"png-200-200.png",svg:"svg-200-200.png"},Z={"image/png":Q.png,"image/jpeg":Q.jpeg,"image/jpg":Q.jpeg,"image/gif":Q.gif,"image/webp":Q.webp,"image/bmp":Q.bmp,"image/svg+xml":Q.svg};function ee(e){if(!e||"string"==typeof e)return e;var t,n,r,i,l,o,a,u,c,s,d,f,p,m,v,g,h,y,b,w,x,E,k,S,C=e.response;return C&&(void 0===C?"undefined":N(C))==="object"?I(A({},C,e),{id:null!=(l=e.id)?l:C.id,uid:null!=(o=e.uid)?o:C.uid,url:null!=(a=e.url)?a:C.url,preview:e.preview||C.preview,filename:null!=(u=e.filename)?u:C.filename,name:null!=(c=e.name)?c:C.name,title:null!=(s=e.title)?s:C.title,extname:null!=(d=e.extname)?d:C.extname,mimetype:null!=(f=e.mimetype)?f:C.mimetype,size:null!=(p=e.size)?p:C.size,path:null!=(m=e.path)?m:C.path,storageId:null!=(v=e.storageId)?v:C.storageId,storageType:null!=(y=null!=(h=null!=(g=e.storageType)?g:C.storageType)?h:null==(t=e.storage)?void 0:t.type)?y:null==(n=C.storage)?void 0:n.type,storageName:null!=(x=null!=(w=null!=(b=e.storageName)?b:C.storageName)?w:null==(r=e.storage)?void 0:r.name)?x:null==(i=C.storage)?void 0:i.name,storage:null!=(E=e.storage)?E:C.storage,collectionName:null!=(k=e.collectionName)?k:C.collectionName,lastModified:null!=(S=e.lastModified)?S:C.lastModified}):e}var et=function(e){var t=ee(e),n=("string"==typeof t?t:(null==t?void 0:t.extname)||(null==t?void 0:t.name)||(null==t?void 0:t.filename)||(null==t?void 0:t.url)||"").split("?")[0].split("#")[0],r=n.lastIndexOf(".");return -1!==r?n.slice(r+1).toLowerCase().replace(/^\./,""):""},en=function(e){var t=ee(e),n="string"==typeof t?t:(null==t?void 0:t.url)||(null==t?void 0:t.preview)||(null==t?void 0:t.path);return n?n.startsWith("https://")||n.startsWith("http://")?n:"".concat(location.origin,"/").concat(n.replace(/^\//,"")):""},er=function(e){if("string"==typeof e)return e;var t=ee(e);return t?[t.id,t.uid,t.url,t.preview,t.path,t.storageId,t.storageType,t.storageName,t.collectionName,t.lastModified,t.size].filter(function(e){return null!=e&&""!==e}).join(":"):""},ei=function(e){var t=ee(e);if((null==t?void 0:t.mimetype)&&D.includes(t.mimetype))return!0;var n=et(e);return!!n&&H.includes(n)},el=function(e){var t=ee(e);if((null==t?void 0:t.mimetype)&&M.includes(t.mimetype)||(null==t?void 0:t.mimetype)&&(0,i.matchMimetype)(t,"image/*"))return!0;var n=et(e);return!!n&&X.includes(n)},eo=function(e){var t=ee(e);if((null==t?void 0:t.mimetype)&&W.includes(t.mimetype))return!0;var n=et(e);return!!n&&G.includes(n)},ea=function(e){var t=ee(e);if((null==t?void 0:t.mimetype)&&q.includes(t.mimetype))return!0;var n=et(e);return!!n&&$.includes(n)},eu=function(e){var t=ee(e);if((null==t?void 0:t.mimetype)&&V.includes(t.mimetype))return!0;var n=et(e);return!!n&&J.includes(n)},ec=function(e){var t=ee(e);if((null==t?void 0:t.mimetype)&&Y.includes(t.mimetype))return!0;var n=et(e);return!!n&&K.includes(n)},es=function(e){var t=ee(e);return t?t.title&&t.extname?"".concat(t.title).concat(t.extname):t.filename||t.name||t.title||"download":"download"},ed=new Map;function ef(e){var t,n,r,i,l,o=ee(e);return{id:null==o?void 0:o.id,uid:null==o?void 0:o.uid,url:null==o?void 0:o.url,preview:null==o?void 0:o.preview,filename:(null==o?void 0:o.filename)||(null==o?void 0:o.name),name:(null==o?void 0:o.name)||(null==o?void 0:o.filename),title:null==o?void 0:o.title,extname:null==o?void 0:o.extname,mimetype:null==o?void 0:o.mimetype,size:null==o?void 0:o.size,path:null==o?void 0:o.path,storageId:null!=(l=null!=(i=null==o?void 0:o.storageId)?i:null==o?void 0:o.storage_id)?l:null==o||null==(t=o.storage)?void 0:t.id,storage_id:null==o?void 0:o.storage_id,storageType:(null==o?void 0:o.storageType)||(null==o||null==(n=o.storage)?void 0:n.type),storageName:(null==o?void 0:o.storageName)||(null==o||null==(r=o.storage)?void 0:r.name),storage:null==o?void 0:o.storage,collectionName:null==o?void 0:o.collectionName,lastModified:null==o?void 0:o.lastModified}}function ep(e){if(!e)return!1;try{var t=new URL(e,location.origin);if(t.origin!==location.origin)return!1;return["/api/filePreviewAuth:download","/api/extStorage:download","/api/skillHub:download","/api/worker-monitor","/api/carboneTemplates:download","/api/attachments:stream","/api/attachments:sftpStream"].some(function(e){return t.pathname===e||t.pathname.startsWith("".concat(e,"/"))||t.pathname.startsWith("".concat(e,":"))})}catch(e){return!1}}function em(){return(em=_(function(e,t){var n,r;return U(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 ev(e,t){return eg.apply(this,arguments)}function eg(){return(eg=_(function(e,t){var n,r,i,l=arguments;return U(this,function(o){if(!(n=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"inline",n=ef("string"==typeof e?{url:e}:e||{}),r=en(e);if(r&&ep(r))return r;if(function(e,t){var n,r,i,l=ef("string"==typeof e?{url:e}:e||{}),o=l.collectionName||"attachments";return null!=(l.id||l.uid)&&("s3-private"===(i=(r=ef("string"==typeof e?{url:e}:e||{})).storageType||(null==(n=r.storage)?void 0:n.type))||"aws-s3-private"===i||"attachments"===o&&!t)}(e,r)){var i=ef("string"==typeof e?{url:e}:e||{}),l=i.id||i.uid;if(null==l)return"";var o=new URLSearchParams({filterByTk:String(l),mode:t,collection:i.collectionName||"attachments"});return"/api/attachments:stream?".concat(o.toString())}var a=n.id||n.uid;if(null!=a){var u,c=n.collectionName||"attachments",s=new URLSearchParams;s.set("id",String(a)),s.set("collection",c),r&&s.set("url",r);var d=n.storageId||n.storage_id||(null==(u=n.storage)?void 0:u.id);return null!=d&&""!==d&&s.set("storageId",String(d)),(n.filename||n.name)&&s.set("filename",n.filename||n.name),n.mimetype&&s.set("mimetype",n.mimetype),"/api/filePreviewAuth:download?".concat(s.toString())}return r||""}(e,l.length>2&&void 0!==l[2]?l[2]:"inline"))||n.endsWith("?"))throw Error("No file URL");return r="".concat(t?"auth":"anon",":").concat(t||"",":").concat(er(e)||n),(i=ed.get(r))||(i=(function(e,t){return em.apply(this,arguments)})(n,t).catch(function(e){throw ed.delete(r),e}),ed.set(r,i)),[2,i]})})).apply(this,arguments)}function eh(e,t){return ey.apply(this,arguments)}function ey(){return(ey=_(function(e,t){var n,r,i,l;return U(this,function(o){switch(o.label){case 0:return[4,ev(e,t,"attachment")];case 1:return n=o.sent(),r=es(e),(i=document.createElement("a")).href=l=URL.createObjectURL(n),i.download=r,document.body.appendChild(i),i.click(),document.body.removeChild(i),setTimeout(function(){return URL.revokeObjectURL(l)},1e3),[2]}})})).apply(this,arguments)}function eb(t,n){var r=L((0,e.useState)(null),2),i=r[0],l=r[1],o=L((0,e.useState)(!0),2),a=o[0],u=o[1],c=L((0,e.useState)(null),2),s=c[0],d=c[1],f=(0,e.useRef)(null),p=(0,e.useRef)(t);p.current=t;var m=er(t);return(0,e.useEffect)(function(){var e=!1,t=p.current;if(!(en(t)||"string"!=typeof t&&((null==t?void 0:t.id)||(null==t?void 0:t.uid)))){u(!1),d("No file URL");return}return u(!0),d(null),ev(t,n).then(function(t){if(!e){var n=URL.createObjectURL(t);f.current=n,l(n),u(!1)}}).catch(function(t){e||(d(t.message||"Failed to load"),u(!1))}),function(){e=!0,f.current&&(URL.revokeObjectURL(f.current),f.current=null)}},[m,n]),{blobUrl:i,loading:a,error:s}}function ew(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 ex(e){var n=e.message;return t().createElement("div",{style:{padding:20,textAlign:"center",color:"#ff4d4f"}},n)}function eE(e){var i=e.file,l=e.title,o=e.ocrStatus,u=e.isOcrSupported,c=a();return t().createElement("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,paddingRight:40}},t().createElement(r.Space,{size:8,style:{minWidth:0,overflow:"hidden"}},t().createElement("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:600},title:l},l),function(){if(!u||!o)return null;switch(o){case"pending-ocr":return t().createElement(r.Tag,{color:"processing",icon:t().createElement(n.SyncOutlined,{spin:!0})},c("OCR Pending"));case"waiting-verify":return t().createElement(r.Tag,{color:"warning",icon:t().createElement(n.ClockCircleOutlined,null)},c("Waiting Verify"));case"verified":case"accepted":return t().createElement(r.Tag,{color:"success",icon:t().createElement(n.CheckCircleOutlined,null)},c("OCR Verified"));case"rejected":return t().createElement(r.Tag,{color:"error"},c("OCR Rejected"));case"failed":return t().createElement(r.Tag,{color:"error"},c("OCR Failed"));default:return t().createElement(r.Tag,{color:"default"},c("No OCR"))}}()),t().createElement(C,{file:i}))}function ek(e){var n,r=e.file,l=(0,i.useAPIClient)(),o=a(),u=eb(r,(null==(n=l.auth)?void 0:n.token)||""),c=u.blobUrl,s=u.loading,d=u.error;return s?t().createElement(ew,{message:o("Loading preview...")}):d||!c?t().createElement(ex,{message:o("Failed to load file preview")}):t().createElement("iframe",{src:c,width:"100%",height:"100%",style:{border:"none"}})}function eS(e){var n,r=e.file,l=(0,i.useAPIClient)(),o=a(),u=eb(r,(null==(n=l.auth)?void 0:n.token)||""),c=u.blobUrl,s=u.loading,d=u.error;return s?t().createElement(ew,{message:o("Loading preview...")}):d||!c?t().createElement(ex,{message:o("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 eC(n){var r,l,o,u,c,s,d,f,p,m,v,g,h=n.file,y=(0,i.useAPIClient)(),b=a(),w=(null==(g=y.auth)?void 0:g.token)||"",x=(l=(r=L((0,e.useState)(null),2))[0],o=r[1],c=(u=L((0,e.useState)(!0),2))[0],s=u[1],f=(d=L((0,e.useState)(null),2))[0],p=d[1],(m=(0,e.useRef)(h)).current=h,v=er(h),(0,e.useEffect)(function(){var e=!1,t=m.current;if(!(en(t)||"string"!=typeof t&&((null==t?void 0:t.id)||(null==t?void 0:t.uid)))){s(!1),p("No file URL");return}return s(!0),p(null),ev(t,w).then(function(e){return e.text()}).then(function(t){e||(o(t),s(!1))}).catch(function(t){e||(p(t.message||"Failed to load"),s(!1))}),function(){e=!0}},[v,w]),{text:l,loading:c,error:f}),E=x.text,k=x.loading,S=x.error;return k?t().createElement(ew,{message:b("Loading preview...")}):S||null===E?t().createElement(ex,{message:b("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"}},E)}function eO(n){var r,l=n.file,o=(0,i.useAPIClient)(),u=a(),c=(null==(r=o.auth)?void 0:r.token)||"",s=(0,e.useRef)(null),d=(0,e.useRef)(l);d.current=l;var f=er(l),p=L((0,e.useState)(!0),2),v=p[0],g=p[1],h=L((0,e.useState)(null),2),y=h[0],b=h[1];return(0,e.useEffect)(function(){var e=!1,t=d.current;if(!(en(t)||"string"!=typeof t&&((null==t?void 0:t.id)||(null==t?void 0:t.uid)))||!s.current){g(!1),b("No file URL");return}return g(!0),b(null),_(function(){var n,r,i;return U(this,function(l){switch(l.label){case 0:return l.trys.push([0,4,,5]),[4,ev(t,c)];case 1:if(n=l.sent(),e)return[2];return[4,O("imported_-1dm6lbf_component",m.e("374").then(m.bind(m,335)))];case 2:if(r=l.sent(),e||!s.current)return[2];return s.current.innerHTML="",[4,r.renderAsync(n,s.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 l.sent(),g(!1),[3,5];case 4:if(i=l.sent(),e)return[2];return b(i.message||"Failed to render DOCX"),g(!1),[3,5];case 5:return[2]}})})(),function(){e=!0}},[f,c]),t().createElement("div",{style:{width:"100%",height:"100%",position:"relative"}},v&&t().createElement(ew,{message:u("Loading preview...")}),y&&t().createElement(ex,{message:u("Failed to load file preview")}),t().createElement("div",{ref:s,style:{width:"100%",height:"100%",overflow:"auto",display:v||y?"none":"block"}}))}function eP(n){var r,l=n.file,o=(0,i.useAPIClient)(),u=a(),c=(null==(r=o.auth)?void 0:r.token)||"",s=(0,e.useRef)(null),d=(0,e.useRef)(l);d.current=l;var f=er(l),p=L((0,e.useState)(!0),2),v=p[0],g=p[1],h=L((0,e.useState)(null),2),y=h[0],b=h[1],w=L((0,e.useState)([]),2),x=w[0],E=w[1],k=L((0,e.useState)(""),2),S=k[0],C=k[1],P=L((0,e.useState)({}),2),j=P[0],T=P[1];return(0,e.useEffect)(function(){var e=!1,t=d.current;if(!(en(t)||"string"!=typeof t&&((null==t?void 0:t.id)||(null==t?void 0:t.uid)))){g(!1),b("No file URL");return}return g(!0),b(null),_(function(){var n,r,i,l,o,a,u,s,d,f,p,v,h,y;return U(this,function(w){switch(w.label){case 0:return w.trys.push([0,4,,5]),[4,ev(t,c)];case 1:if(n=w.sent(),e)return[2];return[4,O("imported_-1lj2ifg_component",m.e("166").then(m.bind(m,907)))];case 2:if(r=w.sent(),e)return[2];return[4,n.arrayBuffer()];case 3:if(i=w.sent(),e)return[2];o=(l=r.read(i,{type:"array"})).SheetNames,a={},u=!0,s=!1,d=void 0;try{for(f=o[Symbol.iterator]();!(u=(p=f.next()).done);u=!0)v=p.value,h=l.Sheets[v],a[v]=r.utils.sheet_to_html(h,{id:"xlsx-preview-table"})}catch(e){s=!0,d=e}finally{try{u||null==f.return||f.return()}finally{if(s)throw d}}if(e)return[2];return E(o),C(o[0]||""),T(a),g(!1),[3,5];case 4:if(y=w.sent(),e)return[2];return b(y.message||"Failed to render XLSX"),g(!1),[3,5];case 5:return[2]}})})(),function(){e=!0}},[f,c]),t().createElement("div",{style:{width:"100%",height:"100%",display:"flex",flexDirection:"column"}},v&&t().createElement(ew,{message:u("Loading preview...")}),y&&t().createElement(ex,{message:u("Failed to load file preview")}),!v&&!y&&t().createElement(t().Fragment,null,x.length>1&&t().createElement("div",{style:{display:"flex",gap:0,borderBottom:"1px solid #e8e8e8",background:"#fafafa",padding:"0 8px",flexShrink:0,overflowX:"auto"}},x.map(function(e){return t().createElement("button",{key:e,onClick:function(){return C(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:s,style:{flex:1,overflow:"auto",padding:0},dangerouslySetInnerHTML:{__html:j[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 ")))}function ej(n){var r,l=n.file,o=(0,i.useAPIClient)(),u=a(),c=(null==(r=o.auth)?void 0:r.token)||"",s=L((0,e.useState)(!0),2),d=s[0],f=s[1],p=L((0,e.useState)(null),2),v=p[0],g=p[1],h=L((0,e.useState)(null),2),y=h[0],b=h[1],w=L((0,e.useState)(null),2),x=w[0],E=w[1],k=(0,e.useRef)(l);k.current=l;var S=er(l);return(0,e.useEffect)(function(){var e=!1,t=k.current;if(!(en(t)||"string"!=typeof t&&((null==t?void 0:t.id)||(null==t?void 0:t.uid)))){f(!1),g("No file URL");return}return f(!0),g(null),_(function(){var n,r,i,l;return U(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,Promise.all([ev(t,c),O("imported_tpp3om_component",m.e("514").then(m.bind(m,581)))])];case 1:if(r=(n=L.apply(void 0,[o.sent(),2]))[0],i=n[1],e)return[2];return b(r),E(function(){return i.PptxPreview}),f(!1),[3,3];case 2:if(l=o.sent(),e)return[2];return g(l.message||"Failed to render PPTX"),f(!1),[3,3];case 3:return[2]}})})(),function(){e=!0}},[S,c]),t().createElement("div",{style:{width:"100%",height:"100%",position:"relative"}},d&&t().createElement(ew,{message:u("Loading preview...")}),v&&t().createElement(ex,{message:u("Failed to load file preview")}),!d&&!v&&x&&t().createElement("div",{style:{width:"100%",height:"100%",overflow:"auto"}},t().createElement(x,{file:y})))}var e_=function(l){return function(o){var u,c=o.open,s=o.onOpenChange,d=o.onClose,f=o.file,p=o.index,m=o.list,v=o.onSwitchIndex;o.onDownload;var g=(0,i.useAPIClient)(),h=a(),y=L((0,e.useState)("visual"),2),b=y[0],w=y[1],x=(0,e.useCallback)((u=_(function(e){var t,n,i;return U(this,function(l){switch(l.label){case 0:if(!(n=e||f))return[2];i=(null==(t=g.auth)?void 0:t.token)||"",l.label=1;case 1:return l.trys.push([1,3,,4]),[4,eh(n,i)];case 2:return l.sent(),[3,4];case 3:return l.sent(),r.message.error(h("Failed to download file")),[3,4];case 4:return[2]}})}),function(e){return u.apply(this,arguments)}),[f,g,h]);if("boolean"!=typeof c)return t().createElement(l,I(A({},o),{onDownload:x}));var E=es(f),k="number"==typeof p&&!!v&&p>0,S="number"==typeof p&&!!v&&p<m.length-1;return t().createElement(r.Modal,{open:c,title:t().createElement(eE,{file:f,title:E}),onCancel:function(){null==s||s(!1),null==d||d(),w("visual")},footer:t().createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",width:"100%"}},t().createElement("div",{key:"left-actions"},t().createElement(r.Button,{onClick:function(){return w(function(e){return"visual"===e?"raw":"visual"})}},"visual"===b?h("View Raw Parsed Text"):h("View Visual Preview"))),t().createElement(r.Space,{size:14,style:{fontSize:"20px"}},t().createElement(n.LeftOutlined,{style:{cursor:k?"pointer":"not-allowed"},onClick:function(){return k&&(null==v?void 0:v(p-1))}}),t().createElement(n.RightOutlined,{style:{cursor:S?"pointer":"not-allowed"},onClick:function(){return S&&(null==v?void 0:v(p+1))}}),t().createElement(n.DownloadOutlined,{onClick:function(){return x(f)}}))),width:"90%",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"}},"raw"===b?t().createElement(eT,{file:f}):t().createElement(l,I(A({},o),{onDownload:x}))))}};function eT(l){var o=l.file,u=(0,i.useAPIClient)(),c=a(),s=L((0,e.useState)(""),2),d=s[0],f=s[1],p=L((0,e.useState)(!0),2),m=p[0],v=p[1],g=L((0,e.useState)(null),2),h=g[0],y=g[1],b=(0,i.useComponent)("MarkdownVditor"),w=(0,i.useComponent)("Markdown.Void");return((0,e.useEffect)(function(){var e=!1;return _(function(){var t,n,r,i,l,a,c,s,d,p;return U(this,function(m){switch(m.label){case 0:v(!0),y(null),m.label=1;case 1:return m.trys.push([1,4,,5]),[4,ev(o,(null==(t=u.auth)?void 0:t.token)||"")];case 2:if(i=m.sent(),e)return[2];return(l=new FormData).append("file",i,es(o)),l.append("attachment",JSON.stringify(ef(o))),[4,u.request({url:"filePreviewAuth:getContent",method:"post",data:l,headers:{"Content-Type":"multipart/form-data"}})];case 3:if(a=m.sent(),e)return[2];return s=c=(null==a||null==(r=a.data)||null==(n=r.data)?void 0:n.content)||"",(d=c.match(/<file_preview[^>]*>([\s\S]*?)<\/file_preview>/i))&&(s=d[1].trim()),f(s),v(!1),[3,5];case 4:if(p=m.sent(),e)return[2];return y(p.message||"Failed to fetch raw text"),v(!1),[3,5];case 5:return[2]}})})(),function(){e=!0}},[o,u]),m)?t().createElement(r.Spin,{size:"large",tip:c("Extracting raw text..."),style:{marginTop:"40px"}}):h?t().createElement(r.Alert,{type:"error",message:h,style:{width:"100%",margin:"20px"}}):d?t().createElement("div",{style:{width:"100%",height:"100%",display:"flex",flexDirection:"column",position:"relative"}},t().createElement("span",{onClick:function(){if(navigator.clipboard&&navigator.clipboard.writeText)navigator.clipboard.writeText(d).then(function(){r.message.success(c("Copied to clipboard"))}).catch(function(e){r.message.error(c("Failed to copy")),console.error("Copy error",e)});else{var e=document.createElement("textarea");e.value=d,document.body.appendChild(e),e.select();try{document.execCommand("copy"),r.message.success(c("Copied to clipboard"))}catch(e){r.message.error(c("Failed to copy"))}document.body.removeChild(e)}},style:{position:"absolute",top:"20px",right:"25px",zIndex:10,cursor:"pointer",padding:"4px 10px",background:"rgba(255, 255, 255, 0.85)",border:"1px solid #e8e8e8",borderRadius:"4px",color:"#1890ff",display:"flex",alignItems:"center",gap:"6px",boxShadow:"0 2px 4px rgba(0,0,0,0.05)",fontSize:"13px"},title:c("Copy")},t().createElement(n.CopyOutlined,null),c("Copy")),t().createElement("div",{style:{flex:1,overflow:"auto",padding:"20px",textAlign:"left"}},t().createElement("style",null,"\n .hide-vditor-toolbar .vditor-toolbar {\n display: none !important;\n }\n .hide-vditor-toolbar .vditor {\n border: none !important;\n }\n "),t().createElement("div",{className:"hide-vditor-toolbar",style:{height:"100%"}},b?t().createElement(b,{value:d,disabled:!1}):w?t().createElement(w,{content:d}):t().createElement("pre",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"monospace",fontSize:"13px"}},d)))):t().createElement(r.Alert,{type:"info",style:{width:"100%",margin:"20px"},description:c("No text content could be extracted from this file."),showIcon:!0})}function eR(l){var o,u,c=l.index,s=l.list,d=l.onSwitchIndex,f=a(),p=(0,i.useAPIClient)(),m=s[c],v=L((0,e.useState)(!1),2),g=v[0],h=v[1],y=L((0,e.useState)("visual"),2),b=y[0],w=y[1],x=L((0,e.useState)("preview"),2),E=x[0],k=x[1],S=L((0,e.useState)("no-ocr"),2),C=S[0],O=S[1],P=L((0,e.useState)(null),2),j=P[0],T=P[1],R=L((0,e.useState)(null),2),A=R[0],I=R[1],F=(0,e.useMemo)(function(){return!!m&&(ei(m)||el(m))},[m]),N=(0,i.useComponent)("OcrVerifyBlock"),B=(0,e.useCallback)(_(function(){var e,t,n;return U(this,function(r){switch(r.label){case 0:if(!(null==m?void 0:m.id))return[2,null];return[4,p.request({url:"filePreviewAuth:getOcrStatus",method:"post",data:{attachmentId:m.id}})];case 1:return(n=null==(t=r.sent())||null==(e=t.data)?void 0:e.data)&&(T(n.id||null),O(n.status||"no-ocr"),I(n.error||null)),[2,n]}})}),[p,null==m?void 0:m.id]);(0,e.useEffect)(function(){if(null==m?void 0:m.id){var e=!1;return T(null),O("no-ocr"),I(null),B().then(function(){if(e)return}).catch(console.error),function(){e=!0}}},[null==m?void 0:m.id,B]),(0,e.useEffect)(function(){if("pending-ocr"===C&&(null==m?void 0:m.id)){var e,t=null,n=!1,i=(e=_(function(){var e;return U(this,function(l){switch(l.label){case 0:return l.trys.push([0,2,,3]),[4,B()];case 1:if(e=l.sent(),n)return[2];return e&&("pending-ocr"!==e.status?"failed"===e.status?r.message.error(e.error||f("OCR processing failed")):r.message.success(f("OCR processing completed!")):t=setTimeout(i,3e3)),[3,3];case 2:return console.error("Polling error",l.sent()),t=setTimeout(i,3e3),[3,3];case 3:return[2]}})}),function(){return e.apply(this,arguments)});return t=setTimeout(i,3e3),function(){n=!0,t&&clearTimeout(t)}}},[C,null==m?void 0:m.id,B,f]);var z=(o=_(function(){var e,t,n,i;return U(this,function(l){switch(l.label){case 0:if(!(null==m?void 0:m.id))return[2];l.label=1;case 1:return l.trys.push([1,3,,4]),O("pending-ocr"),[4,p.request({url:"filePreviewAuth:runOcr",method:"post",data:{attachmentId:m.id}})];case 2:return(n=null==(t=l.sent())||null==(e=t.data)?void 0:e.data)&&(T(n.id||null),O(n.status||"pending-ocr"),I(n.error||null)),r.message.info(f("OCR process started in the background.")),[3,4];case 3:return i=l.sent(),r.message.error((null==i?void 0:i.message)||f("Failed to start OCR process.")),O("no-ocr"),[3,4];case 4:return[2]}})}),function(){return o.apply(this,arguments)}),D=(0,e.useCallback)((u=_(function(e){var t,n,i,l;return U(this,function(o){switch(o.label){case 0:null==e||null==(t=e.preventDefault)||t.call(e),null==e||null==(n=e.stopPropagation)||n.call(e),l=(null==(i=p.auth)?void 0:i.token)||"",h(!0),o.label=1;case 1:return o.trys.push([1,3,4,5]),[4,eh(m,l)];case 2:return o.sent(),[3,5];case 3:return o.sent(),r.message.error(f("Failed to download file")),[3,5];case 4:return h(!1),[7];case 5:return[2]}})}),function(e){return u.apply(this,arguments)}),[m,p,f]),M=(0,e.useCallback)(function(){d(null),w("visual"),k("preview")},[d]),W=(0,e.useMemo)(function(){return ei(m)?ek:el(m)?eS:eo(m)?eC:ea(m)?eO:eu(m)?eP:ec(m)?ej:null},[m]),q=null!=W||"raw"===b,V=[{key:"preview",label:t().createElement("span",null,t().createElement(n.EyeOutlined,null)," ",f("Visual Preview")),children:t().createElement("div",{style:{height:"70vh",width:"100%",overflow:"auto",background:"#f5f5f5",display:"flex",justifyContent:"center",alignItems:"center"}},W?t().createElement(W,{file:m}):null)},{key:"ocr",label:t().createElement("span",null,t().createElement(n.ScanOutlined,null)," ",f("OCR & Verify")),children:t().createElement("div",{style:{height:"70vh",width:"100%",display:"flex",flexDirection:"column"}},"no-ocr"===C&&t().createElement("div",{style:{display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",height:"100%",padding:"40px",background:"#fafafa",borderRadius:"8px"}},t().createElement(n.ScanOutlined,{style:{fontSize:"64px",color:"#1890ff",marginBottom:"20px"}}),t().createElement("h3",{style:{fontSize:"18px",fontWeight:600,marginBottom:"10px"}},f("Word-level Song ngữ (English & Vietnamese) OCR")),t().createElement("p",{style:{color:"#8c8c8c",maxWidth:"480px",textAlign:"center",marginBottom:"24px"}},f("Chưa c\xf3 dữ liệu OCR cấp độ Từ (Word-level) cho tệp n\xe0y. H\xe3y chạy nhận dạng Tesseract-OCR để bắt đầu đối so\xe1t v\xe0 verify toạ độ.")),t().createElement(r.Button,{type:"primary",size:"large",icon:t().createElement(n.ThunderboltOutlined,null),onClick:z},f("Run Tesseract OCR"))),"pending-ocr"===C&&t().createElement("div",{style:{display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",height:"100%",padding:"40px"}},t().createElement(r.Spin,{size:"large",tip:f("Analyzing layout structure and running song ngữ OCR...")}),t().createElement("p",{style:{color:"#8c8c8c",marginTop:"20px",fontSize:"13px",textAlign:"center"}},f("Extracting word-level coordinates via Tesseract-OCR. This will automatically refresh when complete."))),"failed"===C&&t().createElement("div",{style:{padding:"40px"}},t().createElement(r.Alert,{type:"error",showIcon:!0,message:f("OCR processing failed"),description:A||f("Please try running OCR again."),style:{marginBottom:24}}),t().createElement(r.Button,{type:"primary",icon:t().createElement(n.ThunderboltOutlined,null),onClick:z},f("Run Tesseract OCR"))),["waiting-verify","verified","accepted","rejected"].includes(C)&&t().createElement("div",{style:{flex:1,height:"100%",overflow:"hidden"}},N&&j?t().createElement(N,{collection:"attachmentOcrResults",recordId:j,pdfField:"attachment",jsonField:"data",statusField:"status"}):N?t().createElement("div",{style:{padding:"20px"}},t().createElement(r.Alert,{type:"error",message:f("OCR result record not found"),description:f("Please try running OCR again."),showIcon:!0})):t().createElement("div",{style:{padding:"20px"}},t().createElement(r.Alert,{type:"error",message:f("Plugin OCR Verify Block is not enabled"),description:f("Please enable the plugin-ocr-verify-block plugin to display the verify splitter layout."),showIcon:!0}))))}];return t().createElement(r.Modal,{open:null!=c,title:t().createElement(eE,{file:m,title:(null==m?void 0:m.title)||(null==m?void 0:m.filename)||(null==m?void 0:m.name)||"File",ocrStatus:C,isOcrSupported:F}),onCancel:M,footer:t().createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",width:"100%"}},t().createElement("div",{key:"left-actions"},!F&&t().createElement(r.Button,{onClick:function(){return w(function(e){return"visual"===e?"raw":"visual"})}},"visual"===b?f("View Raw Parsed Text"):f("View Visual Preview"))),t().createElement(r.Space,null,t().createElement(r.Button,{key:"download",onClick:D,loading:g},f("Download")),t().createElement(r.Button,{key:"close",onClick:M},f("Close")))),width:q?"90%":520,centered:!0},F?t().createElement(r.Tabs,{activeKey:E,onChange:function(e){return k(e)},items:V,style:{width:"100%",height:"100%"}}):t().createElement("div",{style:{maxWidth:"100%",maxHeight:q?"calc(100vh - 256px)":"auto",height:q?"70vh":"auto",width:"100%",background:"white",display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",overflowY:"auto"}},"raw"===b?t().createElement(eT,{file:m}):W?t().createElement(W,{file:m}):t().createElement(r.Alert,{type:"info",style:{width:"100%"},description:f("This file type cannot be previewed. Click Download to save the file."),showIcon:!0})))}function eA(n){var l=n.file,o=(0,i.useAPIClient)(),u=a(),c=(0,e.useCallback)(_(function(){var e,t;return U(this,function(n){switch(n.label){case 0:t=(null==(e=o.auth)?void 0:e.token)||"",n.label=1;case 1:return n.trys.push([1,3,,4]),[4,eh(l,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]}})}),[l,o,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 eI=function(e){var o;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function a(){var e,t;if(!(this instanceof a))throw TypeError("Cannot call a class as a function");return e=a,t=arguments,e=R(e),function(e,t){if(t&&("object"===N(t)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,z()?Reflect.construct(e,t||[],R(this).constructor):e.apply(this,t))}return a.prototype=Object.create(e&&e.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),e&&F(a,e),o=[{key:"load",value:function(){var e=this;return _(function(){return U(this,function(o){return e.patchUploadPreviewBase64Fallback(),!function(e){try{i=e.pm.get("ai")}catch(e){return}var i,l,o=null==i?void 0:i.aiManager;if(null==o?void 0:o.registerWorkContext)try{(null==(l=o.getWorkContext)?void 0:l.call(o,w))||o.registerWorkContext(w,{name:w,tag:{Component:function(e){var i=e.item;return t().createElement(r.Space,null,t().createElement(n.FileTextOutlined,null),t().createElement("span",null,(null==i?void 0:i.title)||""))}},chatbox:{Component:function(e){var i=e.item;return t().createElement(r.Space,null,t().createElement(n.FileTextOutlined,null),t().createElement("span",null,(null==i?void 0:i.title)||""))}}})}catch(e){}}(e.app),i.attachmentFileTypes.add({match:function(){return!0},Previewer:eR}),l.filePreviewTypes.add({match:function(){return!0},Previewer:e_(eA)}),l.filePreviewTypes.add({match:ei,Previewer:e_(ek)}),l.filePreviewTypes.add({match:el,getThumbnailURL:function(e){var t,n,r,i,l,o,a,u;return(u=[null==(a=ee(e))?void 0:a.preview,null==a?void 0:a.url].find(function(e){return"string"==typeof e&&e}))&&!ep(u)?u:(n=et(t=ee(a)),r="string"==typeof(null==t?void 0:t.mimetype)?t.mimetype.toLowerCase():"",i=Q[n]||Z[r]||"unknown-200-200.png",l="file-placeholder/".concat(i),o="undefined"==typeof window?"/":window.__nocobase_dev_public_path__||window.__nocobase_public_path__||"/","".concat(o.replace(/\/?$/,"/")).concat(l.replace(/^\//,"")))},Previewer:e_(eS)}),l.filePreviewTypes.add({match:eo,Previewer:e_(eC)}),l.filePreviewTypes.add({match:ea,Previewer:e_(eO)}),l.filePreviewTypes.add({match:eu,Previewer:e_(eP)}),l.filePreviewTypes.add({match:ec,Previewer:e_(ej)}),[2]})})()}},{key:"patchUploadPreviewBase64Fallback",value:function(){if("undefined"!=typeof window){var e,t=null==(e=window.FileReader)?void 0:e.prototype;if(t&&!t.__filePreviewAuthBase64FallbackPatched){var n=t.readAsDataURL;"function"==typeof n&&(Object.defineProperty(t,"__filePreviewAuthBase64FallbackPatched",{value:!0,configurable:!0}),t.readAsDataURL=function(e){var t=this;if(null!=e)return n.call(this,e);setTimeout(function(){var e,n;try{Object.defineProperty(t,"result",{value:"",configurable:!0})}catch(e){}null==(e=t.onload)||e.call(t,new ProgressEvent("load")),null==(n=t.onloadend)||n.call(t,new ProgressEvent("loadend"))},0)})}}}}],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)}}(a.prototype,o),a}(B(i.Plugin)),eF=eI}(),v}()});
@@ -16,5 +16,7 @@ module.exports = {
16
16
  "@nocobase/plugin-file-manager": "2.0.57",
17
17
  "@nocobase/actions": "2.0.57",
18
18
  "@nocobase/server": "2.0.57",
19
- "@nocobase/utils": "2.0.57"
19
+ "@nocobase/utils": "2.0.57",
20
+ "sequelize": "6.35.2",
21
+ "@nocobase/database": "2.0.57"
20
22
  };
@@ -0,0 +1,2 @@
1
+ declare const _default: import("@nocobase/database").CollectionOptions;
2
+ export default _default;
@@ -24,22 +24,47 @@ var __copyProps = (to, from, except, desc) => {
24
24
  return to;
25
25
  };
26
26
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
- var attachments_exports = {};
28
- __export(attachments_exports, {
29
- default: () => attachments_default
27
+ var attachment_ocr_results_exports = {};
28
+ __export(attachment_ocr_results_exports, {
29
+ default: () => attachment_ocr_results_default
30
30
  });
31
- module.exports = __toCommonJS(attachments_exports);
32
- var attachments_default = {
33
- name: "attachments",
31
+ module.exports = __toCommonJS(attachment_ocr_results_exports);
32
+ var import_database = require("@nocobase/database");
33
+ var attachment_ocr_results_default = (0, import_database.defineCollection)({
34
+ name: "attachmentOcrResults",
35
+ title: "Attachment OCR results",
36
+ dumpRules: "required",
37
+ migrationRules: ["schema-only", "overwrite"],
38
+ indexes: [
39
+ {
40
+ fields: ["attachmentId"],
41
+ unique: true
42
+ },
43
+ {
44
+ fields: ["status"]
45
+ }
46
+ ],
34
47
  fields: [
35
48
  {
36
- name: "ocrStatus",
49
+ type: "belongsTo",
50
+ name: "attachment",
51
+ target: "attachments",
52
+ foreignKey: "attachmentId",
53
+ onDelete: "CASCADE",
54
+ interface: "m2o"
55
+ },
56
+ {
37
57
  type: "string",
58
+ name: "status",
38
59
  defaultValue: "no-ocr"
39
60
  },
40
61
  {
41
- name: "ocrData",
42
- type: "json"
62
+ type: "json",
63
+ name: "data"
64
+ },
65
+ {
66
+ type: "text",
67
+ name: "error"
43
68
  }
44
69
  ]
45
- };
70
+ });
@@ -0,0 +1,5 @@
1
+ import { Migration } from '@nocobase/server';
2
+ export default class extends Migration {
3
+ on: string;
4
+ up(): Promise<void>;
5
+ }
@@ -0,0 +1,65 @@
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 __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var move_ocr_fields_out_of_attachments_exports = {};
28
+ __export(move_ocr_fields_out_of_attachments_exports, {
29
+ default: () => move_ocr_fields_out_of_attachments_default
30
+ });
31
+ module.exports = __toCommonJS(move_ocr_fields_out_of_attachments_exports);
32
+ var import_server = require("@nocobase/server");
33
+ class move_ocr_fields_out_of_attachments_default extends import_server.Migration {
34
+ on = "afterLoad";
35
+ async up() {
36
+ const attachments = this.db.getCollection("attachments");
37
+ if (!attachments) {
38
+ return;
39
+ }
40
+ const queryInterface = this.db.sequelize.getQueryInterface();
41
+ const tableName = attachments.getTableNameWithSchema();
42
+ const columns = await queryInterface.describeTable(tableName).catch(() => null);
43
+ if (!columns) {
44
+ return;
45
+ }
46
+ await this.db.sequelize.transaction(async (transaction) => {
47
+ if (columns.ocrStatus) {
48
+ await queryInterface.removeColumn(tableName, "ocrStatus", { transaction });
49
+ }
50
+ if (columns.ocrData) {
51
+ await queryInterface.removeColumn(tableName, "ocrData", { transaction });
52
+ }
53
+ const fieldRepo = this.db.getRepository("fields");
54
+ if (fieldRepo) {
55
+ await fieldRepo.destroy({
56
+ filter: {
57
+ collectionName: "attachments",
58
+ name: ["ocrStatus", "ocrData"]
59
+ },
60
+ transaction
61
+ });
62
+ }
63
+ });
64
+ }
65
+ }
@@ -23,4 +23,5 @@ export declare class TesseractWorker {
23
23
  private listenRedisQueue;
24
24
  private startDbPolling;
25
25
  private processJob;
26
+ private updateOcrResult;
26
27
  }
@@ -129,15 +129,17 @@ class TesseractWorker {
129
129
  this.pollTimer = setInterval(async () => {
130
130
  if (!this.isRunning) return;
131
131
  try {
132
- const repo = this.db.getRepository("attachments");
132
+ const repo = this.db.getRepository("attachmentOcrResults");
133
133
  if (!repo) return;
134
134
  const record = await repo.findOne({
135
- filter: { ocrStatus: "pending-ocr" },
135
+ filter: { status: "pending-ocr" },
136
136
  sort: ["createdAt"]
137
137
  });
138
138
  if (record) {
139
- const id = record.get("id");
140
- await this.processJob(id);
139
+ const attachmentId = record.get("attachmentId");
140
+ if (attachmentId != null) {
141
+ await this.processJob(attachmentId);
142
+ }
141
143
  }
142
144
  } catch (err) {
143
145
  this.log.error(`[TesseractWorker] DB Polling error: ${err.message}`);
@@ -147,10 +149,16 @@ class TesseractWorker {
147
149
  async processJob(attachmentId) {
148
150
  this.log.info(`[TesseractWorker] Processing OCR Job for attachment ID ${attachmentId}`);
149
151
  const repo = this.db.getRepository("attachments");
150
- if (!repo) return;
152
+ const ocrRepo = this.db.getRepository("attachmentOcrResults");
153
+ if (!repo || !ocrRepo) return;
151
154
  const attachment = await repo.findOne({ filterByTk: attachmentId });
152
155
  if (!attachment) {
153
156
  this.log.warn(`[TesseractWorker] Attachment ${attachmentId} not found in DB.`);
157
+ await this.updateOcrResult(attachmentId, {
158
+ status: "failed",
159
+ error: "Attachment not found"
160
+ }).catch(() => {
161
+ });
154
162
  return;
155
163
  }
156
164
  try {
@@ -167,23 +175,46 @@ class TesseractWorker {
167
175
  const ocrData = {
168
176
  pages: result.pages
169
177
  };
170
- await repo.update({
171
- filterByTk: attachmentId,
172
- values: {
173
- ocrData,
174
- ocrStatus: "waiting-verify"
175
- }
178
+ await this.updateOcrResult(attachmentId, {
179
+ data: ocrData,
180
+ status: "waiting-verify",
181
+ error: null
176
182
  });
177
183
  this.log.info(`[TesseractWorker] Successfully processed OCR for attachment ${attachmentId}`);
178
184
  } catch (err) {
179
- this.log.error(`[TesseractWorker] Failed to process OCR for attachment ${attachmentId}: ${err.stack || err.message}`);
180
- await repo.update({
181
- filterByTk: attachmentId,
182
- values: { ocrStatus: "no-ocr" }
185
+ this.log.error(
186
+ `[TesseractWorker] Failed to process OCR for attachment ${attachmentId}: ${err.stack || err.message}`
187
+ );
188
+ await this.updateOcrResult(attachmentId, {
189
+ status: "failed",
190
+ error: (err == null ? void 0 : err.message) || String(err)
183
191
  }).catch(() => {
184
192
  });
185
193
  }
186
194
  }
195
+ async updateOcrResult(attachmentId, values) {
196
+ const repo = this.db.getRepository("attachmentOcrResults");
197
+ if (!repo) return null;
198
+ const existing = await repo.findOne({
199
+ filter: {
200
+ attachmentId
201
+ }
202
+ });
203
+ const nextValues = {
204
+ attachmentId,
205
+ ...values
206
+ };
207
+ if (existing) {
208
+ await repo.update({
209
+ filterByTk: existing.get("id"),
210
+ values: nextValues
211
+ });
212
+ return existing;
213
+ }
214
+ return repo.create({
215
+ values: nextValues
216
+ });
217
+ }
187
218
  }
188
219
  function getStorageFromCache(cache, storageId) {
189
220
  if (storageId === void 0 || storageId === null) return void 0;
@@ -15,12 +15,16 @@ export declare class PluginFilePreviewAuthServer extends Plugin {
15
15
  afterEnable(): Promise<void>;
16
16
  beforeDisable(): Promise<void>;
17
17
  beforeDestroy(): Promise<void>;
18
+ private syncOcrResultCollection;
18
19
  /**
19
20
  * Disable NocoBase's built-in Office previewer after plugins have loaded.
20
21
  * This keeps this authenticated previewer as the active Office handler without causing a restart loop.
21
22
  */
22
23
  private disableBuiltinOfficePreviewer;
23
24
  private registerDownloadApi;
25
+ private getOcrResultByAttachmentId;
26
+ private upsertOcrResult;
27
+ private serializeOcrResult;
24
28
  private registerAIWorkContext;
25
29
  private resolveAttachment;
26
30
  private getParentCollections;
@@ -32,6 +36,13 @@ export declare class PluginFilePreviewAuthServer extends Plugin {
32
36
  private getMarkItDownParserPlugin;
33
37
  private extractAttachmentText;
34
38
  private readAttachmentAsText;
39
+ private prepareAttachmentForFileManager;
40
+ private resolveCollection;
41
+ private resolveStorageId;
42
+ private resolveStorageIdFromRecordTable;
43
+ private ensureFileFields;
44
+ private copyFileFieldsFromRecord;
45
+ private resolveFileFieldsFromRecordTable;
35
46
  private formatAttachmentWorkContext;
36
47
  /**
37
48
  * Register Excel handler into plugin-document-parser's InternalParserRegistry.