import{h as b}from"./httpComponent-AiGk8DOD.js";import{F as m,f as w,a as y,D as _}from"./manifest--hA2W8VB.js";var T=new Uint8Array([255,216,255,224,0,16,74,70,73,70,0,1,1,1,0,72,0,72,0,0,255,219,0,67,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,194,0,11,8,0,1,0,1,1,1,17,0,255,196,0,20,16,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,218,0,8,1,1,0,1,63,16]),F=`%PDF-1.1
%¥±ë

1 0 obj
  << /Type /Catalog
     /Pages 2 0 R
  >>
endobj

2 0 obj
  << /Type /Pages
     /Kids [3 0 R]
     /Count 1
     /MediaBox [0 0 300 144]
  >>
endobj

3 0 obj
  <<  /Type /Page
      /Parent 2 0 R
      /Resources
       << /Font
           << /F1
               << /Type /Font
                  /Subtype /Type1
                  /BaseFont /Times-Roman
               >>
           >>
       >>
      /Contents 4 0 R
  >>
endobj

4 0 obj
  << /Length 55 >>
stream
  BT
    /F1 18 Tf
    0 0 Td
    (Hello World) Tj
  ET
endstream
endobj

xref
0 5
0000000000 65535 f 
0000000018 00000 n 
0000000077 00000 n 
0000000178 00000 n 
0000000457 00000 n 
trailer
  <<  /Root 1 0 R
      /Size 5
  >>
startxref
565
%%EOF
`,N=new Uint8Array([78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,0,1,0,0,0,1,1,0,0,0,0,55,110,249,36,0,0,0,16,73,68,65,84,120,156,98,96,1,0,0,0,255,255,3,0,0,6,0,5,87,191,171,212,0,0,0,0,73,69,78,68,174,66,96,130]);const h=new Map,O=(t,e,a)=>{t.set(e,a)},v={[m.JPG]:{init:{headers:{"Content-Type":"image/jpg"}},body:T},[m.PDF]:{init:{headers:{"Content-Type":"application/pdf"}},body:window.btoa(F)},[m.PNG]:{init:{headers:{"Content-Type":"image/png"}},body:N},[m.TXT]:{init:{headers:{"Content-Type":"text/plain"}},body:"This is a text file"}},R=t=>{const e={useOriginalName:0,download:0,downloadWithOriginalName:0},a=t.get("useOriginalName");a!==null&&(e.useOriginalName=Number.parseInt(a)&&1);const i=t.get("download");i!==null&&(e.download=Number.parseInt(i)&&1);const o=t.get("downloadWithOriginalName");return o!==null&&(e.downloadWithOriginalName=Number.parseInt(o)&&1),e},x=async t=>{var e;const{pathname:a,searchParams:i}=t,o=a.match(new RegExp("\\/(?<id>[^/]+)\\.(?<ext>[^.]+)$"));if(o===null||o.groups===void 0||!("id"in o.groups)||!("ext"in o.groups))return new Response("Bad Request",{status:400});const{groups:{id:c}}=o,s=Object.entries(w).find(([,n])=>n===c),{useOriginalName:r,download:d,downloadWithOriginalName:p}=R(i),f=(n,l,g=l)=>{const u={};return r?u["Content-Disposition"]='inline; filename="'.concat(g,".").concat(n,'"'):p?u["Content-Disposition"]='attachment; filename="'.concat(g,".").concat(n,'"'):d&&(u["Content-Disposition"]='attachment; filename="'.concat(l,".").concat(n,'"')),u};if(s){const[n]=s,l=v[n];return new Response(l.body,{...l.init,headers:{...(e=l.init)==null?void 0:e.headers,...f(n,c,_)}})}else{const n=h.get(c);return n?new Response(n):new Response("Not Found",{status:404})}},j=async(t,{body:e}={})=>{const{pathname:a}=t;if(!(e&&e instanceof FormData))return new Response("Bad Request",{status:400});const i=e.get("file"),{name:o,size:c}=i,s=y(),r=o.match(new RegExp("\\.(?<ext>[^.]+)$"));let d;r!==null&&r.groups&&"ext"in r.groups&&(d=r.groups.ext);const p="".concat(s).concat(d?".".concat(d):""),f={name:o,size:c,_id:s,file:p,location:"".concat(a.replace(/\/$/,""),"/download/").concat(p)},n=await i.text();return O(h,s,n),new Response(JSON.stringify(f),{status:200,headers:{"Content-Type":"application/json"}})},C={docLink:"https://docs.mia-platform.eu/docs/microfrontend-composer/back-kit/components/file_service_client",description:{en:"Client for Mia-Platform File Service",it:"Client per il servizio File Service di Mia-Platform"},label:"File Service Client",mocks:{fetch:t=>{var e,a;const i=(a=(e=t.basePath)==null?void 0:e.replace(/\/$/,""))!=null?a:"";return[{handler:x,method:"GET",url:{pathname:"".concat(i,"/download/")}},{handler:j,method:"POST",url:{pathname:"".concat(i,"/")}}]}},properties:{...b,basePath:{__mia_configuration:{attribute:!1,priority:"high",description:"The URL base path used to reach the File Service",label:"File Service base path"},type:"string"},queryParams:{type:"object",__mia_configuration:{description:"Optional query params to enforce the service behavior",label:"Optional query parameters",attribute:!1},default:{download:1,downloadWithOriginalName:1,useOriginalName:1},properties:{download:{type:"number",default:1,__mia_configuration:{"schema-hint":"on-off-toggle",label:"Download",description:"Download the file as an attachment"}},downloadWithOriginalName:{type:"number",default:1,__mia_configuration:{"schema-hint":"on-off-toggle",label:"Download with file original name",description:"Download the file with its original name as attachment"}},useOriginalName:{type:"number",default:1,__mia_configuration:{"schema-hint":"on-off-toggle",label:"Use file original name",description:"Download the file with its original name"}}}}},type:"connector"};var S=C;export{S as default};
