-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi-iife.js
More file actions
1 lines (1 loc) · 2.8 KB
/
Copy pathapi-iife.js
File metadata and controls
1 lines (1 loc) · 2.8 KB
1
if("__TAURI__"in window){var __TAURI_PLUGIN_SHARE__=function(e){"use strict";async function t(e,t={},r){return window.__TAURI_INTERNALS__.invoke(e,t,r)}"function"==typeof SuppressedError&&SuppressedError;const r=52428800,n=104857600;function i(e){return Boolean(e.text||e.url||e.files&&e.files.length>0||e.filePaths&&e.filePaths.length>0)}function o(e){return(new TextEncoder).encode(e).length}function s(e){if(e.text&&o(e.text)>65536)throw new TypeError("text exceeds the maximum length of 65536 bytes.");if(e.title&&o(e.title)>1024)throw new TypeError("title exceeds the maximum length of 1024 bytes.");if(void 0!==e.url){if(o(e.url)>4096)throw new TypeError("url exceeds the maximum length of 4096 bytes.");if(e.url.length>0&&!function(e){if(e.trim()!==e||/[\s\u0000-\u001f\u007f]/u.test(e))return!1;const t=e.indexOf("://");if(-1===t)return!1;const r=e.slice(t+3).split(/[/?#]/u,1)[0].split("@").pop()??"";if(!r||r.startsWith(":"))return!1;try{const t=new URL(e);return("http:"===t.protocol||"https:"===t.protocol)&&t.host.length>0}catch{return!1}}(e.url))throw new TypeError("Only http:// and https:// URLs can be shared as URLs.")}const t=(e.files?.length??0)+(e.filePaths?.length??0);if(0!==t){if(t>16)throw new TypeError("Too many files provided. Maximum is 16.");if(e.files&&e.files.length>0){if(e.files.reduce((e,t)=>e+t.size,0)>n)throw new TypeError("Total shared file size exceeds the maximum of 104857600 bytes.");const t=e.files.find(e=>e.size>r);if(t)throw new TypeError(`File '${t.name}' exceeds the maximum size of 52428800 bytes.`);if(e.files.find(e=>o(e.name)>255))throw new TypeError("File name exceeds the maximum length of 255 bytes.");if(e.files.find(e=>o(e.type||"application/octet-stream")>255))throw new TypeError("mime type exceeds the maximum length of 255 bytes.")}if(e.filePaths&&e.filePaths.length>0){if(e.filePaths.find(e=>o(e)>4096))throw new TypeError("file path exceeds the maximum length of 4096 bytes.")}}}async function a(e){return new Promise((t,r)=>{const n=new FileReader;n.readAsDataURL(e),n.onload=()=>{const e=n.result.split(",")[1];t(e)},n.onerror=e=>r(e)})}return e.canShare=async function(e){if(e&&!i(e))return!1;if(e)try{s(e)}catch{return!1}const r=await t("plugin:vnidrop-share|can_share");return!0===r.value||"true"===r.value},e.cleanup=async function(){await t("plugin:vnidrop-share|cleanup")},e.share=async function(e){if(!i(e))throw new TypeError("No content provided to share.");s(e);const r={text:e.text,title:e.title,url:e.url};e.files&&e.files.length>0&&(r.files=await Promise.all(e.files.map(async e=>({data:await a(e),name:e.name,mimeType:e.type||"application/octet-stream"})))),e.filePaths&&e.filePaths.length>0&&(r.filePaths=e.filePaths),e.anchor&&(r.anchor=e.anchor),await t("plugin:vnidrop-share|share",{options:r})},e}({});Object.defineProperty(window.__TAURI__,"share",{value:__TAURI_PLUGIN_SHARE__})}