wiki-viewer 3.1.1 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/.next/standalone/.next/BUILD_ID +1 -1
  2. package/.next/standalone/.next/build-manifest.json +3 -3
  3. package/.next/standalone/.next/prerender-manifest.json +3 -3
  4. package/.next/standalone/.next/required-server-files.json +1 -1
  5. package/.next/standalone/.next/server/app/_global-error.html +1 -1
  6. package/.next/standalone/.next/server/app/_global-error.rsc +1 -1
  7. package/.next/standalone/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  8. package/.next/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  9. package/.next/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  10. package/.next/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  11. package/.next/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  12. package/.next/standalone/.next/server/app/api/agent/activity/route.js.nft.json +1 -1
  13. package/.next/standalone/.next/server/app/api/agent/events/[...path]/route.js.nft.json +1 -1
  14. package/.next/standalone/.next/server/app/api/agent/files/[...path]/route.js.nft.json +1 -1
  15. package/.next/standalone/.next/server/app/api/agent/fs/file/[...path]/route.js.nft.json +1 -1
  16. package/.next/standalone/.next/server/app/api/agent/fs/ls/[[...path]]/route.js.nft.json +1 -1
  17. package/.next/standalone/.next/server/app/api/agent/fs/move/route.js.nft.json +1 -1
  18. package/.next/standalone/.next/server/app/api/agent/fs/search/route.js.nft.json +1 -1
  19. package/.next/standalone/.next/server/app/api/agent/settings/route.js.nft.json +1 -1
  20. package/.next/standalone/.next/server/app/api/agent/sidecar/[...path]/route.js.nft.json +1 -1
  21. package/.next/standalone/.next/server/app/api/app-proxy/[...path]/route.js.nft.json +1 -1
  22. package/.next/standalone/.next/server/app/api/assets/[...path]/route.js.nft.json +1 -1
  23. package/.next/standalone/.next/server/app/api/pdf/save/route.js.nft.json +1 -1
  24. package/.next/standalone/.next/server/app/api/share/[token]/asset/route.js.nft.json +1 -1
  25. package/.next/standalone/.next/server/app/api/share/[token]/route.js.nft.json +1 -1
  26. package/.next/standalone/.next/server/app/api/share/route.js.nft.json +1 -1
  27. package/.next/standalone/.next/server/app/api/system/reveal/route.js.nft.json +1 -1
  28. package/.next/standalone/.next/server/app/api/system/workspaces/[id]/branch/route.js.nft.json +1 -1
  29. package/.next/standalone/.next/server/app/api/system/workspaces/[id]/open/route.js.nft.json +1 -1
  30. package/.next/standalone/.next/server/app/api/system/workspaces/[id]/refresh/route.js.nft.json +1 -1
  31. package/.next/standalone/.next/server/app/api/system/workspaces/[id]/route.js.nft.json +1 -1
  32. package/.next/standalone/.next/server/app/api/system/workspaces/route.js.nft.json +1 -1
  33. package/.next/standalone/.next/server/app/api/upload/[...path]/route.js.nft.json +1 -1
  34. package/.next/standalone/.next/server/app/api/wiki/app/route.js.nft.json +1 -1
  35. package/.next/standalone/.next/server/app/api/wiki/backlinks/route.js.nft.json +1 -1
  36. package/.next/standalone/.next/server/app/api/wiki/content/route.js.nft.json +1 -1
  37. package/.next/standalone/.next/server/app/api/wiki/download/route.js.nft.json +1 -1
  38. package/.next/standalone/.next/server/app/api/wiki/folder/route.js.nft.json +1 -1
  39. package/.next/standalone/.next/server/app/api/wiki/git-branches/route.js.nft.json +1 -1
  40. package/.next/standalone/.next/server/app/api/wiki/git-checkout/route.js.nft.json +1 -1
  41. package/.next/standalone/.next/server/app/api/wiki/git-diff/route.js.nft.json +1 -1
  42. package/.next/standalone/.next/server/app/api/wiki/git-file-info/route.js.nft.json +1 -1
  43. package/.next/standalone/.next/server/app/api/wiki/git-history/route.js.nft.json +1 -1
  44. package/.next/standalone/.next/server/app/api/wiki/git-pull/route.js.nft.json +1 -1
  45. package/.next/standalone/.next/server/app/api/wiki/hosted-apps/[slug]/route.js.nft.json +1 -1
  46. package/.next/standalone/.next/server/app/api/wiki/hosted-apps/route.js.nft.json +1 -1
  47. package/.next/standalone/.next/server/app/api/wiki/move/route.js.nft.json +1 -1
  48. package/.next/standalone/.next/server/app/api/wiki/new-file/route.js.nft.json +1 -1
  49. package/.next/standalone/.next/server/app/api/wiki/outlinks/route.js.nft.json +1 -1
  50. package/.next/standalone/.next/server/app/api/wiki/page/route.js.nft.json +1 -1
  51. package/.next/standalone/.next/server/app/api/wiki/presence/route.js.nft.json +1 -1
  52. package/.next/standalone/.next/server/app/api/wiki/preview-token/route.js.nft.json +1 -1
  53. package/.next/standalone/.next/server/app/api/wiki/route.js.nft.json +1 -1
  54. package/.next/standalone/.next/server/app/api/wiki/scratch/route.js.nft.json +1 -1
  55. package/.next/standalone/.next/server/app/api/wiki/search/route.js.nft.json +1 -1
  56. package/.next/standalone/.next/server/app/api/wiki/slugs/route.js.nft.json +1 -1
  57. package/.next/standalone/.next/server/app/api/wiki/upload/route.js.nft.json +1 -1
  58. package/.next/standalone/.next/server/app/api/wiki/watch/route.js.nft.json +1 -1
  59. package/.next/standalone/.next/server/app/app/[slug]/[[...rest]]/route.js.nft.json +1 -1
  60. package/.next/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
  61. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0.fl467._.js +1 -1
  62. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0cqahds._.js +1 -1
  63. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0f.q.gf._.js +1 -1
  64. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0fc05ki._.js +1 -1
  65. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0fkfkc.._.js +1 -1
  66. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0skgiv0._.js +1 -1
  67. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0tuu3y1._.js +1 -1
  68. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0z5f4h8._.js +1 -1
  69. package/.next/standalone/.next/server/chunks/[root-of-the-server]__11ltgmp._.js +1 -1
  70. package/.next/standalone/.next/server/chunks/[root-of-the-server]__12g8s_j._.js +1 -1
  71. package/.next/standalone/.next/server/chunks/ssr/_0_j0j3f._.js +1 -1
  72. package/.next/standalone/.next/server/middleware-build-manifest.js +3 -3
  73. package/.next/standalone/.next/server/pages/500.html +1 -1
  74. package/.next/standalone/.next/server/server-reference-manifest.js +1 -1
  75. package/.next/standalone/.next/server/server-reference-manifest.json +1 -1
  76. package/.next/standalone/.next/static/chunks/{0.4z79b01ogty.js → 0cz0xzb~lms_9.js} +1 -1
  77. package/.next/standalone/package.json +1 -1
  78. package/.next/standalone/server.js +1 -1
  79. package/bin/shared/ssh-target.js +3 -1
  80. package/package.json +1 -1
  81. /package/.next/standalone/.next/static/{UIhlbM5yWbVS3aIHrh_He → nfXY6poENgSEOPczB4Z-L}/_buildManifest.js +0 -0
  82. /package/.next/standalone/.next/static/{UIhlbM5yWbVS3aIHrh_He → nfXY6poENgSEOPczB4Z-L}/_clientMiddlewareManifest.js +0 -0
  83. /package/.next/standalone/.next/static/{UIhlbM5yWbVS3aIHrh_He → nfXY6poENgSEOPczB4Z-L}/_ssgManifest.js +0 -0
