// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0-or-later
// @source: https://gitlab.com/soapbox-pub/ditto/-/tree/f0a3877c
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/esm-eUNZ_BYQ.js","assets/preload-helper-CZgWQFsJ.js","assets/dist-DQ_zK-Nr.js","assets/dittoDownloader-CZ0ISYxD.js","assets/esm-CYQFKuSX.js"])))=>i.map(i=>d[i]);
import{t as e}from"./preload-helper-CZgWQFsJ.js";import{t}from"./dist-DQ_zK-Nr.js";import{i as n}from"./encryptedFile-DKFYUsvG.js";async function r(n,r){if(t.isNativePlatform()){let{Filesystem:t,Directory:i,Encoding:a}=await e(async()=>{let{Filesystem:e,Directory:t,Encoding:n}=await import(`./esm-eUNZ_BYQ.js`);return{Filesystem:e,Directory:t,Encoding:n}},__vite__mapDeps([0,1,2]));await t.writeFile({path:n,data:r,directory:i.Documents,encoding:a.UTF8})}else{let e=new Blob([r],{type:`text/plain; charset=utf-8`}),t=globalThis.URL.createObjectURL(e),i=document.createElement(`a`);i.href=t,i.download=n,i.style.display=`none`,document.body.appendChild(i),i.click(),globalThis.URL.revokeObjectURL(t),document.body.removeChild(i)}}function i(e){let t=``,n=32768;for(let r=0;r<e.length;r+=n)t+=String.fromCharCode(...e.subarray(r,r+n));return btoa(t)}async function a(n,r){if(t.isNativePlatform()){let{Filesystem:t,Directory:a}=await e(async()=>{let{Filesystem:e,Directory:t}=await import(`./esm-eUNZ_BYQ.js`);return{Filesystem:e,Directory:t}},__vite__mapDeps([0,1,2]));await t.writeFile({path:n,data:i(r),directory:a.Documents})}else{let e=new Blob([r],{type:`application/octet-stream`}),t=globalThis.URL.createObjectURL(e),i=document.createElement(`a`);i.href=t,i.download=n,i.style.display=`none`,document.body.appendChild(i),i.click(),globalThis.URL.revokeObjectURL(t),document.body.removeChild(i)}}var o={"image/png":`png`,"image/jpeg":`jpg`,"image/gif":`gif`,"image/webp":`webp`,"image/svg+xml":`svg`,"video/mp4":`mp4`,"video/webm":`webm`,"audio/mpeg":`mp3`,"audio/ogg":`ogg`,"audio/wav":`wav`,"application/pdf":`pdf`};async function s(e,t,r){let{bytes:i,mime:s}=await n(e,t),l=r??c(e),u=o[s];return await a(u&&!l.includes(`.`)?`${l}.${u}`:l,i),`downloaded`}function c(e){try{let{pathname:t}=new URL(e),n=t.split(`/`).filter(Boolean).pop();if(n)return decodeURIComponent(n)}catch{}return`download`}async function l(n,r){let i=r??c(n);if(t.getPlatform()===`android`)try{let{DittoDownloader:t}=await e(async()=>{let{DittoDownloader:e}=await import(`./dittoDownloader-CZ0ISYxD.js`);return{DittoDownloader:e}},__vite__mapDeps([3,2]));return await t.download({url:n,filename:i}),`downloaded`}catch{return await u(n),`opened`}if(t.isNativePlatform())try{let{Filesystem:t,Directory:r}=await e(async()=>{let{Filesystem:e,Directory:t}=await import(`./esm-eUNZ_BYQ.js`);return{Filesystem:e,Directory:t}},__vite__mapDeps([0,1,2]));return await t.downloadFile({url:n,path:i,directory:r.Documents}),`downloaded`}catch{return await u(n),`opened`}try{let e=await fetch(n);if(!e.ok)throw Error(`Failed to fetch ${n}: ${e.status}`);return await a(i,new Uint8Array(await e.arrayBuffer())),`downloaded`}catch{return await u(n),`opened`}}async function u(n){if(t.isNativePlatform()){let{AppLauncher:t}=await e(async()=>{let{AppLauncher:e}=await import(`./esm-CYQFKuSX.js`);return{AppLauncher:e}},__vite__mapDeps([4,1,2]));await t.openUrl({url:n})}else/^https?:/i.test(n)?window.open(n,`_blank`,`noopener,noreferrer`):window.location.href=n}export{u as a,l as i,s as n,r,a as t};
// @license-end
