import l from"node:path";import{readFile as u,existsSync as d}from"node:fs";import{promisify as h}from"node:util";import{PUBLIC_API_DEFINITIONS_FOLDER as A}from"../../constants/common.js";import{GRAPHQL_SPEC_SLUG as R}from"../../../constants/common";import{canDownloadApiDefinition as w}from"../../utils/rbac.js";const F=h(u);async function D(s,e,r){const{isAuthenticated:n,teams:i,claims:{email:a}}=e.user,o=new URL(s.url),c=decodeURIComponent(o.pathname.replace(R,"")),{rbac:p={},requiresLogin:m=!1}=e.config;if(!w(o.pathname,p,m,{isAuthenticated:n,email:a,teams:i}))return new Response("Unauthorized",{status:n?403:401});const t=l.join(r.props?.outdir??"",A,c);if(!d(t))return new Response("Not found",{status:404});const f=await F(t,"utf-8");return new Response(f,{headers:{"Content-Type":"application/graphql"}})}export{D as default};