@@ -1,3 +1,3 @@
1
- module.exports=[583627,e=>{"use strict";var t=e.i(798003),r=e.i(254226);function s(){return(process.env.WIKI_ADMIN_EMAILS??"").split(",").map(e=>e.trim().toLowerCase()).filter(Boolean)}async function n(e,r){if(r){let e=s();if(e.length>0&&e.includes(r.toLowerCase()))return!0}return((await (0,t.readConfig)()).adminUserIds??[]).includes(e)}async function a(){return(await (0,t.readConfig)()).adminUserIds??[]}async function i(e){await (0,t.updateConfig)(t=>{let r=t.adminUserIds??[];return r.includes(e)?t:{...t,adminUserIds:[...r,e]}})}async function o(e){let r=s().length>0,n=!1;if(await (0,t.updateConfig)(t=>{let s=(t.adminUserIds??[]).filter(t=>t!==e);return 0!==s.length||r?{...t,adminUserIds:s}:(n=!0,t)}),n)throw Error("LAST_ADMIN: cannot remove the last admin with no WIKI_ADMIN_EMAILS configured")}async function l(e){if(s().length>0||r.SYNTHETIC_USER_IDS.has(e)||((await (0,t.readConfig)()).adminUserIds??[]).length>0)return;let n=!1;await (0,t.updateConfig)(t=>(t.adminUserIds??[]).length>0?t:(n=!0,{...t,adminUserIds:[e]})),n&&console.log(`[wiki-viewer] Bootstrap: first user ${e} promoted to admin`)}async function u(e){if("1"===process.env.WIKI_NO_AUTH)return{ok:!0,user:{id:"local",email:"local@localhost",name:"local"}};let t=await (0,r.requireUser)(e);return t.ok?await n(t.user.id,t.user.email)?{ok:!0,user:t.user}:{ok:!1,status:403,code:"ADMIN_REQUIRED"}:{ok:!1,status:401,code:"UNAUTHORIZED"}}e.s(["addAdmin",0,i,"ensureBootstrapAdmin",0,l,"isAdmin",0,n,"listAdmins",0,a,"removeAdmin",0,o,"requireAdmin",0,u])},874533,(e,t,r)=>{t.exports=e.x("node:child_process",()=>require("node:child_process"))},812057,(e,t,r)=>{t.exports=e.x("node:util",()=>require("node:util"))},256294,296555,e=>{"use strict";let t;var r=e.i(874533),s=e.i(812057),n=e.i(912714),a=e.i(750227),i=e.i(660526);e.i(902157);let o=RegExp("[;|&$`<>(){}\\n\\r\\0]");function l(e){let{target:t,mountpoint:r,port:s}=e,n=t.user?`${t.user}@`:"",a=[`${n}${t.host}:${t.remotePath}`,r];s&&Number.isInteger(Number(s))&&Number(s)>0&&65536>Number(s)&&a.push("-p",String(s));let i=e.authMethod??"agent";!e.authMethod&&(null!=e.password?i="password":e.keyPath&&(i="keyfile"));let o=["reconnect","ServerAliveInterval=15","ServerAliveCountMax=3","compression=yes","cache=yes","kernel_cache","StrictHostKeyChecking=accept-new","BatchMode=yes"];if(e.readOnly&&o.push("ro"),"keyfile"===i&&e.keyPath&&(o.push(`IdentityFile=${e.keyPath}`),o.push("IdentitiesOnly=yes")),"password"===i){let e=o.indexOf("BatchMode=yes");e>=0&&o.splice(e,1),o.push("password_stdin"),o.push("PreferredAuthentications=password,keyboard-interactive"),o.push("PubkeyAuthentication=no"),o.push("NumberOfPasswordPrompts=1")}return e.extraOptions&&o.push(...e.extraOptions),a.push("-o",o.join(",")),a}e.s(["buildSshfsArgs",0,l,"isValidKeyPath",0,function(e){return!(!e||o.test(e)||e.includes(".."))&&(e.startsWith("/")||e.startsWith("~/"))},"parseSshTarget",0,function(e){let t;if(!e||o.test(e))return null;let r=e.trim(),s=r.indexOf(":");if(s<=0)return null;let n=r.slice(0,s),a=r.slice(s+1);if(!a.startsWith("/")||a.includes(".."))return null;let i=n,l=n.indexOf("@");return l>=0&&(t=n.slice(0,l),i=n.slice(l+1),!t)?null:i&&/^[a-zA-Z0-9.\-]+$/.test(i)&&(!t||/^[a-zA-Z0-9._\-]+$/.test(t))?{user:t,host:i,remotePath:a}:null}],296555);let u=(0,s.promisify)(r.execFile);function d(){return a.default.join(i.default.homedir(),".wiki-viewer","mounts")}async function c(){if(!0!==t)try{await u("sshfs",["--version"]),t=!0}catch{throw Error("sshfs binary not found. Install sshfs + FUSE (e.g. `apt install sshfs`, `brew install macfuse sshfs`) and ensure it is on PATH.")}}async function p(t){var r;let s=a.default.resolve(t),i=!1;try{i=(await (0,n.readFile)("/proc/mounts","utf8")).split("\n").some(e=>{let t=e.split(" ");return t[1]===s&&/fuse/.test(t[2]??"")})}catch{i=!1}return!!i&&(r=s,new Promise(t=>{let s=!1,n=setTimeout(()=>{s||(s=!0,t(!1))},4e3);e.A(687903).then(({readdir:e})=>e(r)).then(()=>{s||(s=!0,clearTimeout(n),t(!0))}).catch(()=>{s||(s=!0,clearTimeout(n),t(!1))})}))}async function h(e){await c(),await (0,n.mkdir)(e.mountpoint,{recursive:!0});let t=l(e);if(await new Promise((s,n)=>{let a=(0,r.spawn)("sshfs",t,{stdio:["pipe","ignore","pipe"]}),i="",o=setTimeout(()=>{a.kill("SIGKILL"),n(Error("sshfs mount timed out after 25s."))},25e3);a.stderr?.on("data",e=>{i+=e.toString()}),a.on("error",e=>{clearTimeout(o),n(e.message.includes("ENOENT")?Error("sshfs binary not found on PATH."):e)}),a.on("close",e=>{clearTimeout(o),0===e?s():n(Error(`sshfs exited ${e}: ${i.trim()||"mount failed"}`))}),"password"===e.authMethod&&a.stdin?.write((e.password??"")+"\n"),a.stdin?.end()}),!await p(e.mountpoint))throw Error("sshfs reported success but the mount is not live.")}async function m(e){let t=a.default.resolve(e);for(let[e,r]of[["fusermount",["-u","-z",t]],["umount",[t]]])try{await u(e,r);break}catch{}try{await (0,n.rmdir)(t)}catch{}}e.s(["assertSshfsAvailable",0,c,"isMounted",0,p,"mountSshfs",0,h,"mountpointFor",0,function(e){return a.default.join(d(),e)},"mountsDir",0,d,"unmountSshfs",0,m],256294)},402662,e=>{"use strict";var t=e.i(351216);e.s(["checkOrigin",0,function(e){let r=e.method.toUpperCase();if("GET"===r||"HEAD"===r||"OPTIONS"===r)return null;let s=e.headers.get("origin"),n=e.headers.get("referer");if(!s&&!n)return null;let a=function(e){let t=Array.from(new Set(["localhost","127.0.0.1",e.split(":")[0],...(process.env.WIKI_OWNER_HOSTS??"").split(",").map(e=>e.trim()).filter(Boolean)])),r=["",":3000",":3003"];e.includes(":")&&r.push(":"+e.split(":")[1]);let s=new Set;for(let e of t)for(let t of["http","https"])for(let n of r)s.add(`${t}://${e}${n}`);return s}(e.headers.get("host")??"");if(s)return a.has(s)?null:t.NextResponse.json({error:"FORBIDDEN",message:"Bad origin"},{status:403});if(n){try{let{protocol:e,host:t}=new URL(n);if(a.has(`${e}//${t}`))return null}catch{}return t.NextResponse.json({error:"FORBIDDEN",message:"Bad referer"},{status:403})}return null}])},262758,e=>{"use strict";var t=e.i(985426),r=e.i(257574),s=e.i(507835),n=e.i(457789),a=e.i(119791),i=e.i(141062),o=e.i(957291),l=e.i(535899),u=e.i(610241),d=e.i(62749),c=e.i(624891),p=e.i(725836),h=e.i(532736),m=e.i(257858),f=e.i(487476),v=e.i(193695);e.i(484264);var w=e.i(315709),g=e.i(912714),y=e.i(351216),R=e.i(402662),_=e.i(254226),k=e.i(583627),A=e.i(798003),E=e.i(359211);async function N(e){if("1"===process.env.WIKI_NO_AUTH){await (0,E.migrateConfigToWorkspaces)();let e=(await (0,E.listWorkspaces)()).map(E.sanitizeWorkspace);return y.NextResponse.json({workspaces:e,isAdmin:!0})}let t=await (0,_.requireUser)(e);if(!t.ok)return y.NextResponse.json({error:"UNAUTHORIZED"},{status:401});await (0,k.ensureBootstrapAdmin)(t.user.id),await (0,E.migrateConfigToWorkspaces)();let r=await (0,k.isAdmin)(t.user.id,t.user.email),s=(await (0,E.listWorkspaces)()).filter(e=>(0,E.userCanAccess)(e,t.user.id,r)).map(E.sanitizeWorkspace);return y.NextResponse.json({workspaces:s,isAdmin:r})}async function x(e){let t=(0,R.checkOrigin)(e);if(t)return t;let r=await (0,k.requireAdmin)(e);if(!r.ok)return y.NextResponse.json({error:r.code},{status:r.status});let s=await e.json();if(s.sshTarget){let e,t=s.sshAuthMethod??"agent";if(!["agent","keyfile","password"].includes(t))return y.NextResponse.json({error:"Invalid auth method"},{status:400});if(void 0!==s.sshPort&&(!Number.isInteger(e=Number(s.sshPort))||e<1||e>65535))return y.NextResponse.json({error:"Invalid port"},{status:400});try{let n=await (0,E.createSshWorkspace)({target:s.sshTarget,port:e,authMethod:t,keyPath:s.sshKeyPath?.trim()||void 0,password:s.sshPassword||void 0,readOnly:!0===s.sshReadOnly,name:s.name?.trim()||void 0,createdBy:r.user.id});return y.NextResponse.json({ok:!0,workspace:(0,E.sanitizeWorkspace)(n)})}catch(t){let e=t instanceof Error?t.message:String(t);return y.NextResponse.json({error:e},{status:400})}}if(s.remoteUrl){if(void 0!==s.subpath&&"string"!=typeof s.subpath)return y.NextResponse.json({error:"Invalid subpath"},{status:400});let e=s.subpath?.trim()||void 0;if(e&&(e.startsWith("/")||e.includes("..")||/[;|&$`<>(){}\n\0]/.test(e)))return y.NextResponse.json({error:"Invalid subpath"},{status:400});let t=await (0,A.readConfig)();try{let n=await (0,E.createGitWorkspace)({remoteUrl:s.remoteUrl,branch:s.branch?.trim()||void 0,token:s.token||void 0,username:s.username?.trim()||void 0,name:s.name?.trim()||void 0,createdBy:r.user.id,allowedHosts:t.git?.allowedHosts,allowInsecureHttp:t.git?.allowInsecureHttp,subpath:e});return y.NextResponse.json({ok:!0,workspace:(0,E.sanitizeWorkspace)(n)})}catch(t){let e=t instanceof Error?t.message:String(t);return y.NextResponse.json({error:e},{status:400})}}let n=s.rootDir?.trim();if(!n)return y.NextResponse.json({error:"Missing rootDir"},{status:400});try{if(!(await (0,g.stat)(n)).isDirectory())return y.NextResponse.json({error:"Not a directory"},{status:400})}catch{return y.NextResponse.json({error:"Directory not found"},{status:404})}let a=await (0,E.createWorkspace)({rootDir:n,name:s.name?.trim()||void 0,createdBy:r.user.id});return y.NextResponse.json({ok:!0,workspace:(0,E.sanitizeWorkspace)(a)})}e.s(["GET",0,N,"POST",0,x,"runtime",0,"nodejs"],401923);var I=e.i(401923);let b=new t.AppRouteRouteModule({definition:{kind:r.RouteKind.APP_ROUTE,page:"/api/system/workspaces/route",pathname:"/api/system/workspaces",filename:"route",bundlePath:""},distDir:".next",relativeProjectDir:"",resolvedPagePath:"[project]/src/app/api/system/workspaces/route.ts",nextConfigOutput:"standalone",userland:I,...{}}),{workAsyncStorage:C,workUnitAsyncStorage:P,serverHooks:T}=b;async function S(e,t,s){s.requestMeta&&(0,n.setRequestMeta)(e,s.requestMeta),b.isDev&&(0,n.addRequestMeta)(e,"devRequestTimingInternalsEnd",process.hrtime.bigint());let g="/api/system/workspaces/route";g=g.replace(/\/index$/,"")||"/";let y=await b.prepare(e,t,{srcPage:g,multiZoneDraftMode:!1});if(!y)return t.statusCode=400,t.end("Bad Request"),null==s.waitUntil||s.waitUntil.call(s,Promise.resolve()),null;let{buildId:R,params:_,nextConfig:k,parsedUrl:A,isDraftMode:E,prerenderManifest:N,routerServerContext:x,isOnDemandRevalidate:I,revalidateOnlyGenerated:C,resolvedPathname:P,clientReferenceManifest:T,serverActionsManifest:S}=y,O=(0,o.normalizeAppPath)(g),j=!!(N.dynamicRoutes[O]||N.routes[P]),U=async()=>((null==x?void 0:x.render404)?await x.render404(e,t,A,!1):t.end("This page could not be found"),null);if(j&&!E){let e=!!N.routes[P],t=N.dynamicRoutes[O];if(t&&!1===t.fallback&&!e){if(k.adapterPath)return await U();throw new v.NoFallbackError}}let q=null;!j||b.isDev||E||(q="/index"===(q=P)?"/":q);let D=!0===b.isDev||!j,H=j&&!D;S&&T&&(0,i.setManifestsSingleton)({page:g,clientReferenceManifest:T,serverActionsManifest:S});let M=e.method||"GET",$=(0,a.getTracer)(),W=$.getActiveScopeSpan(),B=!!(null==x?void 0:x.isWrappedByNextServer),K=!!(0,n.getRequestMeta)(e,"minimalMode"),F=(0,n.getRequestMeta)(e,"incrementalCache")||await b.getIncrementalCache(e,k,N,K);null==F||F.resetRequestCache(),globalThis.__incrementalCache=F;let z={params:_,previewProps:N.preview,renderOpts:{experimental:{authInterrupts:!!k.experimental.authInterrupts},cacheComponents:!!k.cacheComponents,supportsDynamicResponse:D,incrementalCache:F,cacheLifeProfiles:k.cacheLife,waitUntil:s.waitUntil,onClose:e=>{t.on("close",e)},onAfterTaskError:void 0,onInstrumentationRequestError:(t,r,s,n)=>b.onRequestError(e,t,s,n,x)},sharedContext:{buildId:R}},L=new l.NodeNextRequest(e),G=new l.NodeNextResponse(t),Z=u.NextRequestAdapter.fromNodeNextRequest(L,(0,u.signalFromNodeResponse)(t));try{let n,i=async e=>b.handle(Z,z).finally(()=>{if(!e)return;e.setAttributes({"http.status_code":t.statusCode,"next.rsc":!1});let r=$.getRootSpanAttributes();if(!r)return;if(r.get("next.span_type")!==d.BaseServerSpan.handleRequest)return void console.warn(`Unexpected root span type '${r.get("next.span_type")}'. Please report this Next.js issue https://github.com/vercel/next.js`);let s=r.get("next.route");if(s){let t=`${M} ${s}`;e.setAttributes({"next.route":s,"http.route":s,"next.span_name":t}),e.updateName(t),n&&n!==e&&(n.setAttribute("http.route",s),n.updateName(t))}else e.updateName(`${M} ${g}`)}),o=async n=>{var a,o;let l=async({previousCacheEntry:r})=>{try{if(!K&&I&&C&&!r)return t.statusCode=404,t.setHeader("x-nextjs-cache","REVALIDATED"),t.end("This page could not be found"),null;let a=await i(n);e.fetchMetrics=z.renderOpts.fetchMetrics;let o=z.renderOpts.pendingWaitUntil;o&&s.waitUntil&&(s.waitUntil(o),o=void 0);let l=z.renderOpts.collectedTags;if(!j)return await (0,p.sendResponse)(L,G,a,z.renderOpts.pendingWaitUntil),null;{let e=await a.blob(),t=(0,h.toNodeOutgoingHttpHeaders)(a.headers);l&&(t[f.NEXT_CACHE_TAGS_HEADER]=l),!t["content-type"]&&e.type&&(t["content-type"]=e.type);let r=void 0!==z.renderOpts.collectedRevalidate&&!(z.renderOpts.collectedRevalidate>=f.INFINITE_CACHE)&&z.renderOpts.collectedRevalidate,s=void 0===z.renderOpts.collectedExpire||z.renderOpts.collectedExpire>=f.INFINITE_CACHE?void 0:z.renderOpts.collectedExpire;return{value:{kind:w.CachedRouteKind.APP_ROUTE,status:a.status,body:Buffer.from(await e.arrayBuffer()),headers:t},cacheControl:{revalidate:r,expire:s}}}}catch(t){throw(null==r?void 0:r.isStale)&&await b.onRequestError(e,t,{routerKind:"App Router",routePath:g,routeType:"route",revalidateReason:(0,c.getRevalidateReason)({isStaticGeneration:H,isOnDemandRevalidate:I})},!1,x),t}},u=await b.handleResponse({req:e,nextConfig:k,cacheKey:q,routeKind:r.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:N,isRoutePPREnabled:!1,isOnDemandRevalidate:I,revalidateOnlyGenerated:C,responseGenerator:l,waitUntil:s.waitUntil,isMinimalMode:K});if(!j)return null;if((null==u||null==(a=u.value)?void 0:a.kind)!==w.CachedRouteKind.APP_ROUTE)throw Object.defineProperty(Error(`Invariant: app-route received invalid cache entry ${null==u||null==(o=u.value)?void 0:o.kind}`),"__NEXT_ERROR_CODE",{value:"E701",enumerable:!1,configurable:!0});K||t.setHeader("x-nextjs-cache",I?"REVALIDATED":u.isMiss?"MISS":u.isStale?"STALE":"HIT"),E&&t.setHeader("Cache-Control","private, no-cache, no-store, max-age=0, must-revalidate");let d=(0,h.fromNodeOutgoingHttpHeaders)(u.value.headers);return K&&j||d.delete(f.NEXT_CACHE_TAGS_HEADER),!u.cacheControl||t.getHeader("Cache-Control")||d.get("Cache-Control")||d.set("Cache-Control",(0,m.getCacheControlHeader)(u.cacheControl)),await (0,p.sendResponse)(L,G,new Response(u.value.body,{headers:d,status:u.value.status||200})),null};B&&W?await o(W):(n=$.getActiveScopeSpan(),await $.withPropagatedContext(e.headers,()=>$.trace(d.BaseServerSpan.handleRequest,{spanName:`${M} ${g}`,kind:a.SpanKind.SERVER,attributes:{"http.method":M,"http.target":e.url}},o),void 0,!B))}catch(t){if(t instanceof v.NoFallbackError||await b.onRequestError(e,t,{routerKind:"App Router",routePath:O,routeType:"route",revalidateReason:(0,c.getRevalidateReason)({isStaticGeneration:H,isOnDemandRevalidate:I})},!1,x),j)throw t;return await (0,p.sendResponse)(L,G,new Response(null,{status:500})),null}}e.s(["handler",0,S,"patchFetch",0,function(){return(0,s.patchFetch)({workAsyncStorage:C,workUnitAsyncStorage:P})},"routeModule",0,b,"serverHooks",0,T,"workAsyncStorage",0,C,"workUnitAsyncStorage",0,P],262758)},168315,e=>{e.v(t=>Promise.all(["server/chunks/0sag_@better-auth_memory-adapter_dist_index_mjs_0pvj6im._.js"].map(t=>e.l(t))).then(()=>t(862112)))},769787,e=>{e.v(t=>Promise.all(["server/chunks/01er_better-auth_dist_adapters_kysely-adapter_index_mjs_0s~-4gu._.js"].map(t=>e.l(t))).then(()=>t(717789)))},580632,e=>{e.v(e=>Promise.resolve().then(()=>e(270406)))},947559,e=>{e.v(t=>Promise.all(["server/chunks/0ugq_@better-auth_kysely-adapter_dist_bun-sqlite-dialect-DzNwOpKv_mjs_0z1z6m4._.js"].map(t=>e.l(t))).then(()=>t(495181)))},715018,e=>{e.v(t=>Promise.all(["server/chunks/0ugq_@better-auth_kysely-adapter_dist_node-sqlite-dialect_mjs_0qqlvhl._.js"].map(t=>e.l(t))).then(()=>t(698370)))},146843,e=>{e.v(t=>Promise.all(["server/chunks/0ugq_@better-auth_kysely-adapter_dist_d1-sqlite-dialect-C2B7YsIT_mjs_0wynrz3._.js"].map(t=>e.l(t))).then(()=>t(143740)))},697743,e=>{e.v(t=>Promise.all(["server/chunks/0.u4_next_05jevxw._.js"].map(t=>e.l(t))).then(()=>t(428325)))},99243,e=>{e.v(e=>Promise.resolve().then(()=>e(313414)))},893412,e=>{e.v(t=>Promise.all(["server/chunks/src_lib_auth_api-key_ts_0t_ma-t._.js"].map(t=>e.l(t))).then(()=>t(499465)))},687903,e=>{e.v(e=>Promise.resolve().then(()=>e(912714)))}];
1
+ module.exports=[583627,e=>{"use strict";var t=e.i(798003),r=e.i(254226);function s(){return(process.env.WIKI_ADMIN_EMAILS??"").split(",").map(e=>e.trim().toLowerCase()).filter(Boolean)}async function n(e,r){if(r){let e=s();if(e.length>0&&e.includes(r.toLowerCase()))return!0}return((await (0,t.readConfig)()).adminUserIds??[]).includes(e)}async function a(){return(await (0,t.readConfig)()).adminUserIds??[]}async function i(e){await (0,t.updateConfig)(t=>{let r=t.adminUserIds??[];return r.includes(e)?t:{...t,adminUserIds:[...r,e]}})}async function o(e){let r=s().length>0,n=!1;if(await (0,t.updateConfig)(t=>{let s=(t.adminUserIds??[]).filter(t=>t!==e);return 0!==s.length||r?{...t,adminUserIds:s}:(n=!0,t)}),n)throw Error("LAST_ADMIN: cannot remove the last admin with no WIKI_ADMIN_EMAILS configured")}async function l(e){if(s().length>0||r.SYNTHETIC_USER_IDS.has(e)||((await (0,t.readConfig)()).adminUserIds??[]).length>0)return;let n=!1;await (0,t.updateConfig)(t=>(t.adminUserIds??[]).length>0?t:(n=!0,{...t,adminUserIds:[e]})),n&&console.log(`[wiki-viewer] Bootstrap: first user ${e} promoted to admin`)}async function u(e){if("1"===process.env.WIKI_NO_AUTH)return{ok:!0,user:{id:"local",email:"local@localhost",name:"local"}};let t=await (0,r.requireUser)(e);return t.ok?await n(t.user.id,t.user.email)?{ok:!0,user:t.user}:{ok:!1,status:403,code:"ADMIN_REQUIRED"}:{ok:!1,status:401,code:"UNAUTHORIZED"}}e.s(["addAdmin",0,i,"ensureBootstrapAdmin",0,l,"isAdmin",0,n,"listAdmins",0,a,"removeAdmin",0,o,"requireAdmin",0,u])},874533,(e,t,r)=>{t.exports=e.x("node:child_process",()=>require("node:child_process"))},812057,(e,t,r)=>{t.exports=e.x("node:util",()=>require("node:util"))},256294,296555,e=>{"use strict";let t;var r=e.i(874533),s=e.i(812057),n=e.i(912714),a=e.i(750227),i=e.i(660526);e.i(902157);let o=RegExp("[;|&$`<>(){}\\n\\r\\0]");function l(e){let{target:t,mountpoint:r,port:s}=e,n=t.user?`${t.user}@`:"",a=[`${n}${t.host}:${t.remotePath}`,r];s&&Number.isInteger(Number(s))&&Number(s)>0&&65536>Number(s)&&a.push("-p",String(s));let i=e.authMethod??"agent";!e.authMethod&&(null!=e.password?i="password":e.keyPath&&(i="keyfile"));let o=["reconnect","ServerAliveInterval=15","ServerAliveCountMax=3","compression=yes","cache=yes","StrictHostKeyChecking=accept-new","BatchMode=yes"];if(e.readOnly&&o.push("ro"),"keyfile"===i&&e.keyPath&&(o.push(`IdentityFile=${e.keyPath}`),o.push("IdentitiesOnly=yes")),"password"===i){let e=o.indexOf("BatchMode=yes");e>=0&&o.splice(e,1),o.push("password_stdin"),o.push("PreferredAuthentications=password,keyboard-interactive"),o.push("PubkeyAuthentication=no"),o.push("NumberOfPasswordPrompts=1")}return e.extraOptions&&o.push(...e.extraOptions),a.push("-o",o.join(",")),a}e.s(["buildSshfsArgs",0,l,"isValidKeyPath",0,function(e){return!(!e||o.test(e)||e.includes(".."))&&(e.startsWith("/")||e.startsWith("~/"))},"parseSshTarget",0,function(e){let t;if(!e||o.test(e))return null;let r=e.trim(),s=r.indexOf(":");if(s<=0)return null;let n=r.slice(0,s),a=r.slice(s+1);if(!a.startsWith("/")||a.includes(".."))return null;let i=n,l=n.indexOf("@");return l>=0&&(t=n.slice(0,l),i=n.slice(l+1),!t)?null:i&&/^[a-zA-Z0-9.\-]+$/.test(i)&&(!t||/^[a-zA-Z0-9._\-]+$/.test(t))?{user:t,host:i,remotePath:a}:null}],296555);let u=(0,s.promisify)(r.execFile);function d(){return a.default.join(i.default.homedir(),".wiki-viewer","mounts")}async function c(){if(!0!==t)try{await u("sshfs",["--version"]),t=!0}catch{throw Error("sshfs binary not found. Install sshfs + FUSE (e.g. `apt install sshfs`, `brew install macfuse sshfs`) and ensure it is on PATH.")}}async function p(t){var r;let s=a.default.resolve(t),i=!1;try{i=(await (0,n.readFile)("/proc/mounts","utf8")).split("\n").some(e=>{let t=e.split(" ");return t[1]===s&&/fuse/.test(t[2]??"")})}catch{i=!1}return!!i&&(r=s,new Promise(t=>{let s=!1,n=setTimeout(()=>{s||(s=!0,t(!1))},4e3);e.A(687903).then(({readdir:e})=>e(r)).then(()=>{s||(s=!0,clearTimeout(n),t(!0))}).catch(()=>{s||(s=!0,clearTimeout(n),t(!1))})}))}async function h(e){await c(),await (0,n.mkdir)(e.mountpoint,{recursive:!0});let t=l(e);if(await new Promise((s,n)=>{let a=(0,r.spawn)("sshfs",t,{stdio:["pipe","ignore","pipe"]}),i="",o=setTimeout(()=>{a.kill("SIGKILL"),n(Error("sshfs mount timed out after 25s."))},25e3);a.stderr?.on("data",e=>{i+=e.toString()}),a.on("error",e=>{clearTimeout(o),n(e.message.includes("ENOENT")?Error("sshfs binary not found on PATH."):e)}),a.on("close",e=>{clearTimeout(o),0===e?s():n(Error(`sshfs exited ${e}: ${i.trim()||"mount failed"}`))}),"password"===e.authMethod&&a.stdin?.write((e.password??"")+"\n"),a.stdin?.end()}),!await p(e.mountpoint))throw Error("sshfs reported success but the mount is not live.")}async function m(e){let t=a.default.resolve(e);for(let[e,r]of[["fusermount",["-u","-z",t]],["umount",[t]]])try{await u(e,r);break}catch{}try{await (0,n.rmdir)(t)}catch{}}e.s(["assertSshfsAvailable",0,c,"isMounted",0,p,"mountSshfs",0,h,"mountpointFor",0,function(e){return a.default.join(d(),e)},"mountsDir",0,d,"unmountSshfs",0,m],256294)},402662,e=>{"use strict";var t=e.i(351216);e.s(["checkOrigin",0,function(e){let r=e.method.toUpperCase();if("GET"===r||"HEAD"===r||"OPTIONS"===r)return null;let s=e.headers.get("origin"),n=e.headers.get("referer");if(!s&&!n)return null;let a=function(e){let t=Array.from(new Set(["localhost","127.0.0.1",e.split(":")[0],...(process.env.WIKI_OWNER_HOSTS??"").split(",").map(e=>e.trim()).filter(Boolean)])),r=["",":3000",":3003"];e.includes(":")&&r.push(":"+e.split(":")[1]);let s=new Set;for(let e of t)for(let t of["http","https"])for(let n of r)s.add(`${t}://${e}${n}`);return s}(e.headers.get("host")??"");if(s)return a.has(s)?null:t.NextResponse.json({error:"FORBIDDEN",message:"Bad origin"},{status:403});if(n){try{let{protocol:e,host:t}=new URL(n);if(a.has(`${e}//${t}`))return null}catch{}return t.NextResponse.json({error:"FORBIDDEN",message:"Bad referer"},{status:403})}return null}])},262758,e=>{"use strict";var t=e.i(985426),r=e.i(257574),s=e.i(507835),n=e.i(457789),a=e.i(119791),i=e.i(141062),o=e.i(957291),l=e.i(535899),u=e.i(610241),d=e.i(62749),c=e.i(624891),p=e.i(725836),h=e.i(532736),m=e.i(257858),f=e.i(487476),v=e.i(193695);e.i(484264);var w=e.i(315709),g=e.i(912714),y=e.i(351216),R=e.i(402662),_=e.i(254226),k=e.i(583627),A=e.i(798003),E=e.i(359211);async function N(e){if("1"===process.env.WIKI_NO_AUTH){await (0,E.migrateConfigToWorkspaces)();let e=(await (0,E.listWorkspaces)()).map(E.sanitizeWorkspace);return y.NextResponse.json({workspaces:e,isAdmin:!0})}let t=await (0,_.requireUser)(e);if(!t.ok)return y.NextResponse.json({error:"UNAUTHORIZED"},{status:401});await (0,k.ensureBootstrapAdmin)(t.user.id),await (0,E.migrateConfigToWorkspaces)();let r=await (0,k.isAdmin)(t.user.id,t.user.email),s=(await (0,E.listWorkspaces)()).filter(e=>(0,E.userCanAccess)(e,t.user.id,r)).map(E.sanitizeWorkspace);return y.NextResponse.json({workspaces:s,isAdmin:r})}async function x(e){let t=(0,R.checkOrigin)(e);if(t)return t;let r=await (0,k.requireAdmin)(e);if(!r.ok)return y.NextResponse.json({error:r.code},{status:r.status});let s=await e.json();if(s.sshTarget){let e,t=s.sshAuthMethod??"agent";if(!["agent","keyfile","password"].includes(t))return y.NextResponse.json({error:"Invalid auth method"},{status:400});if(void 0!==s.sshPort&&(!Number.isInteger(e=Number(s.sshPort))||e<1||e>65535))return y.NextResponse.json({error:"Invalid port"},{status:400});try{let n=await (0,E.createSshWorkspace)({target:s.sshTarget,port:e,authMethod:t,keyPath:s.sshKeyPath?.trim()||void 0,password:s.sshPassword||void 0,readOnly:!0===s.sshReadOnly,name:s.name?.trim()||void 0,createdBy:r.user.id});return y.NextResponse.json({ok:!0,workspace:(0,E.sanitizeWorkspace)(n)})}catch(t){let e=t instanceof Error?t.message:String(t);return y.NextResponse.json({error:e},{status:400})}}if(s.remoteUrl){if(void 0!==s.subpath&&"string"!=typeof s.subpath)return y.NextResponse.json({error:"Invalid subpath"},{status:400});let e=s.subpath?.trim()||void 0;if(e&&(e.startsWith("/")||e.includes("..")||/[;|&$`<>(){}\n\0]/.test(e)))return y.NextResponse.json({error:"Invalid subpath"},{status:400});let t=await (0,A.readConfig)();try{let n=await (0,E.createGitWorkspace)({remoteUrl:s.remoteUrl,branch:s.branch?.trim()||void 0,token:s.token||void 0,username:s.username?.trim()||void 0,name:s.name?.trim()||void 0,createdBy:r.user.id,allowedHosts:t.git?.allowedHosts,allowInsecureHttp:t.git?.allowInsecureHttp,subpath:e});return y.NextResponse.json({ok:!0,workspace:(0,E.sanitizeWorkspace)(n)})}catch(t){let e=t instanceof Error?t.message:String(t);return y.NextResponse.json({error:e},{status:400})}}let n=s.rootDir?.trim();if(!n)return y.NextResponse.json({error:"Missing rootDir"},{status:400});try{if(!(await (0,g.stat)(n)).isDirectory())return y.NextResponse.json({error:"Not a directory"},{status:400})}catch{return y.NextResponse.json({error:"Directory not found"},{status:404})}let a=await (0,E.createWorkspace)({rootDir:n,name:s.name?.trim()||void 0,createdBy:r.user.id});return y.NextResponse.json({ok:!0,workspace:(0,E.sanitizeWorkspace)(a)})}e.s(["GET",0,N,"POST",0,x,"runtime",0,"nodejs"],401923);var I=e.i(401923);let b=new t.AppRouteRouteModule({definition:{kind:r.RouteKind.APP_ROUTE,page:"/api/system/workspaces/route",pathname:"/api/system/workspaces",filename:"route",bundlePath:""},distDir:".next",relativeProjectDir:"",resolvedPagePath:"[project]/src/app/api/system/workspaces/route.ts",nextConfigOutput:"standalone",userland:I,...{}}),{workAsyncStorage:C,workUnitAsyncStorage:P,serverHooks:T}=b;async function S(e,t,s){s.requestMeta&&(0,n.setRequestMeta)(e,s.requestMeta),b.isDev&&(0,n.addRequestMeta)(e,"devRequestTimingInternalsEnd",process.hrtime.bigint());let g="/api/system/workspaces/route";g=g.replace(/\/index$/,"")||"/";let y=await b.prepare(e,t,{srcPage:g,multiZoneDraftMode:!1});if(!y)return t.statusCode=400,t.end("Bad Request"),null==s.waitUntil||s.waitUntil.call(s,Promise.resolve()),null;let{buildId:R,params:_,nextConfig:k,parsedUrl:A,isDraftMode:E,prerenderManifest:N,routerServerContext:x,isOnDemandRevalidate:I,revalidateOnlyGenerated:C,resolvedPathname:P,clientReferenceManifest:T,serverActionsManifest:S}=y,O=(0,o.normalizeAppPath)(g),j=!!(N.dynamicRoutes[O]||N.routes[P]),U=async()=>((null==x?void 0:x.render404)?await x.render404(e,t,A,!1):t.end("This page could not be found"),null);if(j&&!E){let e=!!N.routes[P],t=N.dynamicRoutes[O];if(t&&!1===t.fallback&&!e){if(k.adapterPath)return await U();throw new v.NoFallbackError}}let q=null;!j||b.isDev||E||(q="/index"===(q=P)?"/":q);let D=!0===b.isDev||!j,H=j&&!D;S&&T&&(0,i.setManifestsSingleton)({page:g,clientReferenceManifest:T,serverActionsManifest:S});let M=e.method||"GET",$=(0,a.getTracer)(),W=$.getActiveScopeSpan(),B=!!(null==x?void 0:x.isWrappedByNextServer),K=!!(0,n.getRequestMeta)(e,"minimalMode"),F=(0,n.getRequestMeta)(e,"incrementalCache")||await b.getIncrementalCache(e,k,N,K);null==F||F.resetRequestCache(),globalThis.__incrementalCache=F;let z={params:_,previewProps:N.preview,renderOpts:{experimental:{authInterrupts:!!k.experimental.authInterrupts},cacheComponents:!!k.cacheComponents,supportsDynamicResponse:D,incrementalCache:F,cacheLifeProfiles:k.cacheLife,waitUntil:s.waitUntil,onClose:e=>{t.on("close",e)},onAfterTaskError:void 0,onInstrumentationRequestError:(t,r,s,n)=>b.onRequestError(e,t,s,n,x)},sharedContext:{buildId:R}},L=new l.NodeNextRequest(e),G=new l.NodeNextResponse(t),Z=u.NextRequestAdapter.fromNodeNextRequest(L,(0,u.signalFromNodeResponse)(t));try{let n,i=async e=>b.handle(Z,z).finally(()=>{if(!e)return;e.setAttributes({"http.status_code":t.statusCode,"next.rsc":!1});let r=$.getRootSpanAttributes();if(!r)return;if(r.get("next.span_type")!==d.BaseServerSpan.handleRequest)return void console.warn(`Unexpected root span type '${r.get("next.span_type")}'. Please report this Next.js issue https://github.com/vercel/next.js`);let s=r.get("next.route");if(s){let t=`${M} ${s}`;e.setAttributes({"next.route":s,"http.route":s,"next.span_name":t}),e.updateName(t),n&&n!==e&&(n.setAttribute("http.route",s),n.updateName(t))}else e.updateName(`${M} ${g}`)}),o=async n=>{var a,o;let l=async({previousCacheEntry:r})=>{try{if(!K&&I&&C&&!r)return t.statusCode=404,t.setHeader("x-nextjs-cache","REVALIDATED"),t.end("This page could not be found"),null;let a=await i(n);e.fetchMetrics=z.renderOpts.fetchMetrics;let o=z.renderOpts.pendingWaitUntil;o&&s.waitUntil&&(s.waitUntil(o),o=void 0);let l=z.renderOpts.collectedTags;if(!j)return await (0,p.sendResponse)(L,G,a,z.renderOpts.pendingWaitUntil),null;{let e=await a.blob(),t=(0,h.toNodeOutgoingHttpHeaders)(a.headers);l&&(t[f.NEXT_CACHE_TAGS_HEADER]=l),!t["content-type"]&&e.type&&(t["content-type"]=e.type);let r=void 0!==z.renderOpts.collectedRevalidate&&!(z.renderOpts.collectedRevalidate>=f.INFINITE_CACHE)&&z.renderOpts.collectedRevalidate,s=void 0===z.renderOpts.collectedExpire||z.renderOpts.collectedExpire>=f.INFINITE_CACHE?void 0:z.renderOpts.collectedExpire;return{value:{kind:w.CachedRouteKind.APP_ROUTE,status:a.status,body:Buffer.from(await e.arrayBuffer()),headers:t},cacheControl:{revalidate:r,expire:s}}}}catch(t){throw(null==r?void 0:r.isStale)&&await b.onRequestError(e,t,{routerKind:"App Router",routePath:g,routeType:"route",revalidateReason:(0,c.getRevalidateReason)({isStaticGeneration:H,isOnDemandRevalidate:I})},!1,x),t}},u=await b.handleResponse({req:e,nextConfig:k,cacheKey:q,routeKind:r.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:N,isRoutePPREnabled:!1,isOnDemandRevalidate:I,revalidateOnlyGenerated:C,responseGenerator:l,waitUntil:s.waitUntil,isMinimalMode:K});if(!j)return null;if((null==u||null==(a=u.value)?void 0:a.kind)!==w.CachedRouteKind.APP_ROUTE)throw Object.defineProperty(Error(`Invariant: app-route received invalid cache entry ${null==u||null==(o=u.value)?void 0:o.kind}`),"__NEXT_ERROR_CODE",{value:"E701",enumerable:!1,configurable:!0});K||t.setHeader("x-nextjs-cache",I?"REVALIDATED":u.isMiss?"MISS":u.isStale?"STALE":"HIT"),E&&t.setHeader("Cache-Control","private, no-cache, no-store, max-age=0, must-revalidate");let d=(0,h.fromNodeOutgoingHttpHeaders)(u.value.headers);return K&&j||d.delete(f.NEXT_CACHE_TAGS_HEADER),!u.cacheControl||t.getHeader("Cache-Control")||d.get("Cache-Control")||d.set("Cache-Control",(0,m.getCacheControlHeader)(u.cacheControl)),await (0,p.sendResponse)(L,G,new Response(u.value.body,{headers:d,status:u.value.status||200})),null};B&&W?await o(W):(n=$.getActiveScopeSpan(),await $.withPropagatedContext(e.headers,()=>$.trace(d.BaseServerSpan.handleRequest,{spanName:`${M} ${g}`,kind:a.SpanKind.SERVER,attributes:{"http.method":M,"http.target":e.url}},o),void 0,!B))}catch(t){if(t instanceof v.NoFallbackError||await b.onRequestError(e,t,{routerKind:"App Router",routePath:O,routeType:"route",revalidateReason:(0,c.getRevalidateReason)({isStaticGeneration:H,isOnDemandRevalidate:I})},!1,x),j)throw t;return await (0,p.sendResponse)(L,G,new Response(null,{status:500})),null}}e.s(["handler",0,S,"patchFetch",0,function(){return(0,s.patchFetch)({workAsyncStorage:C,workUnitAsyncStorage:P})},"routeModule",0,b,"serverHooks",0,T,"workAsyncStorage",0,C,"workUnitAsyncStorage",0,P],262758)},168315,e=>{e.v(t=>Promise.all(["server/chunks/0sag_@better-auth_memory-adapter_dist_index_mjs_0pvj6im._.js"].map(t=>e.l(t))).then(()=>t(862112)))},769787,e=>{e.v(t=>Promise.all(["server/chunks/01er_better-auth_dist_adapters_kysely-adapter_index_mjs_0s~-4gu._.js"].map(t=>e.l(t))).then(()=>t(717789)))},580632,e=>{e.v(e=>Promise.resolve().then(()=>e(270406)))},947559,e=>{e.v(t=>Promise.all(["server/chunks/0ugq_@better-auth_kysely-adapter_dist_bun-sqlite-dialect-DzNwOpKv_mjs_0z1z6m4._.js"].map(t=>e.l(t))).then(()=>t(495181)))},715018,e=>{e.v(t=>Promise.all(["server/chunks/0ugq_@better-auth_kysely-adapter_dist_node-sqlite-dialect_mjs_0qqlvhl._.js"].map(t=>e.l(t))).then(()=>t(698370)))},146843,e=>{e.v(t=>Promise.all(["server/chunks/0ugq_@better-auth_kysely-adapter_dist_d1-sqlite-dialect-C2B7YsIT_mjs_0wynrz3._.js"].map(t=>e.l(t))).then(()=>t(143740)))},697743,e=>{e.v(t=>Promise.all(["server/chunks/0.u4_next_05jevxw._.js"].map(t=>e.l(t))).then(()=>t(428325)))},99243,e=>{e.v(e=>Promise.resolve().then(()=>e(313414)))},893412,e=>{e.v(t=>Promise.all(["server/chunks/src_lib_auth_api-key_ts_0t_ma-t._.js"].map(t=>e.l(t))).then(()=>t(499465)))},687903,e=>{e.v(e=>Promise.resolve().then(()=>e(912714)))}];
2
2
 
3
3
  //# sourceMappingURL=%5Broot-of-the-server%5D__0tuu3y1._.js.map
@@ -1,3 +1,3 @@
1
- module.exports=[583627,e=>{"use strict";var t=e.i(798003),r=e.i(254226);function a(){return(process.env.WIKI_ADMIN_EMAILS??"").split(",").map(e=>e.trim().toLowerCase()).filter(Boolean)}async function s(e,r){if(r){let e=a();if(e.length>0&&e.includes(r.toLowerCase()))return!0}return((await (0,t.readConfig)()).adminUserIds??[]).includes(e)}async function n(){return(await (0,t.readConfig)()).adminUserIds??[]}async function i(e){await (0,t.updateConfig)(t=>{let r=t.adminUserIds??[];return r.includes(e)?t:{...t,adminUserIds:[...r,e]}})}async function o(e){let r=a().length>0,s=!1;if(await (0,t.updateConfig)(t=>{let a=(t.adminUserIds??[]).filter(t=>t!==e);return 0!==a.length||r?{...t,adminUserIds:a}:(s=!0,t)}),s)throw Error("LAST_ADMIN: cannot remove the last admin with no WIKI_ADMIN_EMAILS configured")}async function l(e){if(a().length>0||r.SYNTHETIC_USER_IDS.has(e)||((await (0,t.readConfig)()).adminUserIds??[]).length>0)return;let s=!1;await (0,t.updateConfig)(t=>(t.adminUserIds??[]).length>0?t:(s=!0,{...t,adminUserIds:[e]})),s&&console.log(`[wiki-viewer] Bootstrap: first user ${e} promoted to admin`)}async function u(e){if("1"===process.env.WIKI_NO_AUTH)return{ok:!0,user:{id:"local",email:"local@localhost",name:"local"}};let t=await (0,r.requireUser)(e);return t.ok?await s(t.user.id,t.user.email)?{ok:!0,user:t.user}:{ok:!1,status:403,code:"ADMIN_REQUIRED"}:{ok:!1,status:401,code:"UNAUTHORIZED"}}e.s(["addAdmin",0,i,"ensureBootstrapAdmin",0,l,"isAdmin",0,s,"listAdmins",0,n,"removeAdmin",0,o,"requireAdmin",0,u])},812057,(e,t,r)=>{t.exports=e.x("node:util",()=>require("node:util"))},874533,(e,t,r)=>{t.exports=e.x("node:child_process",()=>require("node:child_process"))},256294,296555,e=>{"use strict";let t;var r=e.i(874533),a=e.i(812057),s=e.i(912714),n=e.i(750227),i=e.i(660526);e.i(902157);let o=RegExp("[;|&$`<>(){}\\n\\r\\0]");function l(e){let{target:t,mountpoint:r,port:a}=e,s=t.user?`${t.user}@`:"",n=[`${s}${t.host}:${t.remotePath}`,r];a&&Number.isInteger(Number(a))&&Number(a)>0&&65536>Number(a)&&n.push("-p",String(a));let i=e.authMethod??"agent";!e.authMethod&&(null!=e.password?i="password":e.keyPath&&(i="keyfile"));let o=["reconnect","ServerAliveInterval=15","ServerAliveCountMax=3","compression=yes","cache=yes","kernel_cache","StrictHostKeyChecking=accept-new","BatchMode=yes"];if(e.readOnly&&o.push("ro"),"keyfile"===i&&e.keyPath&&(o.push(`IdentityFile=${e.keyPath}`),o.push("IdentitiesOnly=yes")),"password"===i){let e=o.indexOf("BatchMode=yes");e>=0&&o.splice(e,1),o.push("password_stdin"),o.push("PreferredAuthentications=password,keyboard-interactive"),o.push("PubkeyAuthentication=no"),o.push("NumberOfPasswordPrompts=1")}return e.extraOptions&&o.push(...e.extraOptions),n.push("-o",o.join(",")),n}e.s(["buildSshfsArgs",0,l,"isValidKeyPath",0,function(e){return!(!e||o.test(e)||e.includes(".."))&&(e.startsWith("/")||e.startsWith("~/"))},"parseSshTarget",0,function(e){let t;if(!e||o.test(e))return null;let r=e.trim(),a=r.indexOf(":");if(a<=0)return null;let s=r.slice(0,a),n=r.slice(a+1);if(!n.startsWith("/")||n.includes(".."))return null;let i=s,l=s.indexOf("@");return l>=0&&(t=s.slice(0,l),i=s.slice(l+1),!t)?null:i&&/^[a-zA-Z0-9.\-]+$/.test(i)&&(!t||/^[a-zA-Z0-9._\-]+$/.test(t))?{user:t,host:i,remotePath:n}:null}],296555);let u=(0,a.promisify)(r.execFile);function c(){return n.default.join(i.default.homedir(),".wiki-viewer","mounts")}async function d(){if(!0!==t)try{await u("sshfs",["--version"]),t=!0}catch{throw Error("sshfs binary not found. Install sshfs + FUSE (e.g. `apt install sshfs`, `brew install macfuse sshfs`) and ensure it is on PATH.")}}async function p(t){var r;let a=n.default.resolve(t),i=!1;try{i=(await (0,s.readFile)("/proc/mounts","utf8")).split("\n").some(e=>{let t=e.split(" ");return t[1]===a&&/fuse/.test(t[2]??"")})}catch{i=!1}return!!i&&(r=a,new Promise(t=>{let a=!1,s=setTimeout(()=>{a||(a=!0,t(!1))},4e3);e.A(687903).then(({readdir:e})=>e(r)).then(()=>{a||(a=!0,clearTimeout(s),t(!0))}).catch(()=>{a||(a=!0,clearTimeout(s),t(!1))})}))}async function h(e){await d(),await (0,s.mkdir)(e.mountpoint,{recursive:!0});let t=l(e);if(await new Promise((a,s)=>{let n=(0,r.spawn)("sshfs",t,{stdio:["pipe","ignore","pipe"]}),i="",o=setTimeout(()=>{n.kill("SIGKILL"),s(Error("sshfs mount timed out after 25s."))},25e3);n.stderr?.on("data",e=>{i+=e.toString()}),n.on("error",e=>{clearTimeout(o),s(e.message.includes("ENOENT")?Error("sshfs binary not found on PATH."):e)}),n.on("close",e=>{clearTimeout(o),0===e?a():s(Error(`sshfs exited ${e}: ${i.trim()||"mount failed"}`))}),"password"===e.authMethod&&n.stdin?.write((e.password??"")+"\n"),n.stdin?.end()}),!await p(e.mountpoint))throw Error("sshfs reported success but the mount is not live.")}async function m(e){let t=n.default.resolve(e);for(let[e,r]of[["fusermount",["-u","-z",t]],["umount",[t]]])try{await u(e,r);break}catch{}try{await (0,s.rmdir)(t)}catch{}}e.s(["assertSshfsAvailable",0,d,"isMounted",0,p,"mountSshfs",0,h,"mountpointFor",0,function(e){return n.default.join(c(),e)},"mountsDir",0,c,"unmountSshfs",0,m],256294)},536654,e=>{"use strict";var t=e.i(912714),r=e.i(750227);function a(e){return!!(r.default.isAbsolute(e)||".."===e||e.startsWith(".."+r.default.sep)||e.startsWith("../"))}async function s(e,n,i={}){let o;if(!e)return null;let l=function(e){if(e.includes("\0")||r.default.isAbsolute(e))return null;let t=e.replace(/\\/g,"/");return(("."===(t=r.default.posix.normalize(t))||"./"===t)&&(t=""),".."===t||t.startsWith("../")||/^[a-zA-Z]:\//.test(t)||t.startsWith("/"))?null:t}(n);if(null===l)return null;if(i.deniedSegments?.length){for(let e of l.split("/").filter(Boolean))if(i.deniedSegments.includes(e))return null}try{o=await (0,t.realpath)(e)}catch{return null}let u=l?r.default.join(o,l):o;try{let e=await (0,t.realpath)(u),s=r.default.relative(o,e);if(a(s))return null;return{relPath:l,absolutePath:e}}catch{if(!i.allowMissing)return null;let e=u;for(;;){let s=r.default.dirname(e);if(s===e)break;try{let e=await (0,t.realpath)(s),n=r.default.relative(o,e);if(a(n))return null;return{relPath:l,absolutePath:u}}catch{e=s}}return null}}e.s(["resolveWorkspacePath",0,s])},814747,(e,t,r)=>{t.exports=e.x("path",()=>require("path"))},224361,(e,t,r)=>{t.exports=e.x("util",()=>require("util"))},688947,(e,t,r)=>{t.exports=e.x("stream",()=>require("stream"))},427699,(e,t,r)=>{t.exports=e.x("events",()=>require("events"))},857764,(e,t,r)=>{t.exports=e.x("node:url",()=>require("node:url"))},848475,e=>{"use strict";var t=e.i(750227);let r={".md":"text/markdown; charset=utf-8",".markdown":"text/markdown; charset=utf-8",".mdx":"text/markdown; charset=utf-8",".txt":"text/plain; charset=utf-8",".json":"application/json; charset=utf-8",".jsonc":"application/json; charset=utf-8",".ts":"text/typescript; charset=utf-8",".tsx":"text/typescript; charset=utf-8",".mts":"text/typescript; charset=utf-8",".js":"text/javascript; charset=utf-8",".jsx":"text/javascript; charset=utf-8",".mjs":"text/javascript; charset=utf-8",".html":"text/html; charset=utf-8",".htm":"text/html; charset=utf-8",".css":"text/css; charset=utf-8",".yaml":"text/yaml; charset=utf-8",".yml":"text/yaml; charset=utf-8",".toml":"text/toml; charset=utf-8",".xml":"application/xml; charset=utf-8",".svg":"image/svg+xml",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".avif":"image/avif",".ico":"image/x-icon",".bmp":"image/bmp",".pdf":"application/pdf",".zip":"application/zip",".tar":"application/x-tar",".gz":"application/gzip",".py":"text/x-python; charset=utf-8",".rs":"text/x-rustsrc; charset=utf-8",".go":"text/x-go; charset=utf-8",".sh":"text/x-shellscript; charset=utf-8",".csv":"text/csv; charset=utf-8",".tsv":"text/tab-separated-values; charset=utf-8",".env":"text/plain; charset=utf-8",".log":"text/plain; charset=utf-8",".ini":"text/plain; charset=utf-8",".conf":"text/plain; charset=utf-8",".mmd":"text/plain; charset=utf-8",".ipynb":"application/json; charset=utf-8",".docx":"application/vnd.openxmlformats-officedocument.wordprocessingml.document",".xlsx":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",".pptx":"application/vnd.openxmlformats-officedocument.presentationml.presentation",".doc":"application/msword",".xls":"application/vnd.ms-excel",".ppt":"application/vnd.ms-powerpoint",".mp4":"video/mp4",".webm":"video/webm",".mov":"video/quicktime",".m4v":"video/mp4",".mp3":"audio/mpeg",".wav":"audio/wav",".ogg":"audio/ogg",".m4a":"audio/mp4",".aac":"audio/aac"};e.s(["contentTypeForPath",0,function(e){return r[t.default.extname(e).toLowerCase()]??"application/octet-stream"}])},81111,(e,t,r)=>{t.exports=e.x("node:stream",()=>require("node:stream"))},727028,(e,t,r)=>{t.exports=e.x("node:zlib",()=>require("node:zlib"))},526798,e=>{"use strict";var t=e.i(985426),r=e.i(257574),a=e.i(507835),s=e.i(457789),n=e.i(119791),i=e.i(141062),o=e.i(957291),l=e.i(535899),u=e.i(610241),c=e.i(62749),d=e.i(624891),p=e.i(725836),h=e.i(532736),m=e.i(257858),f=e.i(487476),v=e.i(193695);e.i(484264);var x=e.i(315709),w=e.i(912714),g=e.i(351216),y=e.i(723012),_=e.i(345212),R=e.i(762512);async function E(e){let t=await (0,R.getBySlug)(e);if(!t)return null;if("html"===t.type)return{kind:"html",entry:t,workspaceId:t.workspaceId,relPath:t.relPath};let r=(0,_.getStatus)(t.workspaceId,t.relPath);return{kind:"node",entry:t,workspaceId:t.workspaceId,relPath:t.relPath,port:r.port,status:r.status}}var P=e.i(536654),A=e.i(716234),k=e.i(848475),N=e.i(583627),b=e.i(254226),I=e.i(359211);async function C(e,t){let r=await (0,I.getWorkspace)(t);if(!r)return g.NextResponse.json({error:"WORKSPACE_NOT_FOUND"},{status:404});if("1"===process.env.WIKI_NO_AUTH)return null;let a=await (0,b.requireUser)(e);if(!a.ok)return g.NextResponse.json({error:"UNAUTHORIZED"},{status:401});let s=await (0,N.isAdmin)(a.user.id,a.user.email);return(0,I.userCanAccess)(r,a.user.id,s)?null:g.NextResponse.json({error:"WORKSPACE_FORBIDDEN"},{status:403})}async function T(e,t,r){let a=r.filter(Boolean).join("/"),s=await (0,P.resolveWorkspacePath)(e,t,{deniedSegments:A.DENIED_SEGMENTS});if(!s)return g.NextResponse.json({error:"Invalid path"},{status:400});let n=!1;try{n=(await (0,w.stat)(s.absolutePath)).isFile()}catch{return g.NextResponse.json({error:"File not found"},{status:404})}let i=n?t.split("/").slice(0,-1).join("/"):t,o=n?t:`${t}/index.html`.replace(/\/+/g,"/").replace(/^\//,""),l=""===a?o:[i,a].filter(Boolean).join("/"),u=await (0,P.resolveWorkspacePath)(e,l,{deniedSegments:A.DENIED_SEGMENTS});if(!u)return g.NextResponse.json({error:"Invalid path"},{status:400});try{if((await (0,w.stat)(u.absolutePath)).isDirectory()){let t=await (0,P.resolveWorkspacePath)(e,`${l}/index.html`,{deniedSegments:A.DENIED_SEGMENTS});if(!t)return g.NextResponse.json({error:"Not found"},{status:404});let r=await (0,w.readFile)(t.absolutePath);return new Response(new Uint8Array(r),{headers:{"Content-Type":"text/html; charset=utf-8","Cache-Control":"no-store"}})}let t=await (0,w.readFile)(u.absolutePath);return new Response(new Uint8Array(t),{headers:{"Content-Type":(0,k.contentTypeForPath)(u.absolutePath),"Cache-Control":"private, max-age=60"}})}catch{return g.NextResponse.json({error:"File not found"},{status:404})}}async function S(e,{params:t}){let{slug:r,rest:a}=await t,s=await E(r);if(!s)return g.NextResponse.json({error:"SLUG_NOT_FOUND"},{status:404});let n=await C(e,s.workspaceId);if(n)return n;let i=await (0,I.getWorkspace)(s.workspaceId);if(!i)return g.NextResponse.json({error:"WORKSPACE_NOT_FOUND"},{status:404});if("html"===s.kind)return T(i.rootDir,s.relPath,a??[]);if(!s.port||"running"!==s.status)return new Response(`<!doctype html><meta charset="utf-8"><title>App stopped</title><body style="font:14px system-ui;padding:2rem;color:#444"><h1 style="font-size:1.1rem">This app is not running</h1><p>The hosted app <code>${r}</code> is stopped. Start it from the Hosted Apps section in the sidebar, then reload.</p></body>`,{status:503,headers:{"content-type":"text/html; charset=utf-8","cache-control":"no-store"}});let o="/"+(a??[]).filter(Boolean).join("/");return(0,y.forwardToChild)(e,{port:s.port,rest:o,proxyBase:`/app/${r}`})}e.s(["DELETE",0,S,"GET",0,S,"HEAD",0,S,"OPTIONS",0,S,"PATCH",0,S,"POST",0,S,"PUT",0,S,"dynamic",0,"force-dynamic"],512415);var j=e.i(512415);let O=new t.AppRouteRouteModule({definition:{kind:r.RouteKind.APP_ROUTE,page:"/app/[slug]/[[...rest]]/route",pathname:"/app/[slug]/[[...rest]]",filename:"route",bundlePath:""},distDir:".next",relativeProjectDir:"",resolvedPagePath:"[project]/src/app/app/[slug]/[[...rest]]/route.ts",nextConfigOutput:"standalone",userland:j,...{}}),{workAsyncStorage:U,workUnitAsyncStorage:q,serverHooks:D}=O;async function M(e,t,a){a.requestMeta&&(0,s.setRequestMeta)(e,a.requestMeta),O.isDev&&(0,s.addRequestMeta)(e,"devRequestTimingInternalsEnd",process.hrtime.bigint());let w="/app/[slug]/[[...rest]]/route";w=w.replace(/\/index$/,"")||"/";let g=await O.prepare(e,t,{srcPage:w,multiZoneDraftMode:!1});if(!g)return t.statusCode=400,t.end("Bad Request"),null==a.waitUntil||a.waitUntil.call(a,Promise.resolve()),null;let{buildId:y,params:_,nextConfig:R,parsedUrl:E,isDraftMode:P,prerenderManifest:A,routerServerContext:k,isOnDemandRevalidate:N,revalidateOnlyGenerated:b,resolvedPathname:I,clientReferenceManifest:C,serverActionsManifest:T}=g,S=(0,o.normalizeAppPath)(w),j=!!(A.dynamicRoutes[S]||A.routes[I]),U=async()=>((null==k?void 0:k.render404)?await k.render404(e,t,E,!1):t.end("This page could not be found"),null);if(j&&!P){let e=!!A.routes[I],t=A.dynamicRoutes[S];if(t&&!1===t.fallback&&!e){if(R.adapterPath)return await U();throw new v.NoFallbackError}}let q=null;!j||O.isDev||P||(q="/index"===(q=I)?"/":q);let D=!0===O.isDev||!j,M=j&&!D;T&&C&&(0,i.setManifestsSingleton)({page:w,clientReferenceManifest:C,serverActionsManifest:T});let H=e.method||"GET",F=(0,n.getTracer)(),$=F.getActiveScopeSpan(),W=!!(null==k?void 0:k.isWrappedByNextServer),B=!!(0,s.getRequestMeta)(e,"minimalMode"),K=(0,s.getRequestMeta)(e,"incrementalCache")||await O.getIncrementalCache(e,R,A,B);null==K||K.resetRequestCache(),globalThis.__incrementalCache=K;let z={params:_,previewProps:A.preview,renderOpts:{experimental:{authInterrupts:!!R.experimental.authInterrupts},cacheComponents:!!R.cacheComponents,supportsDynamicResponse:D,incrementalCache:K,cacheLifeProfiles:R.cacheLife,waitUntil:a.waitUntil,onClose:e=>{t.on("close",e)},onAfterTaskError:void 0,onInstrumentationRequestError:(t,r,a,s)=>O.onRequestError(e,t,a,s,k)},sharedContext:{buildId:y}},L=new l.NodeNextRequest(e),G=new l.NodeNextResponse(t),Z=u.NextRequestAdapter.fromNodeNextRequest(L,(0,u.signalFromNodeResponse)(t));try{let s,i=async e=>O.handle(Z,z).finally(()=>{if(!e)return;e.setAttributes({"http.status_code":t.statusCode,"next.rsc":!1});let r=F.getRootSpanAttributes();if(!r)return;if(r.get("next.span_type")!==c.BaseServerSpan.handleRequest)return void console.warn(`Unexpected root span type '${r.get("next.span_type")}'. Please report this Next.js issue https://github.com/vercel/next.js`);let a=r.get("next.route");if(a){let t=`${H} ${a}`;e.setAttributes({"next.route":a,"http.route":a,"next.span_name":t}),e.updateName(t),s&&s!==e&&(s.setAttribute("http.route",a),s.updateName(t))}else e.updateName(`${H} ${w}`)}),o=async s=>{var n,o;let l=async({previousCacheEntry:r})=>{try{if(!B&&N&&b&&!r)return t.statusCode=404,t.setHeader("x-nextjs-cache","REVALIDATED"),t.end("This page could not be found"),null;let n=await i(s);e.fetchMetrics=z.renderOpts.fetchMetrics;let o=z.renderOpts.pendingWaitUntil;o&&a.waitUntil&&(a.waitUntil(o),o=void 0);let l=z.renderOpts.collectedTags;if(!j)return await (0,p.sendResponse)(L,G,n,z.renderOpts.pendingWaitUntil),null;{let e=await n.blob(),t=(0,h.toNodeOutgoingHttpHeaders)(n.headers);l&&(t[f.NEXT_CACHE_TAGS_HEADER]=l),!t["content-type"]&&e.type&&(t["content-type"]=e.type);let r=void 0!==z.renderOpts.collectedRevalidate&&!(z.renderOpts.collectedRevalidate>=f.INFINITE_CACHE)&&z.renderOpts.collectedRevalidate,a=void 0===z.renderOpts.collectedExpire||z.renderOpts.collectedExpire>=f.INFINITE_CACHE?void 0:z.renderOpts.collectedExpire;return{value:{kind:x.CachedRouteKind.APP_ROUTE,status:n.status,body:Buffer.from(await e.arrayBuffer()),headers:t},cacheControl:{revalidate:r,expire:a}}}}catch(t){throw(null==r?void 0:r.isStale)&&await O.onRequestError(e,t,{routerKind:"App Router",routePath:w,routeType:"route",revalidateReason:(0,d.getRevalidateReason)({isStaticGeneration:M,isOnDemandRevalidate:N})},!1,k),t}},u=await O.handleResponse({req:e,nextConfig:R,cacheKey:q,routeKind:r.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:A,isRoutePPREnabled:!1,isOnDemandRevalidate:N,revalidateOnlyGenerated:b,responseGenerator:l,waitUntil:a.waitUntil,isMinimalMode:B});if(!j)return null;if((null==u||null==(n=u.value)?void 0:n.kind)!==x.CachedRouteKind.APP_ROUTE)throw Object.defineProperty(Error(`Invariant: app-route received invalid cache entry ${null==u||null==(o=u.value)?void 0:o.kind}`),"__NEXT_ERROR_CODE",{value:"E701",enumerable:!1,configurable:!0});B||t.setHeader("x-nextjs-cache",N?"REVALIDATED":u.isMiss?"MISS":u.isStale?"STALE":"HIT"),P&&t.setHeader("Cache-Control","private, no-cache, no-store, max-age=0, must-revalidate");let c=(0,h.fromNodeOutgoingHttpHeaders)(u.value.headers);return B&&j||c.delete(f.NEXT_CACHE_TAGS_HEADER),!u.cacheControl||t.getHeader("Cache-Control")||c.get("Cache-Control")||c.set("Cache-Control",(0,m.getCacheControlHeader)(u.cacheControl)),await (0,p.sendResponse)(L,G,new Response(u.value.body,{headers:c,status:u.value.status||200})),null};W&&$?await o($):(s=F.getActiveScopeSpan(),await F.withPropagatedContext(e.headers,()=>F.trace(c.BaseServerSpan.handleRequest,{spanName:`${H} ${w}`,kind:n.SpanKind.SERVER,attributes:{"http.method":H,"http.target":e.url}},o),void 0,!W))}catch(t){if(t instanceof v.NoFallbackError||await O.onRequestError(e,t,{routerKind:"App Router",routePath:S,routeType:"route",revalidateReason:(0,d.getRevalidateReason)({isStaticGeneration:M,isOnDemandRevalidate:N})},!1,k),j)throw t;return await (0,p.sendResponse)(L,G,new Response(null,{status:500})),null}}e.s(["handler",0,M,"patchFetch",0,function(){return(0,a.patchFetch)({workAsyncStorage:U,workUnitAsyncStorage:q})},"routeModule",0,O,"serverHooks",0,D,"workAsyncStorage",0,U,"workUnitAsyncStorage",0,q],526798)},282139,e=>{e.v(e=>Promise.resolve().then(()=>e(351216)))},687903,e=>{e.v(e=>Promise.resolve().then(()=>e(912714)))},168315,e=>{e.v(t=>Promise.all(["server/chunks/0sag_@better-auth_memory-adapter_dist_index_mjs_0pvj6im._.js"].map(t=>e.l(t))).then(()=>t(862112)))},769787,e=>{e.v(t=>Promise.all(["server/chunks/01er_better-auth_dist_adapters_kysely-adapter_index_mjs_0s~-4gu._.js"].map(t=>e.l(t))).then(()=>t(717789)))},580632,e=>{e.v(e=>Promise.resolve().then(()=>e(270406)))},947559,e=>{e.v(t=>Promise.all(["server/chunks/0ugq_@better-auth_kysely-adapter_dist_bun-sqlite-dialect-DzNwOpKv_mjs_0z1z6m4._.js"].map(t=>e.l(t))).then(()=>t(495181)))},715018,e=>{e.v(t=>Promise.all(["server/chunks/0ugq_@better-auth_kysely-adapter_dist_node-sqlite-dialect_mjs_0qqlvhl._.js"].map(t=>e.l(t))).then(()=>t(698370)))},146843,e=>{e.v(t=>Promise.all(["server/chunks/0ugq_@better-auth_kysely-adapter_dist_d1-sqlite-dialect-C2B7YsIT_mjs_0wynrz3._.js"].map(t=>e.l(t))).then(()=>t(143740)))},697743,e=>{e.v(t=>Promise.all(["server/chunks/0.u4_next_05jevxw._.js"].map(t=>e.l(t))).then(()=>t(428325)))},99243,e=>{e.v(e=>Promise.resolve().then(()=>e(313414)))},893412,e=>{e.v(t=>Promise.all(["server/chunks/src_lib_auth_api-key_ts_0t_ma-t._.js"].map(t=>e.l(t))).then(()=>t(499465)))}];
1
+ module.exports=[583627,e=>{"use strict";var t=e.i(798003),r=e.i(254226);function a(){return(process.env.WIKI_ADMIN_EMAILS??"").split(",").map(e=>e.trim().toLowerCase()).filter(Boolean)}async function s(e,r){if(r){let e=a();if(e.length>0&&e.includes(r.toLowerCase()))return!0}return((await (0,t.readConfig)()).adminUserIds??[]).includes(e)}async function n(){return(await (0,t.readConfig)()).adminUserIds??[]}async function i(e){await (0,t.updateConfig)(t=>{let r=t.adminUserIds??[];return r.includes(e)?t:{...t,adminUserIds:[...r,e]}})}async function o(e){let r=a().length>0,s=!1;if(await (0,t.updateConfig)(t=>{let a=(t.adminUserIds??[]).filter(t=>t!==e);return 0!==a.length||r?{...t,adminUserIds:a}:(s=!0,t)}),s)throw Error("LAST_ADMIN: cannot remove the last admin with no WIKI_ADMIN_EMAILS configured")}async function l(e){if(a().length>0||r.SYNTHETIC_USER_IDS.has(e)||((await (0,t.readConfig)()).adminUserIds??[]).length>0)return;let s=!1;await (0,t.updateConfig)(t=>(t.adminUserIds??[]).length>0?t:(s=!0,{...t,adminUserIds:[e]})),s&&console.log(`[wiki-viewer] Bootstrap: first user ${e} promoted to admin`)}async function u(e){if("1"===process.env.WIKI_NO_AUTH)return{ok:!0,user:{id:"local",email:"local@localhost",name:"local"}};let t=await (0,r.requireUser)(e);return t.ok?await s(t.user.id,t.user.email)?{ok:!0,user:t.user}:{ok:!1,status:403,code:"ADMIN_REQUIRED"}:{ok:!1,status:401,code:"UNAUTHORIZED"}}e.s(["addAdmin",0,i,"ensureBootstrapAdmin",0,l,"isAdmin",0,s,"listAdmins",0,n,"removeAdmin",0,o,"requireAdmin",0,u])},812057,(e,t,r)=>{t.exports=e.x("node:util",()=>require("node:util"))},874533,(e,t,r)=>{t.exports=e.x("node:child_process",()=>require("node:child_process"))},256294,296555,e=>{"use strict";let t;var r=e.i(874533),a=e.i(812057),s=e.i(912714),n=e.i(750227),i=e.i(660526);e.i(902157);let o=RegExp("[;|&$`<>(){}\\n\\r\\0]");function l(e){let{target:t,mountpoint:r,port:a}=e,s=t.user?`${t.user}@`:"",n=[`${s}${t.host}:${t.remotePath}`,r];a&&Number.isInteger(Number(a))&&Number(a)>0&&65536>Number(a)&&n.push("-p",String(a));let i=e.authMethod??"agent";!e.authMethod&&(null!=e.password?i="password":e.keyPath&&(i="keyfile"));let o=["reconnect","ServerAliveInterval=15","ServerAliveCountMax=3","compression=yes","cache=yes","StrictHostKeyChecking=accept-new","BatchMode=yes"];if(e.readOnly&&o.push("ro"),"keyfile"===i&&e.keyPath&&(o.push(`IdentityFile=${e.keyPath}`),o.push("IdentitiesOnly=yes")),"password"===i){let e=o.indexOf("BatchMode=yes");e>=0&&o.splice(e,1),o.push("password_stdin"),o.push("PreferredAuthentications=password,keyboard-interactive"),o.push("PubkeyAuthentication=no"),o.push("NumberOfPasswordPrompts=1")}return e.extraOptions&&o.push(...e.extraOptions),n.push("-o",o.join(",")),n}e.s(["buildSshfsArgs",0,l,"isValidKeyPath",0,function(e){return!(!e||o.test(e)||e.includes(".."))&&(e.startsWith("/")||e.startsWith("~/"))},"parseSshTarget",0,function(e){let t;if(!e||o.test(e))return null;let r=e.trim(),a=r.indexOf(":");if(a<=0)return null;let s=r.slice(0,a),n=r.slice(a+1);if(!n.startsWith("/")||n.includes(".."))return null;let i=s,l=s.indexOf("@");return l>=0&&(t=s.slice(0,l),i=s.slice(l+1),!t)?null:i&&/^[a-zA-Z0-9.\-]+$/.test(i)&&(!t||/^[a-zA-Z0-9._\-]+$/.test(t))?{user:t,host:i,remotePath:n}:null}],296555);let u=(0,a.promisify)(r.execFile);function d(){return n.default.join(i.default.homedir(),".wiki-viewer","mounts")}async function c(){if(!0!==t)try{await u("sshfs",["--version"]),t=!0}catch{throw Error("sshfs binary not found. Install sshfs + FUSE (e.g. `apt install sshfs`, `brew install macfuse sshfs`) and ensure it is on PATH.")}}async function p(t){var r;let a=n.default.resolve(t),i=!1;try{i=(await (0,s.readFile)("/proc/mounts","utf8")).split("\n").some(e=>{let t=e.split(" ");return t[1]===a&&/fuse/.test(t[2]??"")})}catch{i=!1}return!!i&&(r=a,new Promise(t=>{let a=!1,s=setTimeout(()=>{a||(a=!0,t(!1))},4e3);e.A(687903).then(({readdir:e})=>e(r)).then(()=>{a||(a=!0,clearTimeout(s),t(!0))}).catch(()=>{a||(a=!0,clearTimeout(s),t(!1))})}))}async function h(e){await c(),await (0,s.mkdir)(e.mountpoint,{recursive:!0});let t=l(e);if(await new Promise((a,s)=>{let n=(0,r.spawn)("sshfs",t,{stdio:["pipe","ignore","pipe"]}),i="",o=setTimeout(()=>{n.kill("SIGKILL"),s(Error("sshfs mount timed out after 25s."))},25e3);n.stderr?.on("data",e=>{i+=e.toString()}),n.on("error",e=>{clearTimeout(o),s(e.message.includes("ENOENT")?Error("sshfs binary not found on PATH."):e)}),n.on("close",e=>{clearTimeout(o),0===e?a():s(Error(`sshfs exited ${e}: ${i.trim()||"mount failed"}`))}),"password"===e.authMethod&&n.stdin?.write((e.password??"")+"\n"),n.stdin?.end()}),!await p(e.mountpoint))throw Error("sshfs reported success but the mount is not live.")}async function m(e){let t=n.default.resolve(e);for(let[e,r]of[["fusermount",["-u","-z",t]],["umount",[t]]])try{await u(e,r);break}catch{}try{await (0,s.rmdir)(t)}catch{}}e.s(["assertSshfsAvailable",0,c,"isMounted",0,p,"mountSshfs",0,h,"mountpointFor",0,function(e){return n.default.join(d(),e)},"mountsDir",0,d,"unmountSshfs",0,m],256294)},536654,e=>{"use strict";var t=e.i(912714),r=e.i(750227);function a(e){return!!(r.default.isAbsolute(e)||".."===e||e.startsWith(".."+r.default.sep)||e.startsWith("../"))}async function s(e,n,i={}){let o;if(!e)return null;let l=function(e){if(e.includes("\0")||r.default.isAbsolute(e))return null;let t=e.replace(/\\/g,"/");return(("."===(t=r.default.posix.normalize(t))||"./"===t)&&(t=""),".."===t||t.startsWith("../")||/^[a-zA-Z]:\//.test(t)||t.startsWith("/"))?null:t}(n);if(null===l)return null;if(i.deniedSegments?.length){for(let e of l.split("/").filter(Boolean))if(i.deniedSegments.includes(e))return null}try{o=await (0,t.realpath)(e)}catch{return null}let u=l?r.default.join(o,l):o;try{let e=await (0,t.realpath)(u),s=r.default.relative(o,e);if(a(s))return null;return{relPath:l,absolutePath:e}}catch{if(!i.allowMissing)return null;let e=u;for(;;){let s=r.default.dirname(e);if(s===e)break;try{let e=await (0,t.realpath)(s),n=r.default.relative(o,e);if(a(n))return null;return{relPath:l,absolutePath:u}}catch{e=s}}return null}}e.s(["resolveWorkspacePath",0,s])},814747,(e,t,r)=>{t.exports=e.x("path",()=>require("path"))},224361,(e,t,r)=>{t.exports=e.x("util",()=>require("util"))},688947,(e,t,r)=>{t.exports=e.x("stream",()=>require("stream"))},427699,(e,t,r)=>{t.exports=e.x("events",()=>require("events"))},857764,(e,t,r)=>{t.exports=e.x("node:url",()=>require("node:url"))},848475,e=>{"use strict";var t=e.i(750227);let r={".md":"text/markdown; charset=utf-8",".markdown":"text/markdown; charset=utf-8",".mdx":"text/markdown; charset=utf-8",".txt":"text/plain; charset=utf-8",".json":"application/json; charset=utf-8",".jsonc":"application/json; charset=utf-8",".ts":"text/typescript; charset=utf-8",".tsx":"text/typescript; charset=utf-8",".mts":"text/typescript; charset=utf-8",".js":"text/javascript; charset=utf-8",".jsx":"text/javascript; charset=utf-8",".mjs":"text/javascript; charset=utf-8",".html":"text/html; charset=utf-8",".htm":"text/html; charset=utf-8",".css":"text/css; charset=utf-8",".yaml":"text/yaml; charset=utf-8",".yml":"text/yaml; charset=utf-8",".toml":"text/toml; charset=utf-8",".xml":"application/xml; charset=utf-8",".svg":"image/svg+xml",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".avif":"image/avif",".ico":"image/x-icon",".bmp":"image/bmp",".pdf":"application/pdf",".zip":"application/zip",".tar":"application/x-tar",".gz":"application/gzip",".py":"text/x-python; charset=utf-8",".rs":"text/x-rustsrc; charset=utf-8",".go":"text/x-go; charset=utf-8",".sh":"text/x-shellscript; charset=utf-8",".csv":"text/csv; charset=utf-8",".tsv":"text/tab-separated-values; charset=utf-8",".env":"text/plain; charset=utf-8",".log":"text/plain; charset=utf-8",".ini":"text/plain; charset=utf-8",".conf":"text/plain; charset=utf-8",".mmd":"text/plain; charset=utf-8",".ipynb":"application/json; charset=utf-8",".docx":"application/vnd.openxmlformats-officedocument.wordprocessingml.document",".xlsx":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",".pptx":"application/vnd.openxmlformats-officedocument.presentationml.presentation",".doc":"application/msword",".xls":"application/vnd.ms-excel",".ppt":"application/vnd.ms-powerpoint",".mp4":"video/mp4",".webm":"video/webm",".mov":"video/quicktime",".m4v":"video/mp4",".mp3":"audio/mpeg",".wav":"audio/wav",".ogg":"audio/ogg",".m4a":"audio/mp4",".aac":"audio/aac"};e.s(["contentTypeForPath",0,function(e){return r[t.default.extname(e).toLowerCase()]??"application/octet-stream"}])},81111,(e,t,r)=>{t.exports=e.x("node:stream",()=>require("node:stream"))},727028,(e,t,r)=>{t.exports=e.x("node:zlib",()=>require("node:zlib"))},526798,e=>{"use strict";var t=e.i(985426),r=e.i(257574),a=e.i(507835),s=e.i(457789),n=e.i(119791),i=e.i(141062),o=e.i(957291),l=e.i(535899),u=e.i(610241),d=e.i(62749),c=e.i(624891),p=e.i(725836),h=e.i(532736),m=e.i(257858),f=e.i(487476),v=e.i(193695);e.i(484264);var x=e.i(315709),w=e.i(912714),g=e.i(351216),y=e.i(723012),_=e.i(345212),R=e.i(762512);async function E(e){let t=await (0,R.getBySlug)(e);if(!t)return null;if("html"===t.type)return{kind:"html",entry:t,workspaceId:t.workspaceId,relPath:t.relPath};let r=(0,_.getStatus)(t.workspaceId,t.relPath);return{kind:"node",entry:t,workspaceId:t.workspaceId,relPath:t.relPath,port:r.port,status:r.status}}var P=e.i(536654),A=e.i(716234),N=e.i(848475),b=e.i(583627),k=e.i(254226),I=e.i(359211);async function C(e,t){let r=await (0,I.getWorkspace)(t);if(!r)return g.NextResponse.json({error:"WORKSPACE_NOT_FOUND"},{status:404});if("1"===process.env.WIKI_NO_AUTH)return null;let a=await (0,k.requireUser)(e);if(!a.ok)return g.NextResponse.json({error:"UNAUTHORIZED"},{status:401});let s=await (0,b.isAdmin)(a.user.id,a.user.email);return(0,I.userCanAccess)(r,a.user.id,s)?null:g.NextResponse.json({error:"WORKSPACE_FORBIDDEN"},{status:403})}async function T(e,t,r){let a=r.filter(Boolean).join("/"),s=await (0,P.resolveWorkspacePath)(e,t,{deniedSegments:A.DENIED_SEGMENTS});if(!s)return g.NextResponse.json({error:"Invalid path"},{status:400});let n=!1;try{n=(await (0,w.stat)(s.absolutePath)).isFile()}catch{return g.NextResponse.json({error:"File not found"},{status:404})}let i=n?t.split("/").slice(0,-1).join("/"):t,o=n?t:`${t}/index.html`.replace(/\/+/g,"/").replace(/^\//,""),l=""===a?o:[i,a].filter(Boolean).join("/"),u=await (0,P.resolveWorkspacePath)(e,l,{deniedSegments:A.DENIED_SEGMENTS});if(!u)return g.NextResponse.json({error:"Invalid path"},{status:400});try{if((await (0,w.stat)(u.absolutePath)).isDirectory()){let t=await (0,P.resolveWorkspacePath)(e,`${l}/index.html`,{deniedSegments:A.DENIED_SEGMENTS});if(!t)return g.NextResponse.json({error:"Not found"},{status:404});let r=await (0,w.readFile)(t.absolutePath);return new Response(new Uint8Array(r),{headers:{"Content-Type":"text/html; charset=utf-8","Cache-Control":"no-store"}})}let t=await (0,w.readFile)(u.absolutePath);return new Response(new Uint8Array(t),{headers:{"Content-Type":(0,N.contentTypeForPath)(u.absolutePath),"Cache-Control":"private, max-age=60"}})}catch{return g.NextResponse.json({error:"File not found"},{status:404})}}async function S(e,{params:t}){let{slug:r,rest:a}=await t,s=await E(r);if(!s)return g.NextResponse.json({error:"SLUG_NOT_FOUND"},{status:404});let n=await C(e,s.workspaceId);if(n)return n;let i=await (0,I.getWorkspace)(s.workspaceId);if(!i)return g.NextResponse.json({error:"WORKSPACE_NOT_FOUND"},{status:404});if("html"===s.kind)return T(i.rootDir,s.relPath,a??[]);if(!s.port||"running"!==s.status)return new Response(`<!doctype html><meta charset="utf-8"><title>App stopped</title><body style="font:14px system-ui;padding:2rem;color:#444"><h1 style="font-size:1.1rem">This app is not running</h1><p>The hosted app <code>${r}</code> is stopped. Start it from the Hosted Apps section in the sidebar, then reload.</p></body>`,{status:503,headers:{"content-type":"text/html; charset=utf-8","cache-control":"no-store"}});let o="/"+(a??[]).filter(Boolean).join("/");return(0,y.forwardToChild)(e,{port:s.port,rest:o,proxyBase:`/app/${r}`})}e.s(["DELETE",0,S,"GET",0,S,"HEAD",0,S,"OPTIONS",0,S,"PATCH",0,S,"POST",0,S,"PUT",0,S,"dynamic",0,"force-dynamic"],512415);var j=e.i(512415);let O=new t.AppRouteRouteModule({definition:{kind:r.RouteKind.APP_ROUTE,page:"/app/[slug]/[[...rest]]/route",pathname:"/app/[slug]/[[...rest]]",filename:"route",bundlePath:""},distDir:".next",relativeProjectDir:"",resolvedPagePath:"[project]/src/app/app/[slug]/[[...rest]]/route.ts",nextConfigOutput:"standalone",userland:j,...{}}),{workAsyncStorage:U,workUnitAsyncStorage:q,serverHooks:D}=O;async function M(e,t,a){a.requestMeta&&(0,s.setRequestMeta)(e,a.requestMeta),O.isDev&&(0,s.addRequestMeta)(e,"devRequestTimingInternalsEnd",process.hrtime.bigint());let w="/app/[slug]/[[...rest]]/route";w=w.replace(/\/index$/,"")||"/";let g=await O.prepare(e,t,{srcPage:w,multiZoneDraftMode:!1});if(!g)return t.statusCode=400,t.end("Bad Request"),null==a.waitUntil||a.waitUntil.call(a,Promise.resolve()),null;let{buildId:y,params:_,nextConfig:R,parsedUrl:E,isDraftMode:P,prerenderManifest:A,routerServerContext:N,isOnDemandRevalidate:b,revalidateOnlyGenerated:k,resolvedPathname:I,clientReferenceManifest:C,serverActionsManifest:T}=g,S=(0,o.normalizeAppPath)(w),j=!!(A.dynamicRoutes[S]||A.routes[I]),U=async()=>((null==N?void 0:N.render404)?await N.render404(e,t,E,!1):t.end("This page could not be found"),null);if(j&&!P){let e=!!A.routes[I],t=A.dynamicRoutes[S];if(t&&!1===t.fallback&&!e){if(R.adapterPath)return await U();throw new v.NoFallbackError}}let q=null;!j||O.isDev||P||(q="/index"===(q=I)?"/":q);let D=!0===O.isDev||!j,M=j&&!D;T&&C&&(0,i.setManifestsSingleton)({page:w,clientReferenceManifest:C,serverActionsManifest:T});let H=e.method||"GET",F=(0,n.getTracer)(),$=F.getActiveScopeSpan(),W=!!(null==N?void 0:N.isWrappedByNextServer),B=!!(0,s.getRequestMeta)(e,"minimalMode"),K=(0,s.getRequestMeta)(e,"incrementalCache")||await O.getIncrementalCache(e,R,A,B);null==K||K.resetRequestCache(),globalThis.__incrementalCache=K;let z={params:_,previewProps:A.preview,renderOpts:{experimental:{authInterrupts:!!R.experimental.authInterrupts},cacheComponents:!!R.cacheComponents,supportsDynamicResponse:D,incrementalCache:K,cacheLifeProfiles:R.cacheLife,waitUntil:a.waitUntil,onClose:e=>{t.on("close",e)},onAfterTaskError:void 0,onInstrumentationRequestError:(t,r,a,s)=>O.onRequestError(e,t,a,s,N)},sharedContext:{buildId:y}},L=new l.NodeNextRequest(e),G=new l.NodeNextResponse(t),Z=u.NextRequestAdapter.fromNodeNextRequest(L,(0,u.signalFromNodeResponse)(t));try{let s,i=async e=>O.handle(Z,z).finally(()=>{if(!e)return;e.setAttributes({"http.status_code":t.statusCode,"next.rsc":!1});let r=F.getRootSpanAttributes();if(!r)return;if(r.get("next.span_type")!==d.BaseServerSpan.handleRequest)return void console.warn(`Unexpected root span type '${r.get("next.span_type")}'. Please report this Next.js issue https://github.com/vercel/next.js`);let a=r.get("next.route");if(a){let t=`${H} ${a}`;e.setAttributes({"next.route":a,"http.route":a,"next.span_name":t}),e.updateName(t),s&&s!==e&&(s.setAttribute("http.route",a),s.updateName(t))}else e.updateName(`${H} ${w}`)}),o=async s=>{var n,o;let l=async({previousCacheEntry:r})=>{try{if(!B&&b&&k&&!r)return t.statusCode=404,t.setHeader("x-nextjs-cache","REVALIDATED"),t.end("This page could not be found"),null;let n=await i(s);e.fetchMetrics=z.renderOpts.fetchMetrics;let o=z.renderOpts.pendingWaitUntil;o&&a.waitUntil&&(a.waitUntil(o),o=void 0);let l=z.renderOpts.collectedTags;if(!j)return await (0,p.sendResponse)(L,G,n,z.renderOpts.pendingWaitUntil),null;{let e=await n.blob(),t=(0,h.toNodeOutgoingHttpHeaders)(n.headers);l&&(t[f.NEXT_CACHE_TAGS_HEADER]=l),!t["content-type"]&&e.type&&(t["content-type"]=e.type);let r=void 0!==z.renderOpts.collectedRevalidate&&!(z.renderOpts.collectedRevalidate>=f.INFINITE_CACHE)&&z.renderOpts.collectedRevalidate,a=void 0===z.renderOpts.collectedExpire||z.renderOpts.collectedExpire>=f.INFINITE_CACHE?void 0:z.renderOpts.collectedExpire;return{value:{kind:x.CachedRouteKind.APP_ROUTE,status:n.status,body:Buffer.from(await e.arrayBuffer()),headers:t},cacheControl:{revalidate:r,expire:a}}}}catch(t){throw(null==r?void 0:r.isStale)&&await O.onRequestError(e,t,{routerKind:"App Router",routePath:w,routeType:"route",revalidateReason:(0,c.getRevalidateReason)({isStaticGeneration:M,isOnDemandRevalidate:b})},!1,N),t}},u=await O.handleResponse({req:e,nextConfig:R,cacheKey:q,routeKind:r.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:A,isRoutePPREnabled:!1,isOnDemandRevalidate:b,revalidateOnlyGenerated:k,responseGenerator:l,waitUntil:a.waitUntil,isMinimalMode:B});if(!j)return null;if((null==u||null==(n=u.value)?void 0:n.kind)!==x.CachedRouteKind.APP_ROUTE)throw Object.defineProperty(Error(`Invariant: app-route received invalid cache entry ${null==u||null==(o=u.value)?void 0:o.kind}`),"__NEXT_ERROR_CODE",{value:"E701",enumerable:!1,configurable:!0});B||t.setHeader("x-nextjs-cache",b?"REVALIDATED":u.isMiss?"MISS":u.isStale?"STALE":"HIT"),P&&t.setHeader("Cache-Control","private, no-cache, no-store, max-age=0, must-revalidate");let d=(0,h.fromNodeOutgoingHttpHeaders)(u.value.headers);return B&&j||d.delete(f.NEXT_CACHE_TAGS_HEADER),!u.cacheControl||t.getHeader("Cache-Control")||d.get("Cache-Control")||d.set("Cache-Control",(0,m.getCacheControlHeader)(u.cacheControl)),await (0,p.sendResponse)(L,G,new Response(u.value.body,{headers:d,status:u.value.status||200})),null};W&&$?await o($):(s=F.getActiveScopeSpan(),await F.withPropagatedContext(e.headers,()=>F.trace(d.BaseServerSpan.handleRequest,{spanName:`${H} ${w}`,kind:n.SpanKind.SERVER,attributes:{"http.method":H,"http.target":e.url}},o),void 0,!W))}catch(t){if(t instanceof v.NoFallbackError||await O.onRequestError(e,t,{routerKind:"App Router",routePath:S,routeType:"route",revalidateReason:(0,c.getRevalidateReason)({isStaticGeneration:M,isOnDemandRevalidate:b})},!1,N),j)throw t;return await (0,p.sendResponse)(L,G,new Response(null,{status:500})),null}}e.s(["handler",0,M,"patchFetch",0,function(){return(0,a.patchFetch)({workAsyncStorage:U,workUnitAsyncStorage:q})},"routeModule",0,O,"serverHooks",0,D,"workAsyncStorage",0,U,"workUnitAsyncStorage",0,q],526798)},282139,e=>{e.v(e=>Promise.resolve().then(()=>e(351216)))},687903,e=>{e.v(e=>Promise.resolve().then(()=>e(912714)))},168315,e=>{e.v(t=>Promise.all(["server/chunks/0sag_@better-auth_memory-adapter_dist_index_mjs_0pvj6im._.js"].map(t=>e.l(t))).then(()=>t(862112)))},769787,e=>{e.v(t=>Promise.all(["server/chunks/01er_better-auth_dist_adapters_kysely-adapter_index_mjs_0s~-4gu._.js"].map(t=>e.l(t))).then(()=>t(717789)))},580632,e=>{e.v(e=>Promise.resolve().then(()=>e(270406)))},947559,e=>{e.v(t=>Promise.all(["server/chunks/0ugq_@better-auth_kysely-adapter_dist_bun-sqlite-dialect-DzNwOpKv_mjs_0z1z6m4._.js"].map(t=>e.l(t))).then(()=>t(495181)))},715018,e=>{e.v(t=>Promise.all(["server/chunks/0ugq_@better-auth_kysely-adapter_dist_node-sqlite-dialect_mjs_0qqlvhl._.js"].map(t=>e.l(t))).then(()=>t(698370)))},146843,e=>{e.v(t=>Promise.all(["server/chunks/0ugq_@better-auth_kysely-adapter_dist_d1-sqlite-dialect-C2B7YsIT_mjs_0wynrz3._.js"].map(t=>e.l(t))).then(()=>t(143740)))},697743,e=>{e.v(t=>Promise.all(["server/chunks/0.u4_next_05jevxw._.js"].map(t=>e.l(t))).then(()=>t(428325)))},99243,e=>{e.v(e=>Promise.resolve().then(()=>e(313414)))},893412,e=>{e.v(t=>Promise.all(["server/chunks/src_lib_auth_api-key_ts_0t_ma-t._.js"].map(t=>e.l(t))).then(()=>t(499465)))}];
2
2
 
3
3
  //# sourceMappingURL=%5Broot-of-the-server%5D__0z5f4h8._.js.map
@@ -1,4 +1,4 @@
1
- module.exports=[874533,(e,t,r)=>{t.exports=e.x("node:child_process",()=>require("node:child_process"))},812057,(e,t,r)=>{t.exports=e.x("node:util",()=>require("node:util"))},256294,296555,e=>{"use strict";let t;var r=e.i(874533),s=e.i(812057),a=e.i(912714),i=e.i(750227),n=e.i(660526);e.i(902157);let o=RegExp("[;|&$`<>(){}\\n\\r\\0]");function l(e){let{target:t,mountpoint:r,port:s}=e,a=t.user?`${t.user}@`:"",i=[`${a}${t.host}:${t.remotePath}`,r];s&&Number.isInteger(Number(s))&&Number(s)>0&&65536>Number(s)&&i.push("-p",String(s));let n=e.authMethod??"agent";!e.authMethod&&(null!=e.password?n="password":e.keyPath&&(n="keyfile"));let o=["reconnect","ServerAliveInterval=15","ServerAliveCountMax=3","compression=yes","cache=yes","kernel_cache","StrictHostKeyChecking=accept-new","BatchMode=yes"];if(e.readOnly&&o.push("ro"),"keyfile"===n&&e.keyPath&&(o.push(`IdentityFile=${e.keyPath}`),o.push("IdentitiesOnly=yes")),"password"===n){let e=o.indexOf("BatchMode=yes");e>=0&&o.splice(e,1),o.push("password_stdin"),o.push("PreferredAuthentications=password,keyboard-interactive"),o.push("PubkeyAuthentication=no"),o.push("NumberOfPasswordPrompts=1")}return e.extraOptions&&o.push(...e.extraOptions),i.push("-o",o.join(",")),i}e.s(["buildSshfsArgs",0,l,"isValidKeyPath",0,function(e){return!(!e||o.test(e)||e.includes(".."))&&(e.startsWith("/")||e.startsWith("~/"))},"parseSshTarget",0,function(e){let t;if(!e||o.test(e))return null;let r=e.trim(),s=r.indexOf(":");if(s<=0)return null;let a=r.slice(0,s),i=r.slice(s+1);if(!i.startsWith("/")||i.includes(".."))return null;let n=a,l=a.indexOf("@");return l>=0&&(t=a.slice(0,l),n=a.slice(l+1),!t)?null:n&&/^[a-zA-Z0-9.\-]+$/.test(n)&&(!t||/^[a-zA-Z0-9._\-]+$/.test(t))?{user:t,host:n,remotePath:i}:null}],296555);let u=(0,s.promisify)(r.execFile);function c(){return i.default.join(n.default.homedir(),".wiki-viewer","mounts")}async function d(){if(!0!==t)try{await u("sshfs",["--version"]),t=!0}catch{throw Error("sshfs binary not found. Install sshfs + FUSE (e.g. `apt install sshfs`, `brew install macfuse sshfs`) and ensure it is on PATH.")}}async function p(t){var r;let s=i.default.resolve(t),n=!1;try{n=(await (0,a.readFile)("/proc/mounts","utf8")).split("\n").some(e=>{let t=e.split(" ");return t[1]===s&&/fuse/.test(t[2]??"")})}catch{n=!1}return!!n&&(r=s,new Promise(t=>{let s=!1,a=setTimeout(()=>{s||(s=!0,t(!1))},4e3);e.A(687903).then(({readdir:e})=>e(r)).then(()=>{s||(s=!0,clearTimeout(a),t(!0))}).catch(()=>{s||(s=!0,clearTimeout(a),t(!1))})}))}async function h(e){await d(),await (0,a.mkdir)(e.mountpoint,{recursive:!0});let t=l(e);if(await new Promise((s,a)=>{let i=(0,r.spawn)("sshfs",t,{stdio:["pipe","ignore","pipe"]}),n="",o=setTimeout(()=>{i.kill("SIGKILL"),a(Error("sshfs mount timed out after 25s."))},25e3);i.stderr?.on("data",e=>{n+=e.toString()}),i.on("error",e=>{clearTimeout(o),a(e.message.includes("ENOENT")?Error("sshfs binary not found on PATH."):e)}),i.on("close",e=>{clearTimeout(o),0===e?s():a(Error(`sshfs exited ${e}: ${n.trim()||"mount failed"}`))}),"password"===e.authMethod&&i.stdin?.write((e.password??"")+"\n"),i.stdin?.end()}),!await p(e.mountpoint))throw Error("sshfs reported success but the mount is not live.")}async function f(e){let t=i.default.resolve(e);for(let[e,r]of[["fusermount",["-u","-z",t]],["umount",[t]]])try{await u(e,r);break}catch{}try{await (0,a.rmdir)(t)}catch{}}e.s(["assertSshfsAvailable",0,d,"isMounted",0,p,"mountSshfs",0,h,"mountpointFor",0,function(e){return i.default.join(c(),e)},"mountsDir",0,c,"unmountSshfs",0,f],256294)},536654,e=>{"use strict";var t=e.i(912714),r=e.i(750227);function s(e){return!!(r.default.isAbsolute(e)||".."===e||e.startsWith(".."+r.default.sep)||e.startsWith("../"))}async function a(e,i,n={}){let o;if(!e)return null;let l=function(e){if(e.includes("\0")||r.default.isAbsolute(e))return null;let t=e.replace(/\\/g,"/");return(("."===(t=r.default.posix.normalize(t))||"./"===t)&&(t=""),".."===t||t.startsWith("../")||/^[a-zA-Z]:\//.test(t)||t.startsWith("/"))?null:t}(i);if(null===l)return null;if(n.deniedSegments?.length){for(let e of l.split("/").filter(Boolean))if(n.deniedSegments.includes(e))return null}try{o=await (0,t.realpath)(e)}catch{return null}let u=l?r.default.join(o,l):o;try{let e=await (0,t.realpath)(u),a=r.default.relative(o,e);if(s(a))return null;return{relPath:l,absolutePath:e}}catch{if(!n.allowMissing)return null;let e=u;for(;;){let a=r.default.dirname(e);if(a===e)break;try{let e=await (0,t.realpath)(a),i=r.default.relative(o,e);if(s(i))return null;return{relPath:l,absolutePath:u}}catch{e=a}}return null}}e.s(["resolveWorkspacePath",0,a])},848475,e=>{"use strict";var t=e.i(750227);let r={".md":"text/markdown; charset=utf-8",".markdown":"text/markdown; charset=utf-8",".mdx":"text/markdown; charset=utf-8",".txt":"text/plain; charset=utf-8",".json":"application/json; charset=utf-8",".jsonc":"application/json; charset=utf-8",".ts":"text/typescript; charset=utf-8",".tsx":"text/typescript; charset=utf-8",".mts":"text/typescript; charset=utf-8",".js":"text/javascript; charset=utf-8",".jsx":"text/javascript; charset=utf-8",".mjs":"text/javascript; charset=utf-8",".html":"text/html; charset=utf-8",".htm":"text/html; charset=utf-8",".css":"text/css; charset=utf-8",".yaml":"text/yaml; charset=utf-8",".yml":"text/yaml; charset=utf-8",".toml":"text/toml; charset=utf-8",".xml":"application/xml; charset=utf-8",".svg":"image/svg+xml",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".avif":"image/avif",".ico":"image/x-icon",".bmp":"image/bmp",".pdf":"application/pdf",".zip":"application/zip",".tar":"application/x-tar",".gz":"application/gzip",".py":"text/x-python; charset=utf-8",".rs":"text/x-rustsrc; charset=utf-8",".go":"text/x-go; charset=utf-8",".sh":"text/x-shellscript; charset=utf-8",".csv":"text/csv; charset=utf-8",".tsv":"text/tab-separated-values; charset=utf-8",".env":"text/plain; charset=utf-8",".log":"text/plain; charset=utf-8",".ini":"text/plain; charset=utf-8",".conf":"text/plain; charset=utf-8",".mmd":"text/plain; charset=utf-8",".ipynb":"application/json; charset=utf-8",".docx":"application/vnd.openxmlformats-officedocument.wordprocessingml.document",".xlsx":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",".pptx":"application/vnd.openxmlformats-officedocument.presentationml.presentation",".doc":"application/msword",".xls":"application/vnd.ms-excel",".ppt":"application/vnd.ms-powerpoint",".mp4":"video/mp4",".webm":"video/webm",".mov":"video/quicktime",".m4v":"video/mp4",".mp3":"audio/mpeg",".wav":"audio/wav",".ogg":"audio/ogg",".m4a":"audio/mp4",".aac":"audio/aac"};e.s(["contentTypeForPath",0,function(e){return r[t.default.extname(e).toLowerCase()]??"application/octet-stream"}])},719126,e=>{"use strict";var t=e.i(666680),r=e.i(912714),s=e.i(750227),a=e.i(716234),i=e.i(536654),n=e.i(848475);async function o(e,t){if(!e)return null;let r=await (0,i.resolveWorkspacePath)(e,t,{allowMissing:!0,deniedSegments:a.DENIED_SEGMENTS});return r?.absolutePath??null}async function l(e,t){let s=420;try{let t=await (0,r.stat)(e);s=511&t.mode}catch{}let a=e+".~"+process.pid+"."+Date.now()+".tmp",i=await (0,r.open)(a,"w",s);try{await i.write(t),await i.datasync()}finally{await i.close()}await (0,r.rename)(a,e)}async function u(e,t){let a=s.default.dirname(e);if(t)return await (0,r.mkdir)(a,{recursive:!0}),!0;try{return await (0,r.stat)(a),!0}catch{return!1}}e.s(["atomicWrite",0,l,"ensureParentDir",0,u,"extractShaHex",0,function(e){return e.replace(/^"/,"").replace(/"$/,"").replace(/^sha256:/,"")},"isDeniedRelPath",0,function(e){let t=e.replace(/\\/g,"/");return a.DENIED_SEGMENTS.some(e=>t===e||t.startsWith(e+"/"))},"isMarkdown",0,function(e){return e.endsWith(".md")||e.endsWith(".markdown")},"looksLikeBinary",0,function(e){return e.slice(0,Math.min(e.length,8192)).includes(0)},"mimeByExt",0,function(e){return(0,n.contentTypeForPath)(e)},"safeAbsPath",0,o,"sha256ofBuf",0,function(e){return"sha256:"+(0,t.createHash)("sha256").update(e).digest("hex")}])},487018,e=>{"use strict";var t=e.x("node:sqlite",()=>require("node:sqlite"),!0);function r(e){return 1===e.length&&Array.isArray(e[0])?e[0]:e}class s{stmt;constructor(e){this.stmt=e}get reader(){return this.stmt.columns().length>0}all(...e){let t=r(e);return this.stmt.all(...t)}get(...e){let t=r(e);return this.stmt.get(...t)}run(...e){let t=r(e),s=this.stmt.run(...t);return{changes:Number(s.changes),lastInsertRowid:Number(s.lastInsertRowid)}}iterate(...e){let t=r(e);return this.stmt.iterate(...t)}}class a{db;constructor(e){this.db=new t.DatabaseSync(e),this.db.exec("PRAGMA busy_timeout = 5000"),this.db.exec("PRAGMA journal_mode = WAL")}prepare(e){return new s(this.db.prepare(e))}exec(e){this.db.exec(e)}close(){this.db.close()}pragma(e){this.db.exec(`PRAGMA ${e}`)}}e.s(["default",()=>a])},97082,e=>{"use strict";var t=e.i(487018),r=e.i(750227),s=e.i(660526),a=e.i(902157),i=e.i(666680);let n=null;function o(){var e;if(n)return n;let i=r.default.join(process.env.HOME??s.default.homedir(),".wiki-viewer");return(0,a.mkdirSync)(i,{recursive:!0}),(n=new t.default(r.default.join(i,"shared.db"))).pragma("journal_mode = WAL"),n.pragma("synchronous = NORMAL"),n.exec(`
1
+ module.exports=[874533,(e,t,r)=>{t.exports=e.x("node:child_process",()=>require("node:child_process"))},812057,(e,t,r)=>{t.exports=e.x("node:util",()=>require("node:util"))},256294,296555,e=>{"use strict";let t;var r=e.i(874533),s=e.i(812057),a=e.i(912714),i=e.i(750227),n=e.i(660526);e.i(902157);let o=RegExp("[;|&$`<>(){}\\n\\r\\0]");function l(e){let{target:t,mountpoint:r,port:s}=e,a=t.user?`${t.user}@`:"",i=[`${a}${t.host}:${t.remotePath}`,r];s&&Number.isInteger(Number(s))&&Number(s)>0&&65536>Number(s)&&i.push("-p",String(s));let n=e.authMethod??"agent";!e.authMethod&&(null!=e.password?n="password":e.keyPath&&(n="keyfile"));let o=["reconnect","ServerAliveInterval=15","ServerAliveCountMax=3","compression=yes","cache=yes","StrictHostKeyChecking=accept-new","BatchMode=yes"];if(e.readOnly&&o.push("ro"),"keyfile"===n&&e.keyPath&&(o.push(`IdentityFile=${e.keyPath}`),o.push("IdentitiesOnly=yes")),"password"===n){let e=o.indexOf("BatchMode=yes");e>=0&&o.splice(e,1),o.push("password_stdin"),o.push("PreferredAuthentications=password,keyboard-interactive"),o.push("PubkeyAuthentication=no"),o.push("NumberOfPasswordPrompts=1")}return e.extraOptions&&o.push(...e.extraOptions),i.push("-o",o.join(",")),i}e.s(["buildSshfsArgs",0,l,"isValidKeyPath",0,function(e){return!(!e||o.test(e)||e.includes(".."))&&(e.startsWith("/")||e.startsWith("~/"))},"parseSshTarget",0,function(e){let t;if(!e||o.test(e))return null;let r=e.trim(),s=r.indexOf(":");if(s<=0)return null;let a=r.slice(0,s),i=r.slice(s+1);if(!i.startsWith("/")||i.includes(".."))return null;let n=a,l=a.indexOf("@");return l>=0&&(t=a.slice(0,l),n=a.slice(l+1),!t)?null:n&&/^[a-zA-Z0-9.\-]+$/.test(n)&&(!t||/^[a-zA-Z0-9._\-]+$/.test(t))?{user:t,host:n,remotePath:i}:null}],296555);let u=(0,s.promisify)(r.execFile);function c(){return i.default.join(n.default.homedir(),".wiki-viewer","mounts")}async function d(){if(!0!==t)try{await u("sshfs",["--version"]),t=!0}catch{throw Error("sshfs binary not found. Install sshfs + FUSE (e.g. `apt install sshfs`, `brew install macfuse sshfs`) and ensure it is on PATH.")}}async function p(t){var r;let s=i.default.resolve(t),n=!1;try{n=(await (0,a.readFile)("/proc/mounts","utf8")).split("\n").some(e=>{let t=e.split(" ");return t[1]===s&&/fuse/.test(t[2]??"")})}catch{n=!1}return!!n&&(r=s,new Promise(t=>{let s=!1,a=setTimeout(()=>{s||(s=!0,t(!1))},4e3);e.A(687903).then(({readdir:e})=>e(r)).then(()=>{s||(s=!0,clearTimeout(a),t(!0))}).catch(()=>{s||(s=!0,clearTimeout(a),t(!1))})}))}async function h(e){await d(),await (0,a.mkdir)(e.mountpoint,{recursive:!0});let t=l(e);if(await new Promise((s,a)=>{let i=(0,r.spawn)("sshfs",t,{stdio:["pipe","ignore","pipe"]}),n="",o=setTimeout(()=>{i.kill("SIGKILL"),a(Error("sshfs mount timed out after 25s."))},25e3);i.stderr?.on("data",e=>{n+=e.toString()}),i.on("error",e=>{clearTimeout(o),a(e.message.includes("ENOENT")?Error("sshfs binary not found on PATH."):e)}),i.on("close",e=>{clearTimeout(o),0===e?s():a(Error(`sshfs exited ${e}: ${n.trim()||"mount failed"}`))}),"password"===e.authMethod&&i.stdin?.write((e.password??"")+"\n"),i.stdin?.end()}),!await p(e.mountpoint))throw Error("sshfs reported success but the mount is not live.")}async function f(e){let t=i.default.resolve(e);for(let[e,r]of[["fusermount",["-u","-z",t]],["umount",[t]]])try{await u(e,r);break}catch{}try{await (0,a.rmdir)(t)}catch{}}e.s(["assertSshfsAvailable",0,d,"isMounted",0,p,"mountSshfs",0,h,"mountpointFor",0,function(e){return i.default.join(c(),e)},"mountsDir",0,c,"unmountSshfs",0,f],256294)},536654,e=>{"use strict";var t=e.i(912714),r=e.i(750227);function s(e){return!!(r.default.isAbsolute(e)||".."===e||e.startsWith(".."+r.default.sep)||e.startsWith("../"))}async function a(e,i,n={}){let o;if(!e)return null;let l=function(e){if(e.includes("\0")||r.default.isAbsolute(e))return null;let t=e.replace(/\\/g,"/");return(("."===(t=r.default.posix.normalize(t))||"./"===t)&&(t=""),".."===t||t.startsWith("../")||/^[a-zA-Z]:\//.test(t)||t.startsWith("/"))?null:t}(i);if(null===l)return null;if(n.deniedSegments?.length){for(let e of l.split("/").filter(Boolean))if(n.deniedSegments.includes(e))return null}try{o=await (0,t.realpath)(e)}catch{return null}let u=l?r.default.join(o,l):o;try{let e=await (0,t.realpath)(u),a=r.default.relative(o,e);if(s(a))return null;return{relPath:l,absolutePath:e}}catch{if(!n.allowMissing)return null;let e=u;for(;;){let a=r.default.dirname(e);if(a===e)break;try{let e=await (0,t.realpath)(a),i=r.default.relative(o,e);if(s(i))return null;return{relPath:l,absolutePath:u}}catch{e=a}}return null}}e.s(["resolveWorkspacePath",0,a])},848475,e=>{"use strict";var t=e.i(750227);let r={".md":"text/markdown; charset=utf-8",".markdown":"text/markdown; charset=utf-8",".mdx":"text/markdown; charset=utf-8",".txt":"text/plain; charset=utf-8",".json":"application/json; charset=utf-8",".jsonc":"application/json; charset=utf-8",".ts":"text/typescript; charset=utf-8",".tsx":"text/typescript; charset=utf-8",".mts":"text/typescript; charset=utf-8",".js":"text/javascript; charset=utf-8",".jsx":"text/javascript; charset=utf-8",".mjs":"text/javascript; charset=utf-8",".html":"text/html; charset=utf-8",".htm":"text/html; charset=utf-8",".css":"text/css; charset=utf-8",".yaml":"text/yaml; charset=utf-8",".yml":"text/yaml; charset=utf-8",".toml":"text/toml; charset=utf-8",".xml":"application/xml; charset=utf-8",".svg":"image/svg+xml",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".avif":"image/avif",".ico":"image/x-icon",".bmp":"image/bmp",".pdf":"application/pdf",".zip":"application/zip",".tar":"application/x-tar",".gz":"application/gzip",".py":"text/x-python; charset=utf-8",".rs":"text/x-rustsrc; charset=utf-8",".go":"text/x-go; charset=utf-8",".sh":"text/x-shellscript; charset=utf-8",".csv":"text/csv; charset=utf-8",".tsv":"text/tab-separated-values; charset=utf-8",".env":"text/plain; charset=utf-8",".log":"text/plain; charset=utf-8",".ini":"text/plain; charset=utf-8",".conf":"text/plain; charset=utf-8",".mmd":"text/plain; charset=utf-8",".ipynb":"application/json; charset=utf-8",".docx":"application/vnd.openxmlformats-officedocument.wordprocessingml.document",".xlsx":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",".pptx":"application/vnd.openxmlformats-officedocument.presentationml.presentation",".doc":"application/msword",".xls":"application/vnd.ms-excel",".ppt":"application/vnd.ms-powerpoint",".mp4":"video/mp4",".webm":"video/webm",".mov":"video/quicktime",".m4v":"video/mp4",".mp3":"audio/mpeg",".wav":"audio/wav",".ogg":"audio/ogg",".m4a":"audio/mp4",".aac":"audio/aac"};e.s(["contentTypeForPath",0,function(e){return r[t.default.extname(e).toLowerCase()]??"application/octet-stream"}])},719126,e=>{"use strict";var t=e.i(666680),r=e.i(912714),s=e.i(750227),a=e.i(716234),i=e.i(536654),n=e.i(848475);async function o(e,t){if(!e)return null;let r=await (0,i.resolveWorkspacePath)(e,t,{allowMissing:!0,deniedSegments:a.DENIED_SEGMENTS});return r?.absolutePath??null}async function l(e,t){let s=420;try{let t=await (0,r.stat)(e);s=511&t.mode}catch{}let a=e+".~"+process.pid+"."+Date.now()+".tmp",i=await (0,r.open)(a,"w",s);try{await i.write(t),await i.datasync()}finally{await i.close()}await (0,r.rename)(a,e)}async function u(e,t){let a=s.default.dirname(e);if(t)return await (0,r.mkdir)(a,{recursive:!0}),!0;try{return await (0,r.stat)(a),!0}catch{return!1}}e.s(["atomicWrite",0,l,"ensureParentDir",0,u,"extractShaHex",0,function(e){return e.replace(/^"/,"").replace(/"$/,"").replace(/^sha256:/,"")},"isDeniedRelPath",0,function(e){let t=e.replace(/\\/g,"/");return a.DENIED_SEGMENTS.some(e=>t===e||t.startsWith(e+"/"))},"isMarkdown",0,function(e){return e.endsWith(".md")||e.endsWith(".markdown")},"looksLikeBinary",0,function(e){return e.slice(0,Math.min(e.length,8192)).includes(0)},"mimeByExt",0,function(e){return(0,n.contentTypeForPath)(e)},"safeAbsPath",0,o,"sha256ofBuf",0,function(e){return"sha256:"+(0,t.createHash)("sha256").update(e).digest("hex")}])},487018,e=>{"use strict";var t=e.x("node:sqlite",()=>require("node:sqlite"),!0);function r(e){return 1===e.length&&Array.isArray(e[0])?e[0]:e}class s{stmt;constructor(e){this.stmt=e}get reader(){return this.stmt.columns().length>0}all(...e){let t=r(e);return this.stmt.all(...t)}get(...e){let t=r(e);return this.stmt.get(...t)}run(...e){let t=r(e),s=this.stmt.run(...t);return{changes:Number(s.changes),lastInsertRowid:Number(s.lastInsertRowid)}}iterate(...e){let t=r(e);return this.stmt.iterate(...t)}}class a{db;constructor(e){this.db=new t.DatabaseSync(e),this.db.exec("PRAGMA busy_timeout = 5000"),this.db.exec("PRAGMA journal_mode = WAL")}prepare(e){return new s(this.db.prepare(e))}exec(e){this.db.exec(e)}close(){this.db.close()}pragma(e){this.db.exec(`PRAGMA ${e}`)}}e.s(["default",()=>a])},97082,e=>{"use strict";var t=e.i(487018),r=e.i(750227),s=e.i(660526),a=e.i(902157),i=e.i(666680);let n=null;function o(){var e;if(n)return n;let i=r.default.join(process.env.HOME??s.default.homedir(),".wiki-viewer");return(0,a.mkdirSync)(i,{recursive:!0}),(n=new t.default(r.default.join(i,"shared.db"))).pragma("journal_mode = WAL"),n.pragma("synchronous = NORMAL"),n.exec(`
2
2
  CREATE TABLE IF NOT EXISTS shared_docs (
3
3
  id TEXT PRIMARY KEY,
4
4
  workspace_id TEXT NOT NULL,
@@ -1,3 +1,3 @@
1
- module.exports=[583627,e=>{"use strict";var t=e.i(798003),r=e.i(254226);function s(){return(process.env.WIKI_ADMIN_EMAILS??"").split(",").map(e=>e.trim().toLowerCase()).filter(Boolean)}async function i(e,r){if(r){let e=s();if(e.length>0&&e.includes(r.toLowerCase()))return!0}return((await (0,t.readConfig)()).adminUserIds??[]).includes(e)}async function n(){return(await (0,t.readConfig)()).adminUserIds??[]}async function o(e){await (0,t.updateConfig)(t=>{let r=t.adminUserIds??[];return r.includes(e)?t:{...t,adminUserIds:[...r,e]}})}async function a(e){let r=s().length>0,i=!1;if(await (0,t.updateConfig)(t=>{let s=(t.adminUserIds??[]).filter(t=>t!==e);return 0!==s.length||r?{...t,adminUserIds:s}:(i=!0,t)}),i)throw Error("LAST_ADMIN: cannot remove the last admin with no WIKI_ADMIN_EMAILS configured")}async function u(e){if(s().length>0||r.SYNTHETIC_USER_IDS.has(e)||((await (0,t.readConfig)()).adminUserIds??[]).length>0)return;let i=!1;await (0,t.updateConfig)(t=>(t.adminUserIds??[]).length>0?t:(i=!0,{...t,adminUserIds:[e]})),i&&console.log(`[wiki-viewer] Bootstrap: first user ${e} promoted to admin`)}async function l(e){if("1"===process.env.WIKI_NO_AUTH)return{ok:!0,user:{id:"local",email:"local@localhost",name:"local"}};let t=await (0,r.requireUser)(e);return t.ok?await i(t.user.id,t.user.email)?{ok:!0,user:t.user}:{ok:!1,status:403,code:"ADMIN_REQUIRED"}:{ok:!1,status:401,code:"UNAUTHORIZED"}}e.s(["addAdmin",0,o,"ensureBootstrapAdmin",0,u,"isAdmin",0,i,"listAdmins",0,n,"removeAdmin",0,a,"requireAdmin",0,l])},874533,(e,t,r)=>{t.exports=e.x("node:child_process",()=>require("node:child_process"))},812057,(e,t,r)=>{t.exports=e.x("node:util",()=>require("node:util"))},256294,296555,e=>{"use strict";let t;var r=e.i(874533),s=e.i(812057),i=e.i(912714),n=e.i(750227),o=e.i(660526);e.i(902157);let a=RegExp("[;|&$`<>(){}\\n\\r\\0]");function u(e){let{target:t,mountpoint:r,port:s}=e,i=t.user?`${t.user}@`:"",n=[`${i}${t.host}:${t.remotePath}`,r];s&&Number.isInteger(Number(s))&&Number(s)>0&&65536>Number(s)&&n.push("-p",String(s));let o=e.authMethod??"agent";!e.authMethod&&(null!=e.password?o="password":e.keyPath&&(o="keyfile"));let a=["reconnect","ServerAliveInterval=15","ServerAliveCountMax=3","compression=yes","cache=yes","kernel_cache","StrictHostKeyChecking=accept-new","BatchMode=yes"];if(e.readOnly&&a.push("ro"),"keyfile"===o&&e.keyPath&&(a.push(`IdentityFile=${e.keyPath}`),a.push("IdentitiesOnly=yes")),"password"===o){let e=a.indexOf("BatchMode=yes");e>=0&&a.splice(e,1),a.push("password_stdin"),a.push("PreferredAuthentications=password,keyboard-interactive"),a.push("PubkeyAuthentication=no"),a.push("NumberOfPasswordPrompts=1")}return e.extraOptions&&a.push(...e.extraOptions),n.push("-o",a.join(",")),n}e.s(["buildSshfsArgs",0,u,"isValidKeyPath",0,function(e){return!(!e||a.test(e)||e.includes(".."))&&(e.startsWith("/")||e.startsWith("~/"))},"parseSshTarget",0,function(e){let t;if(!e||a.test(e))return null;let r=e.trim(),s=r.indexOf(":");if(s<=0)return null;let i=r.slice(0,s),n=r.slice(s+1);if(!n.startsWith("/")||n.includes(".."))return null;let o=i,u=i.indexOf("@");return u>=0&&(t=i.slice(0,u),o=i.slice(u+1),!t)?null:o&&/^[a-zA-Z0-9.\-]+$/.test(o)&&(!t||/^[a-zA-Z0-9._\-]+$/.test(t))?{user:t,host:o,remotePath:n}:null}],296555);let l=(0,s.promisify)(r.execFile);function c(){return n.default.join(o.default.homedir(),".wiki-viewer","mounts")}async function d(){if(!0!==t)try{await l("sshfs",["--version"]),t=!0}catch{throw Error("sshfs binary not found. Install sshfs + FUSE (e.g. `apt install sshfs`, `brew install macfuse sshfs`) and ensure it is on PATH.")}}async function f(t){var r;let s=n.default.resolve(t),o=!1;try{o=(await (0,i.readFile)("/proc/mounts","utf8")).split("\n").some(e=>{let t=e.split(" ");return t[1]===s&&/fuse/.test(t[2]??"")})}catch{o=!1}return!!o&&(r=s,new Promise(t=>{let s=!1,i=setTimeout(()=>{s||(s=!0,t(!1))},4e3);e.A(687903).then(({readdir:e})=>e(r)).then(()=>{s||(s=!0,clearTimeout(i),t(!0))}).catch(()=>{s||(s=!0,clearTimeout(i),t(!1))})}))}async function h(e){await d(),await (0,i.mkdir)(e.mountpoint,{recursive:!0});let t=u(e);if(await new Promise((s,i)=>{let n=(0,r.spawn)("sshfs",t,{stdio:["pipe","ignore","pipe"]}),o="",a=setTimeout(()=>{n.kill("SIGKILL"),i(Error("sshfs mount timed out after 25s."))},25e3);n.stderr?.on("data",e=>{o+=e.toString()}),n.on("error",e=>{clearTimeout(a),i(e.message.includes("ENOENT")?Error("sshfs binary not found on PATH."):e)}),n.on("close",e=>{clearTimeout(a),0===e?s():i(Error(`sshfs exited ${e}: ${o.trim()||"mount failed"}`))}),"password"===e.authMethod&&n.stdin?.write((e.password??"")+"\n"),n.stdin?.end()}),!await f(e.mountpoint))throw Error("sshfs reported success but the mount is not live.")}async function m(e){let t=n.default.resolve(e);for(let[e,r]of[["fusermount",["-u","-z",t]],["umount",[t]]])try{await l(e,r);break}catch{}try{await (0,i.rmdir)(t)}catch{}}e.s(["assertSshfsAvailable",0,d,"isMounted",0,f,"mountSshfs",0,h,"mountpointFor",0,function(e){return n.default.join(c(),e)},"mountsDir",0,c,"unmountSshfs",0,m],256294)},499465,e=>{"use strict";var t=e.i(750227),r=e.i(660526),s=e.i(902157),i=e.i(666680);let n=t.default.join(process.env.HOME??r.default.homedir(),".wiki-viewer"),o=t.default.join(n,"api-key");function a(){return(0,s.existsSync)(o)?(0,s.readFileSync)(o,"utf-8").trim():""}e.s(["ensureApiKey",0,function(){if((0,s.mkdirSync)(n,{recursive:!0}),!(0,s.existsSync)(o)){let e=(0,i.randomBytes)(32).toString("hex");(0,s.writeFileSync)(o,e,{mode:384});try{(0,s.chmodSync)(o,384)}catch{}return e}return(0,s.readFileSync)(o,"utf-8").trim()},"getApiKey",0,a,"isApiKeyRequest",0,function(e){return(function(e){let t=[],r=e.headers.get("authorization")??"";if(r.startsWith("Bearer ")){let e=r.slice(7).trim();e&&t.push(e)}return t})(e).some(e=>(function(e){let t=a();if(!t||!e||t.length!==e.length)return!1;try{return(0,i.timingSafeEqual)(Buffer.from(t,"utf-8"),Buffer.from(e,"utf-8"))}catch{return!1}})(e))},"rotateApiKey",0,function(){(0,s.mkdirSync)(n,{recursive:!0});let e=(0,i.randomBytes)(32).toString("hex");(0,s.writeFileSync)(o,e,{mode:384});try{(0,s.chmodSync)(o,384)}catch{}return e}])},660038,e=>{"use strict";var t=e.i(750227),r=e.i(666680),s=e.i(902157),i=e.i(254226),n=e.i(499465),o=e.i(583627),a=e.i(359211);async function u(e,i){var o;let a;if(!("1"===process.env.WIKI_NO_AUTH||(0,n.isApiKeyRequest)(e)))return{ok:!1,status:400,code:"root_requires_api_key"};let u=function(e){let r,i=t.default.resolve(e);try{r=(0,s.statSync)(i)}catch{return{ok:!1,code:"root_not_found"}}return r.isDirectory()?{ok:!0,rootDir:i}:{ok:!1,code:"root_not_a_directory"}}(i);return u.ok?{ok:!0,ws:(o=u.rootDir,a=(0,r.createHash)("sha256").update(o).digest("hex").slice(0,12),{id:`ws_eph_${a}`,name:t.default.basename(o)||"workspace",rootDir:o,createdAt:new Date(0).toISOString(),ephemeral:!0})}:{ok:!1,status:400,code:u.code}}async function l(e){let t,r=new URL(e.url);if("1"===process.env.WIKI_LITE){let t=r.searchParams.get("root");return t?u(e,t):{ok:!1,status:400,code:"root_required"}}await (0,a.migrateConfigToWorkspaces)();let s=r.searchParams.get("root");if(s)return u(e,s);let i=r.searchParams.get("ws")??e.headers.get("x-workspace")??null;if(i)t=await (0,a.getWorkspace)(i)??null;else{let e=await (0,a.listWorkspaces)();if(0===e.length)return{ok:!1,status:400,code:"WORKSPACE_REQUIRED"};t=e.slice().sort((e,t)=>{let r=e.lastOpenedAt?new Date(e.lastOpenedAt).getTime():0,s=t.lastOpenedAt?new Date(t.lastOpenedAt).getTime():0;return s!==r?s-r:e.id<t.id?-1:+(e.id>t.id)})[0]}return t?(t.ssh&&await (0,a.ensureWorkspaceMounted)(t),{ok:!0,ws:t}):{ok:!1,status:i?404:400,code:i?"WORKSPACE_NOT_FOUND":"WORKSPACE_REQUIRED"}}async function c(e,t="read"){if("1"===process.env.WIKI_NO_AUTH){let r=await l(e);if(!r.ok)return r;let{ws:s}=r;return"write"===t&&s.readOnly?{ok:!1,status:403,code:"WORKSPACE_READ_ONLY"}:{ok:!0,ws:s,rootDir:s.rootDir,userId:"local",isAdmin:!0}}let r=await (0,i.requireUser)(e);if(!r.ok)return{ok:!1,status:401,code:"UNAUTHORIZED"};let s=await (0,o.isAdmin)(r.user.id,r.user.email),n=await l(e);if(!n.ok)return n;let{ws:u}=n;return u.ephemeral||(0,a.userCanAccess)(u,r.user.id,s)?"write"===t&&u.readOnly?{ok:!1,status:403,code:"WORKSPACE_READ_ONLY"}:{ok:!0,ws:u,rootDir:u.rootDir,userId:r.user.id,isAdmin:s}:{ok:!1,status:403,code:"WORKSPACE_FORBIDDEN"}}async function d(e,t="read"){let r=await l(e);if(!r.ok)return r;let{ws:s}=r;return"write"===t&&s.readOnly?{ok:!1,status:403,code:"WORKSPACE_READ_ONLY"}:{ok:!0,ws:s,rootDir:s.rootDir}}e.s(["resolveWorkspaceForAgent",0,d,"resolveWorkspaceForUser",0,c],660038)}];
1
+ module.exports=[583627,e=>{"use strict";var t=e.i(798003),r=e.i(254226);function s(){return(process.env.WIKI_ADMIN_EMAILS??"").split(",").map(e=>e.trim().toLowerCase()).filter(Boolean)}async function i(e,r){if(r){let e=s();if(e.length>0&&e.includes(r.toLowerCase()))return!0}return((await (0,t.readConfig)()).adminUserIds??[]).includes(e)}async function n(){return(await (0,t.readConfig)()).adminUserIds??[]}async function o(e){await (0,t.updateConfig)(t=>{let r=t.adminUserIds??[];return r.includes(e)?t:{...t,adminUserIds:[...r,e]}})}async function a(e){let r=s().length>0,i=!1;if(await (0,t.updateConfig)(t=>{let s=(t.adminUserIds??[]).filter(t=>t!==e);return 0!==s.length||r?{...t,adminUserIds:s}:(i=!0,t)}),i)throw Error("LAST_ADMIN: cannot remove the last admin with no WIKI_ADMIN_EMAILS configured")}async function u(e){if(s().length>0||r.SYNTHETIC_USER_IDS.has(e)||((await (0,t.readConfig)()).adminUserIds??[]).length>0)return;let i=!1;await (0,t.updateConfig)(t=>(t.adminUserIds??[]).length>0?t:(i=!0,{...t,adminUserIds:[e]})),i&&console.log(`[wiki-viewer] Bootstrap: first user ${e} promoted to admin`)}async function l(e){if("1"===process.env.WIKI_NO_AUTH)return{ok:!0,user:{id:"local",email:"local@localhost",name:"local"}};let t=await (0,r.requireUser)(e);return t.ok?await i(t.user.id,t.user.email)?{ok:!0,user:t.user}:{ok:!1,status:403,code:"ADMIN_REQUIRED"}:{ok:!1,status:401,code:"UNAUTHORIZED"}}e.s(["addAdmin",0,o,"ensureBootstrapAdmin",0,u,"isAdmin",0,i,"listAdmins",0,n,"removeAdmin",0,a,"requireAdmin",0,l])},874533,(e,t,r)=>{t.exports=e.x("node:child_process",()=>require("node:child_process"))},812057,(e,t,r)=>{t.exports=e.x("node:util",()=>require("node:util"))},256294,296555,e=>{"use strict";let t;var r=e.i(874533),s=e.i(812057),i=e.i(912714),n=e.i(750227),o=e.i(660526);e.i(902157);let a=RegExp("[;|&$`<>(){}\\n\\r\\0]");function u(e){let{target:t,mountpoint:r,port:s}=e,i=t.user?`${t.user}@`:"",n=[`${i}${t.host}:${t.remotePath}`,r];s&&Number.isInteger(Number(s))&&Number(s)>0&&65536>Number(s)&&n.push("-p",String(s));let o=e.authMethod??"agent";!e.authMethod&&(null!=e.password?o="password":e.keyPath&&(o="keyfile"));let a=["reconnect","ServerAliveInterval=15","ServerAliveCountMax=3","compression=yes","cache=yes","StrictHostKeyChecking=accept-new","BatchMode=yes"];if(e.readOnly&&a.push("ro"),"keyfile"===o&&e.keyPath&&(a.push(`IdentityFile=${e.keyPath}`),a.push("IdentitiesOnly=yes")),"password"===o){let e=a.indexOf("BatchMode=yes");e>=0&&a.splice(e,1),a.push("password_stdin"),a.push("PreferredAuthentications=password,keyboard-interactive"),a.push("PubkeyAuthentication=no"),a.push("NumberOfPasswordPrompts=1")}return e.extraOptions&&a.push(...e.extraOptions),n.push("-o",a.join(",")),n}e.s(["buildSshfsArgs",0,u,"isValidKeyPath",0,function(e){return!(!e||a.test(e)||e.includes(".."))&&(e.startsWith("/")||e.startsWith("~/"))},"parseSshTarget",0,function(e){let t;if(!e||a.test(e))return null;let r=e.trim(),s=r.indexOf(":");if(s<=0)return null;let i=r.slice(0,s),n=r.slice(s+1);if(!n.startsWith("/")||n.includes(".."))return null;let o=i,u=i.indexOf("@");return u>=0&&(t=i.slice(0,u),o=i.slice(u+1),!t)?null:o&&/^[a-zA-Z0-9.\-]+$/.test(o)&&(!t||/^[a-zA-Z0-9._\-]+$/.test(t))?{user:t,host:o,remotePath:n}:null}],296555);let l=(0,s.promisify)(r.execFile);function c(){return n.default.join(o.default.homedir(),".wiki-viewer","mounts")}async function d(){if(!0!==t)try{await l("sshfs",["--version"]),t=!0}catch{throw Error("sshfs binary not found. Install sshfs + FUSE (e.g. `apt install sshfs`, `brew install macfuse sshfs`) and ensure it is on PATH.")}}async function f(t){var r;let s=n.default.resolve(t),o=!1;try{o=(await (0,i.readFile)("/proc/mounts","utf8")).split("\n").some(e=>{let t=e.split(" ");return t[1]===s&&/fuse/.test(t[2]??"")})}catch{o=!1}return!!o&&(r=s,new Promise(t=>{let s=!1,i=setTimeout(()=>{s||(s=!0,t(!1))},4e3);e.A(687903).then(({readdir:e})=>e(r)).then(()=>{s||(s=!0,clearTimeout(i),t(!0))}).catch(()=>{s||(s=!0,clearTimeout(i),t(!1))})}))}async function h(e){await d(),await (0,i.mkdir)(e.mountpoint,{recursive:!0});let t=u(e);if(await new Promise((s,i)=>{let n=(0,r.spawn)("sshfs",t,{stdio:["pipe","ignore","pipe"]}),o="",a=setTimeout(()=>{n.kill("SIGKILL"),i(Error("sshfs mount timed out after 25s."))},25e3);n.stderr?.on("data",e=>{o+=e.toString()}),n.on("error",e=>{clearTimeout(a),i(e.message.includes("ENOENT")?Error("sshfs binary not found on PATH."):e)}),n.on("close",e=>{clearTimeout(a),0===e?s():i(Error(`sshfs exited ${e}: ${o.trim()||"mount failed"}`))}),"password"===e.authMethod&&n.stdin?.write((e.password??"")+"\n"),n.stdin?.end()}),!await f(e.mountpoint))throw Error("sshfs reported success but the mount is not live.")}async function m(e){let t=n.default.resolve(e);for(let[e,r]of[["fusermount",["-u","-z",t]],["umount",[t]]])try{await l(e,r);break}catch{}try{await (0,i.rmdir)(t)}catch{}}e.s(["assertSshfsAvailable",0,d,"isMounted",0,f,"mountSshfs",0,h,"mountpointFor",0,function(e){return n.default.join(c(),e)},"mountsDir",0,c,"unmountSshfs",0,m],256294)},499465,e=>{"use strict";var t=e.i(750227),r=e.i(660526),s=e.i(902157),i=e.i(666680);let n=t.default.join(process.env.HOME??r.default.homedir(),".wiki-viewer"),o=t.default.join(n,"api-key");function a(){return(0,s.existsSync)(o)?(0,s.readFileSync)(o,"utf-8").trim():""}e.s(["ensureApiKey",0,function(){if((0,s.mkdirSync)(n,{recursive:!0}),!(0,s.existsSync)(o)){let e=(0,i.randomBytes)(32).toString("hex");(0,s.writeFileSync)(o,e,{mode:384});try{(0,s.chmodSync)(o,384)}catch{}return e}return(0,s.readFileSync)(o,"utf-8").trim()},"getApiKey",0,a,"isApiKeyRequest",0,function(e){return(function(e){let t=[],r=e.headers.get("authorization")??"";if(r.startsWith("Bearer ")){let e=r.slice(7).trim();e&&t.push(e)}return t})(e).some(e=>(function(e){let t=a();if(!t||!e||t.length!==e.length)return!1;try{return(0,i.timingSafeEqual)(Buffer.from(t,"utf-8"),Buffer.from(e,"utf-8"))}catch{return!1}})(e))},"rotateApiKey",0,function(){(0,s.mkdirSync)(n,{recursive:!0});let e=(0,i.randomBytes)(32).toString("hex");(0,s.writeFileSync)(o,e,{mode:384});try{(0,s.chmodSync)(o,384)}catch{}return e}])},660038,e=>{"use strict";var t=e.i(750227),r=e.i(666680),s=e.i(902157),i=e.i(254226),n=e.i(499465),o=e.i(583627),a=e.i(359211);async function u(e,i){var o;let a;if(!("1"===process.env.WIKI_NO_AUTH||(0,n.isApiKeyRequest)(e)))return{ok:!1,status:400,code:"root_requires_api_key"};let u=function(e){let r,i=t.default.resolve(e);try{r=(0,s.statSync)(i)}catch{return{ok:!1,code:"root_not_found"}}return r.isDirectory()?{ok:!0,rootDir:i}:{ok:!1,code:"root_not_a_directory"}}(i);return u.ok?{ok:!0,ws:(o=u.rootDir,a=(0,r.createHash)("sha256").update(o).digest("hex").slice(0,12),{id:`ws_eph_${a}`,name:t.default.basename(o)||"workspace",rootDir:o,createdAt:new Date(0).toISOString(),ephemeral:!0})}:{ok:!1,status:400,code:u.code}}async function l(e){let t,r=new URL(e.url);if("1"===process.env.WIKI_LITE){let t=r.searchParams.get("root");return t?u(e,t):{ok:!1,status:400,code:"root_required"}}await (0,a.migrateConfigToWorkspaces)();let s=r.searchParams.get("root");if(s)return u(e,s);let i=r.searchParams.get("ws")??e.headers.get("x-workspace")??null;if(i)t=await (0,a.getWorkspace)(i)??null;else{let e=await (0,a.listWorkspaces)();if(0===e.length)return{ok:!1,status:400,code:"WORKSPACE_REQUIRED"};t=e.slice().sort((e,t)=>{let r=e.lastOpenedAt?new Date(e.lastOpenedAt).getTime():0,s=t.lastOpenedAt?new Date(t.lastOpenedAt).getTime():0;return s!==r?s-r:e.id<t.id?-1:+(e.id>t.id)})[0]}return t?(t.ssh&&await (0,a.ensureWorkspaceMounted)(t),{ok:!0,ws:t}):{ok:!1,status:i?404:400,code:i?"WORKSPACE_NOT_FOUND":"WORKSPACE_REQUIRED"}}async function c(e,t="read"){if("1"===process.env.WIKI_NO_AUTH){let r=await l(e);if(!r.ok)return r;let{ws:s}=r;return"write"===t&&s.readOnly?{ok:!1,status:403,code:"WORKSPACE_READ_ONLY"}:{ok:!0,ws:s,rootDir:s.rootDir,userId:"local",isAdmin:!0}}let r=await (0,i.requireUser)(e);if(!r.ok)return{ok:!1,status:401,code:"UNAUTHORIZED"};let s=await (0,o.isAdmin)(r.user.id,r.user.email),n=await l(e);if(!n.ok)return n;let{ws:u}=n;return u.ephemeral||(0,a.userCanAccess)(u,r.user.id,s)?"write"===t&&u.readOnly?{ok:!1,status:403,code:"WORKSPACE_READ_ONLY"}:{ok:!0,ws:u,rootDir:u.rootDir,userId:r.user.id,isAdmin:s}:{ok:!1,status:403,code:"WORKSPACE_FORBIDDEN"}}async function d(e,t="read"){let r=await l(e);if(!r.ok)return r;let{ws:s}=r;return"write"===t&&s.readOnly?{ok:!1,status:403,code:"WORKSPACE_READ_ONLY"}:{ok:!0,ws:s,rootDir:s.rootDir}}e.s(["resolveWorkspaceForAgent",0,d,"resolveWorkspaceForUser",0,c],660038)}];
2
2
 
3
3
  //# sourceMappingURL=%5Broot-of-the-server%5D__12g8s_j._.js.map