mirror of
https://github.com/antos-rde/antosdk-apps.git
synced 2024-11-09 15:08:27 +01:00
3 lines
12 KiB
JavaScript
3 lines
12 KiB
JavaScript
|
const e=(()=>{if("undefined"==typeof self)return!1;if("top"in self&&self!==top)try{top}catch(e){return!1}else if("showOpenFilePicker"in self)return"showOpenFilePicker";return!1})(),r=e?Promise.resolve().then((function(){return c})):Promise.resolve().then((function(){return v}));e?Promise.resolve().then((function(){return d})):Promise.resolve().then((function(){return f}));const l=e?Promise.resolve().then((function(){return m})):Promise.resolve().then((function(){return g}));async function o(){return(await l).default(...arguments)}const s=async e=>{const r=await e.getFile();return r.handle=e,r};var c={__proto__:null,default:async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[{}];Array.isArray(e)||(e=[e]);const r=[];e.forEach(((e,l)=>{r[l]={description:e.description||"Files",accept:{}},e.mimeTypes?e.mimeTypes.map((c=>{r[l].accept[c]=e.extensions||[]})):r[l].accept["*/*"]=e.extensions||[]}));const l=await window.showOpenFilePicker({id:e[0].id,startIn:e[0].startIn,types:r,multiple:e[0].multiple||!1,excludeAcceptAllOption:e[0].excludeAcceptAllOption||!1}),c=await Promise.all(l.map(s));return e[0].multiple?c:c[0]}};function u(e){function t(e){if(Object(e)!==e)return Promise.reject(new TypeError(e+" is not an object."));var r=e.done;return Promise.resolve(e.value).then((function(e){return{value:e,done:r}}))}return u=function(e){this.s=e,this.n=e.next},u.prototype={s:null,n:null,next:function(){return t(this.n.apply(this.s,arguments))},return:function(e){var r=this.s.return;return void 0===r?Promise.resolve({value:e,done:!0}):t(r.apply(this.s,arguments))},throw:function(e){var r=this.s.return;return void 0===r?Promise.reject(e):t(r.apply(this.s,arguments))}},new u(e)}const p=async function(e,r){let l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.name,c=arguments.length>3?arguments[3]:void 0;const d=[],m=[];var v,f=!1,g=!1;try{for(var y,h=function(e){var r,l,c,d=2;for("undefined"!=typeof Symbol&&(l=Symbol.asyncIterator,c=Symbol.iterator);d--;){if(l&&null!=(r=e[l]))return r.call(e);if(c&&null!=(r=e[c]))return new u(r.call(e));l="@@asyncIterator",c="@@iterator"}throw new TypeError("Object is not async iterable")}(e.values());f=!(y=await h.next()).done;f=!1){const v=y.value,f="".concat(l,"/").concat(v.name);"file"===v.kind?m.push(v.getFile().then((r=>(r.directoryHandle=e,r.handle=v,Object.defineProperty(r,"webkitRelativePath",{configurable:!0,enumerable:!0,get:()=>f}))))):"directory"!==v.kind||!r||c&&c(v)||d.push(p(v,r,f,c))}}catch(e){g=!0,v=e}finally{try{f&&null!=h.return&&await h.return()}finally{if(g)throw v}}return[...(await Promise.all(d)).flat(),...await Promise.all(m)]};var d={__proto__:null,default:async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e.recursive=e.recursive||!1,e.mode=e.mode||"read";const r=await window.showDirectoryPicker({id:e.id,startIn:e.startIn,mode:e.mode});return p(r,e.recursive,void 0,e.skipDirectory)}},m={__proto__:null,default:async function(e){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[{}],l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,c=arguments.length>3&&void 0!==arguments[3]&&arguments[3],d=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null;Array.isArray(r)||(r=[r]),r[0].fileName=r[0].fileName||"Untitled";const m=[];let v=null;if(e instanceof Blob&&e.type?v=e.type:e.headers&&e.headers.get("content-type")&&(v=e.headers.get("content-type")),r.forEach(((e,r)=>{m[r]={description:e.description||"Files",accept:{}},e.mimeTypes?(0===r&&v&&e.mimeTypes.push(v),e.mimeTypes.map((l=>{m[r].accept[l]=e.extensions||[]}))):v?m[r].accept[v]=e.extensions||[]:m[r].accept["*/*"]=e.extensions||[]})),l)try{await l.getFile()}catch(e){if(l=null,c)throw e}const f=l||await window.showSaveFilePicker({suggestedName:r[0].fileName,id:r[0].id,startIn:r[0].startIn,types:m,excludeAcceptAllOption:r[0].excludeAcceptAllOption||!1});!l&&d&&d(f);const g=await f.createWritable();if("stream"in e){const r=e.stream();return await r.pipeTo(g),f}return"body"in e?(await e.body.pipeTo(g),f):(await g.write(await e),await g.close(),f
|
||
|
//# sourceMappingURL=ext-opensave.js.map
|