Files
NianAIGC/out/_next/static/chunks/app/logs/page-19eb065a0ebab011.js
T
2026-09-02 17:02:02 +08:00

1 line
11 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[524],{1360:(e,t,a)=>{"use strict";a.d(t,{A:()=>r});let r=(0,a(1847).A)("Trash2",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]])},4577:(e,t,a)=>{"use strict";a.d(t,{BrowserAuthGuard:()=>c,BrowserAuthProvider:()=>o,ClientRedirect:()=>d,a:()=>u});var r=a(5155),n=a(2115),s=a(63),l=a(6660);let i=(0,n.createContext)(null);function o(e){let{children:t}=e,[a,s]=(0,n.useState)(null),[o,u]=(0,n.useState)("loading"),[c,d]=(0,n.useState)(null),h=(0,n.useCallback)(async e=>{try{let t=await (0,l.uK)(e);s(t),u("ready"),d(null)}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return;u("error"),d(e instanceof Error?e.message:"无法读取认证状态")}},[]);(0,n.useEffect)(()=>{let e=new AbortController;return h(e.signal),()=>e.abort()},[h]);let f=(0,n.useMemo)(()=>{var e,t;let r=(null==a?void 0:a.user)||null,n=null==(e=null==a?void 0:a.authRequired)||e,s=!n||(null==r?void 0:r.role)==="super_admin",l=s||(null==r?void 0:r.role)==="organization_admin";return{status:o,user:r,authMode:(null==a?void 0:a.authMode)||null,authRequired:n,authConfigured:null!=(t=null==a?void 0:a.authConfigured)&&t,isAdmin:l,isSuperAdmin:s,error:c,refresh:()=>h()}},[c,h,a,o]);return(0,r.jsx)(i.Provider,{value:f,children:t})}function u(){let e=(0,n.useContext)(i);if(!e)throw Error("useBrowserAuth must be used inside BrowserAuthProvider");return e}function c(e){let{children:t,role:a="user"}=e,i=u(),o=(0,s.usePathname)(),c=(0,s.useRouter)(),d="ready"===i.status&&i.authRequired&&!i.user;return((0,n.useEffect)(()=>{if(d){let e=(0,l.M6)(window.location,o||"/create");c.replace("/auth/login?next=".concat(encodeURIComponent(e)))}},[d,o,c]),"loading"===i.status||d)?(0,r.jsx)(h,{message:"正在确认登录状态…"}):"error"===i.status?(0,r.jsx)(h,{message:i.error||"无法读取认证状态",actionLabel:"重试",onAction:()=>void i.refresh()}):("admin"!==a||i.isAdmin)&&("super"!==a||i.isSuperAdmin)?(0,r.jsx)(r.Fragment,{children:t}):(0,r.jsx)(h,{message:"当前账号无权访问此页面。"})}function d(e){let{to:t,forwardNext:a=!1}=e;return(0,n.useEffect)(()=>{let e=a?new URLSearchParams(window.location.search).get("next"):null,r=e?"".concat(t,"?next=").concat(encodeURIComponent(e)):t;window.location.replace(r)},[a,t]),(0,r.jsx)(h,{message:"正在跳转…"})}function h(e){let{message:t,actionLabel:a,onAction:n}=e;return(0,r.jsxs)("section",{className:"panel",children:[(0,r.jsx)("p",{className:"muted",children:t}),a&&n?(0,r.jsx)("button",{className:"button",type:"button",onClick:n,children:a}):null]})}},4934:(e,t,a)=>{"use strict";a.d(t,{LogManager:()=>d});var r=a(5155),n=a(2115),s=a(6651),l=a(5299),i=a(9559),o=a(1360),u=a(7612);let c=[{id:"all",label:"全部"},{id:"error",label:"错误"},{id:"warning",label:"警告"},{id:"info",label:"信息"}];function d(){let[e,t]=(0,n.useState)(null),[a,d]=(0,n.useState)("all"),[f,m]=(0,n.useState)(""),[p,g]=(0,n.useState)(""),[v,x]=(0,n.useState)(!0),[y,j]=(0,n.useState)(!1),[w,b]=(0,n.useState)(null),[N,A]=(0,n.useState)(null),k=(0,n.useRef)(null),E=(0,n.useRef)(null),C=(0,n.useRef)(null);(0,n.useEffect)(()=>{S()},[a,f]),(0,n.useEffect)(()=>(0,u.It)(k,e=>(0,u.xr)(e)),[]),(0,n.useEffect)(()=>{(0,u.c8)(E.current)},[null==e?void 0:e.entries]),(0,n.useEffect)(()=>{(0,u.Js)(C.current)},[w,N]);let M=(0,n.useMemo)(()=>{let t=(null==e?void 0:e.entries)||[];return{total:t.length,error:t.filter(e=>"error"===e.level).length,warning:t.filter(e=>"warning"===e.level).length,info:t.filter(e=>"info"===e.level).length}},[e]);async function S(){x(!0),b(null);try{let e=new URLSearchParams({level:a,limit:"200"});f.trim()&&e.set("q",f.trim());let r=await fetch("/api/logs?".concat(e.toString()),{cache:"no-store"}),n=await r.json();if(!r.ok)throw Error(n.error||"读取日志失败");t(n)}catch(e){b(e instanceof Error?e.message:String(e))}finally{x(!1)}}async function R(){if(window.confirm("确定清空后台日志?")){j(!0),b(null),A(null);try{let e=await fetch("/api/logs",{method:"DELETE"}),t=await e.json();if(!e.ok)throw Error(t.error||"清空日志失败");A("日志已清空。"),await S()}catch(e){b(e instanceof Error?e.message:String(e))}finally{j(!1)}}}return(0,r.jsxs)("div",{className:"log-manager",ref:k,children:[(0,r.jsxs)("div",{className:"workspace-head","data-animate":!0,children:[(0,r.jsx)("div",{children:(0,r.jsx)("h1",{className:"workspace-title",children:"日志管理"})}),(0,r.jsxs)("div",{className:"workspace-meta",children:[(0,r.jsxs)("span",{className:"status",children:[M.total," 条"]}),(0,r.jsxs)("span",{className:"status failed",children:[M.error," 错误"]}),(0,r.jsxs)("span",{className:"status running",children:[M.warning," 警告"]})]})]}),(0,r.jsxs)("section",{className:"panel log-actions","data-animate":!0,children:[(0,r.jsx)("div",{className:"segmented log-tabs","aria-label":"日志级别",children:c.map(e=>(0,r.jsx)("button",{className:a===e.id?"active":"","aria-pressed":a===e.id,type:"button",onClick:()=>d(e.id),children:e.label},e.id))}),(0,r.jsxs)("form",{className:"log-search",onSubmit:function(e){e.preventDefault(),m(p.trim())},children:[(0,r.jsx)(s.A,{"aria-hidden":"true"}),(0,r.jsx)("input",{value:p,placeholder:"搜索消息、路径、状态",onChange:e=>g(e.target.value)})]}),(0,r.jsxs)("div",{className:"toolbar",children:[(0,r.jsxs)("button",{className:"button",type:"button",onClick:S,disabled:v||y,children:[v?(0,r.jsx)(l.A,{className:"spin",size:18}):(0,r.jsx)(i.A,{size:18}),"刷新"]}),(0,r.jsxs)("button",{className:"button danger",type:"button",onClick:R,disabled:v||y,children:[y?(0,r.jsx)(l.A,{className:"spin",size:18}):(0,r.jsx)(o.A,{size:18}),"清空"]})]})]}),w||N?(0,r.jsxs)("div",{ref:C,children:[w?(0,r.jsx)("div",{className:"callout",role:"alert",children:w}):null,N?(0,r.jsx)("div",{className:"callout success-callout",role:"status","aria-live":"polite",children:N}):null]}):null,(0,r.jsx)("section",{className:"panel log-list","data-animate":!0,ref:E,children:v&&!e?(0,r.jsxs)("div",{className:"settings-loading",children:[(0,r.jsx)(l.A,{className:"spin",size:18}),"正在读取日志"]}):(null==e?void 0:e.entries.length)?e.entries.map(e=>(0,r.jsx)(h,{entry:e},e.id)):(0,r.jsx)("div",{className:"log-empty",children:"暂无日志"})})]})}function h(e){var t;let{entry:a}=e,n=function(e){let t=[];return e.stack&&t.push(e.stack),void 0!==e.details&&t.push(JSON.stringify(e.details,null,2)),t.join("\n\n")}(a);return(0,r.jsxs)("article",{className:"log-row log-row-".concat(a.level),children:[(0,r.jsxs)("div",{className:"log-row-main",children:[(0,r.jsx)("span",{className:"status ".concat("error"===a.level?"failed":"warning"===a.level?"running":""),children:"error"===(t=a.level)?"错误":"warning"===t?"警告":"info"===t?"信息":"全部"}),(0,r.jsxs)("div",{className:"log-message",children:[(0,r.jsx)("strong",{children:a.message}),(0,r.jsxs)("small",{children:[function(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString("zh-CN",{hour12:!1})}(a.createdAt)," \xb7 ",a.source,a.status?" \xb7 ".concat(a.status):"",a.method||a.path?" \xb7 ".concat([a.method,a.path].filter(Boolean).join(" ")):""]})]})]}),n?(0,r.jsxs)("details",{className:"log-detail",children:[(0,r.jsx)("summary",{children:"详情"}),(0,r.jsx)("pre",{children:n})]}):null]})}},6651:(e,t,a)=>{"use strict";a.d(t,{A:()=>r});let r=(0,a(1847).A)("Search",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]])},6660:(e,t,a)=>{"use strict";async function r(e){let t=await fetch("/api/auth/me",{method:"GET",cache:"no-store",credentials:"same-origin",headers:{Accept:"application/json"},signal:e});if(!t.ok)throw Error("认证状态请求失败(".concat(t.status,")"));var a,r=await t.json();if(!l(r)||"boolean"!=typeof r.authenticated||"boolean"!=typeof r.authRequired||"boolean"!=typeof r.authConfigured)throw Error("认证状态响应格式无效");if(!r.authenticated){if(null!==r.authMode||null!==r.user)throw Error("认证状态响应格式无效");return{authenticated:!1,authRequired:r.authRequired,authConfigured:r.authConfigured,authMode:null,user:null}}if(!r.authConfigured||"user"!==r.authMode&&"admin"!==r.authMode||!(l(a=r.user)&&"string"==typeof a.id&&a.id.length>0&&"string"==typeof a.subject&&a.subject===a.id&&"string"==typeof a.displayName&&"string"==typeof a.clientId&&("user"===a.role||"organization_admin"===a.role||"super_admin"===a.role)&&"active"===a.status&&("super_admin"===a.role||"string"==typeof a.organizationId&&a.organizationId.length>0)&&Array.isArray(a.authorities)&&a.authorities.every(e=>"string"==typeof e)&&Array.isArray(a.scope)&&a.scope.every(e=>"string"==typeof e)))throw Error("认证用户响应格式无效");let n="user"===r.user.role?"user":"admin";if(r.authMode!==n)throw Error("认证用户响应格式无效");return{authenticated:!0,authRequired:r.authRequired,authConfigured:r.authConfigured,authMode:r.authMode,user:r.user}}function n(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"/create";if(!e||!e.startsWith("/")||e.startsWith("//")||e.includes("\\"))return t;try{let a="http://zhinian.local",r=new URL(e,a);if(r.origin!==a)return t;let n="".concat(r.pathname).concat(r.search).concat(r.hash);if(r.pathname.startsWith("/api/auth")||r.pathname.startsWith("/auth/login")||r.pathname.startsWith("/auth/admin-login"))return t;return n}catch(e){return t}}function s(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"/create";return n("".concat(e.pathname).concat(e.search).concat(e.hash),t)}function l(e){return"object"==typeof e&&null!==e}a.d(t,{M6:()=>s,uK:()=>r,z3:()=>n})},7612:(e,t,a)=>{"use strict";a.d(t,{It:()=>l,Js:()=>u,c8:()=>o,xr:()=>i});var r=a(7605);let n="power2.out";function s(){return window.matchMedia("(prefers-reduced-motion: reduce)").matches}function l(e,t){let a=e.current;if(!a||s())return;let n=r.os.context(()=>t(a),a);return()=>n.revert()}function i(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"[data-animate]";if(s())return;let a=r.os.utils.toArray(t,e);a.length&&r.os.fromTo(a,{autoAlpha:0,y:14},{autoAlpha:1,y:0,duration:.28,ease:n,stagger:.045,clearProps:"transform,opacity,visibility"})}function o(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:10;!e||s()||r.os.fromTo(e,{autoAlpha:0,y:t},{autoAlpha:1,y:0,duration:.28,ease:n,clearProps:"transform,opacity,visibility"})}function u(e){!e||s()||r.os.fromTo(e,{scale:.985},{scale:1,duration:.22,ease:n,clearProps:"transform"})}},9286:(e,t,a)=>{Promise.resolve().then(a.bind(a,4577)),Promise.resolve().then(a.bind(a,4934))},9559:(e,t,a)=>{"use strict";a.d(t,{A:()=>r});let r=(0,a(1847).A)("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]])}},e=>{e.O(0,[592,274,441,255,358],()=>e(e.s=9286)),_N_E=e.O()}]);