@yuuichi/openlist-assets 4.2.6-ym.8 → 4.2.6-ym.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esa-entry.js
CHANGED
|
@@ -49,7 +49,7 @@ EdgeOne has no D1 \u2014 use DB_DRIVER=blob there instead.
|
|
|
49
49
|
`," "];for(let A of a)if(i.includes(A))throw new Error(`invalid path: illegal character detected (0x${A.charCodeAt(0).toString(16)})`);if(/^[A-Za-z]:/.test(i))throw new Error("invalid path: absolute Windows path not allowed");if(i.startsWith("//")||i.startsWith("\\\\"))throw new Error("invalid path: UNC path not allowed");let o=[];for(let A of i.split("/"))if(!(A===""||A===".")){if(A===".."){o.pop();continue}o.push(A)}let c="/"+o.join("/");c===""&&(c="/");let u=(r.storages||[]).filter(A=>!A.disabled&&typeof A.driver=="string"&&A.driver.trim()!==""&&A.driver!=="undefined"&&A.driver!=="null"&&typeof A.mount_path=="string"&&A.mount_path.trim()!=="");if(u.length===0)throw new Error("failed get storage: storage not found; please add a storage first");let l=[...u].sort((A,g)=>{let f="/"+(A.mount_path||"").split("/").filter(Boolean).join("/");return("/"+(g.mount_path||"").split("/").filter(Boolean).join("/")).length-f.length});for(let A of l){let g="/"+(A.mount_path||"").split("/").filter(Boolean).join("/"),f=g==="/";if(f||c===g||c.startsWith(g+"/")){let y=c;f||(y=c.slice(g.length)),y.startsWith("/")||(y="/"+y);let m={};try{m=typeof A.addition=="string"?JSON.parse(A.addition||"{}"):A.addition||{}}catch{m={}}let b=m.root_folder_path!==void 0?m.root_folder_path:"/",B=([b,y].map(F=>F.replace(/\\/g,"/")).filter(F=>!!F&&F!=="/").join("/")||"/").replace(/\/{2,}/g,"/"),k=String(b||"/").replace(/\\/g,"/").replace(/\/+$/,"")||"/";if(k!=="/"&&B!==k&&!B.startsWith(k+"/"))throw new Error("path traversal blocked: escapes storage root");if(B.split("/").includes(".."))throw new Error("path traversal blocked: illegal '..' segment");return{storage:A,relative:y,physical:B,rootFolder:b,cleanPath:c,isVirtual:!1}}}let d=!1;for(let A of u){let g="/"+(A.mount_path||"").split("/").filter(Boolean).join("/");if(g!=="/"&&g.startsWith(c==="/"?"/":c+"/")){d=!0;break}}if(d)return{storage:null,relative:c,physical:null,rootFolder:null,cleanPath:c,isVirtual:!0};throw new Error("failed get storage: storage not found")}async function qi(){let t=await se(),e={};return t.settings&&t.settings.forEach(r=>{e[r.key]=r.value}),e}async function mG(){return(await se()).users||[]}async function yG(){return(await se()).storages||[]}async function IG(){return(await se()).metas||[]}async function wG(){return(await se()).plugins||[]}var ix,YK,$K,WK,nx,XK,Vo,ht,Fr,Ss,Of,Qa,eG,x2,Qf,Tf,Pf,Ff,tG,rG,Dd,Uf,k2,Sd,iG,nG,ax,ex,se,R2,_2,Q2,T2,P2,Ta,ox,vs,_a,bd,tx,uG,lG,AG,du,rx,de,Ye=G(()=>{"use strict";Tr();v2();jo();v2();jo();ix="txt,htm,html,xml,java,properties,sql,js,json,c,cpp,python,py,php,go,rst,css,typescript,ts,log,conf,yaml,yml,cmd,bash,sh,vue,ini,md,bat,gitignore,h,hpp,tsx,vtt,srt,ass,rs,lrc,strm",YK="m3u8,url",$K="authorization,referer",WK="txt,htm,html,xml,java,properties,sql,js,json,c,cpp,python,py,php,go,rst,css,typescript,ts,log,conf,yaml,yml,cmd,bash,sh,vue,ini",nx="{{base_url}}/@s/{{id}}",XK='@{{creator}} shared {{#each files}}{{#if @first}}"{{filename this}}"{{/if}}{{#if @last}}{{#unless (eq @index 0)}} and {{@index}} more files{{/unless}}{{/if}}{{/each}} from {{site_title}}: {{base_url}}/@s/{{id}}{{#if pwd}} , the share code is {{pwd}}{{/if}}{{#if expires}}, please access before {{dateLocaleString expires}}.{{/if}}',Vo={settings:[{key:"version",value:"v4.2.3",type:"string",help:"Application Version",group:1,flag:1},{key:"site_title",value:"OpenList",type:"string",help:"Site Title",group:1,flag:0},{key:"announcement",value:"",type:"text",help:"Site Announcement",group:1,flag:0},{key:"pagination_type",value:"pagination",type:"select",options:"all,pagination,load_more,auto_load_more",help:"Pagination Type",group:1,flag:0},{key:"default_page_size",value:"20",type:"number",help:"Default Page Size",group:1,flag:0},{key:"allow_indexed",value:"false",type:"bool",help:"Allow Search Engine Indexing",group:1,flag:0},{key:"allow_mounted",value:"true",type:"bool",help:"Allow Mounted Storages",group:1,flag:0},{key:"robots_txt",value:`User-agent: *
|
|
50
50
|
Disallow: /`,type:"text",help:"Robots Txt Content",group:1,flag:0},{key:"logo",value:"https://res.oplist.org/logo/logo.svg",type:"string",help:"Site Logo URL",group:2,flag:0},{key:"favicon",value:"https://res.oplist.org/logo/logo.svg",type:"string",help:"Favicon URL",group:2,flag:0},{key:"main_color",value:"#1890ff",type:"string",help:"Main Theme Color",group:2,flag:0},{key:"home_icon",value:"openlist",type:"string",help:"Home Icon Name",group:2,flag:0},{key:"home_container",value:"max_980px",type:"select",options:"max_980px,hope_container",help:"Home Container Width",group:2,flag:0},{key:"settings_layout",value:"responsive",type:"select",options:"list,responsive",help:"Settings Layout Mode",group:2,flag:0},{key:"text_types",value:ix,type:"text",help:"Text File Extensions",group:3,flag:0},{key:"audio_types",value:"mp3,ogg,aac,wav,wma,flac,m4a,opus",type:"text",help:"Audio File Extensions",group:3,flag:0},{key:"video_types",value:"mp4,mkv,webm,avi,mov,flv,m3u8,ts",type:"text",help:"Video File Extensions",group:3,flag:0},{key:"image_types",value:"jpg,png,jpeg,gif,bmp,svg,ico,webp,avif,tiff",type:"text",help:"Image File Extensions",group:3,flag:0},{key:"proxy_types",value:YK,type:"text",help:"Proxy File Extensions",group:3,flag:0},{key:"proxy_ignore_headers",value:$K,type:"text",help:"Proxy Ignore Headers",group:3,flag:0},{key:"external_previews",value:"{}",type:"text",help:"External Previews JSON Config",group:3,flag:0},{key:"iframe_previews",value:"{}",type:"text",help:"Iframe Previews JSON Config",group:3,flag:0},{key:"audio_cover",value:"https://file.nn.ci/alist/cover.png",type:"string",help:"Audio Default Cover Image URL",group:3,flag:0},{key:"audio_autoplay",value:"false",type:"bool",help:"Autoplay Audio",group:3,flag:0},{key:"video_autoplay",value:"false",type:"bool",help:"Autoplay Video",group:3,flag:0},{key:"preview_archives_by_default",value:"false",type:"bool",help:"Preview Archives By Default",group:3,flag:0},{key:"readme_autorender",value:"true",type:"bool",help:"Readme Autorender",group:3,flag:0},{key:"filter_readme_scripts",value:"true",type:"bool",help:"Filter Readme Scripts",group:3,flag:0},{key:"force_preview",value:"",type:"text",help:"Force Preview Config",group:3,flag:0},{key:"specify_preview",value:"",type:"text",help:"Specify Preview Layout Config",group:3,flag:0},{key:"markdown_autorender",value:"true",type:"bool",help:"Autorender Markdown",group:3,flag:0},{key:"code_editor_theme",value:"vs-dark",type:"select",options:"vs,vs-dark,hc-black",help:"Monaco Theme",group:3,flag:0},{key:"office_preview",value:"true",type:"bool",help:"Enable Office Document Preview",group:3,flag:0},{key:"pdf_preview",value:"true",type:"bool",help:"Enable PDF Preview",group:3,flag:0},{key:"hide_files",value:"",type:"text",help:"Files Regex to Hide",group:4,flag:0},{key:"package_download",value:"true",type:"bool",help:"Package Download Enabled",group:4,flag:0},{key:"customize_head",value:"",type:"text",help:"Custom Head HTML/CSS",group:4,flag:0},{key:"customize_body",value:"",type:"text",help:"Custom Body Script",group:4,flag:0},{key:"link_expiration",value:"0",type:"number",help:"Link Expiration in Hours (0 = never expire)",group:4,flag:0},{key:"sign_all",value:"false",type:"bool",help:"Sign All Download Links",group:4,flag:0},{key:"seed_site_url",value:"",type:"string",help:"Public site URL used by transfer seed sources",group:4,flag:1},{key:"seed_default_matrix",value:'{"md5":{"whole":true,"pieces":false},"sha1":{"whole":true,"pieces":false},"sha256":{"whole":true,"pieces":false}}',type:"text",help:"Default transfer seed hash matrix",group:4,flag:1},{key:"seed_format_policies",value:'{"oss":"off","torrent":"off","cas":"off"}',type:"text",help:"Automatic transfer seed format policies",group:4,flag:1},{key:"seed_auto_generate_policy",value:"off",type:"select",options:"off,on",help:"Global automatic transfer seed policy",group:4,flag:1},{key:"seed_single_direct_preview",value:"false",type:"bool",help:"Open single-file transfer seeds directly in preview",group:4,flag:0},{key:"seed_cas_direct_access",value:"false",type:"bool",help:"When opening a single-file CAS seed, immediately rapid-upload it into the same folder and preview the restored file",group:4,flag:0},{key:"seed_default_trackers",value:"",type:"text",help:"Default tracker list offered when generating torrent seeds (one tracker per line)",group:4,flag:1},{key:"privacy_regs",value:"",type:"text",help:"Privacy Regex Rules",group:4,flag:0},{key:"ocr_api",value:"",type:"string",help:"OCR API Endpoint",group:4,flag:0},{key:"filename_char_mapping",value:"{}",type:"text",help:"Filename Char Mapping JSON",group:4,flag:0},{key:"forward_direct_link_params",value:"",type:"string",help:"Forward Direct Link Params",group:4,flag:0},{key:"ignore_direct_link_params",value:"",type:"string",help:"Ignore Direct Link Params",group:4,flag:0},{key:"webauthn_login_enabled",value:"false",type:"bool",help:"Webauthn Login Enabled",group:4,flag:0},{key:"allow_previewing_sharing_files",value:"true",type:"bool",help:"Allow Previewing Sharing Files",group:4,flag:0},{key:"allow_previewing_sharing_archives",value:"true",type:"bool",help:"Allow Previewing Sharing Archives",group:4,flag:0},{key:"force_proxy_sharing_files",value:"false",type:"bool",help:"Force Proxy Sharing Files",group:4,flag:0},{key:"share_summary_content",value:nx,type:"text",help:"Share Summary Content",group:4,flag:0},{key:"handle_hook_after_writing",value:"",type:"string",help:"Handle Hook After Writing",group:4,flag:0},{key:"handle_hook_rate_limit",value:"0",type:"number",help:"Handle Hook Rate Limit",group:4,flag:0},{key:"ignore_system_files",value:"true",type:"bool",help:"Ignore System Files (.DS_Store, desktop.ini, etc.)",group:4,flag:0},{key:"auto_update_index",value:"false",type:"bool",help:"Auto Update Search Index",group:4,flag:0},{key:"sso_login_enabled",value:"false",type:"bool",help:"Enable SSO Login",group:7,flag:0},{key:"sso_login_platform",value:"",type:"select",options:"Github,Microsoft,Google,Dingtalk,Casdoor,OIDC",help:"SSO Platform",group:7,flag:0},{key:"sso_client_id",value:"",type:"string",help:"SSO Client ID",group:7,flag:0},{key:"sso_client_secret",value:"",type:"string",help:"SSO Client Secret",group:7,flag:0},{key:"sso_login_url",value:"",type:"string",help:"SSO Authorization Endpoint",group:7,flag:0},{key:"sso_token_url",value:"",type:"string",help:"SSO Token Endpoint (optional, defaults per platform)",group:7,flag:0},{key:"sso_userinfo_url",value:"",type:"string",help:"SSO UserInfo Endpoint (optional, defaults per platform)",group:7,flag:0},{key:"sso_scopes",value:"",type:"string",help:"SSO OAuth2 Scopes (optional, space separated)",group:7,flag:0},{key:"sso_oidc_discovery_url",value:"",type:"string",help:"OIDC Discovery URL (for OIDC platform)",group:7,flag:0},{key:"sso_login_callback_url",value:"",type:"string",help:"SSO Redirect/Callback URL (optional, defaults to /api/auth/sso_callback)",group:7,flag:0},{key:"sso_compatibility_mode",value:"false",type:"bool",help:"SSO Compatibility Mode (postMessage token handoff)",group:7,flag:0},{key:"sso_auto_register",value:"false",type:"bool",help:"Auto Register New SSO Users",group:7,flag:0},{key:"sso_default_dir",value:"/",type:"string",help:"SSO Default Directory for New Users",group:7,flag:0},{key:"sso_default_permission",value:"0",type:"number",help:"SSO Default Permission for New Users",group:7,flag:0},{key:"ldap_host",value:"",type:"string",help:"LDAP Server Host",group:8,flag:0},{key:"ldap_port",value:"389",type:"number",help:"LDAP Server Port",group:8,flag:0},{key:"traffic_limit",value:"0",type:"number",help:"Traffic Limit in MB",group:10,flag:0},{key:"ip_limit",value:"0",type:"number",help:"IP Rate Limit Per Minute",group:10,flag:0},{key:"115_temp_dir",value:"",type:"string",help:"115 Temp Directory",group:14,flag:0},{key:"115_open_temp_dir",value:"",type:"string",help:"115 Open Temp Directory",group:14,flag:0},{key:"123_temp_dir",value:"",type:"string",help:"123 Pan Temp Directory",group:14,flag:0},{key:"123_open_temp_dir",value:"",type:"string",help:"123 Open Temp Directory",group:14,flag:0},{key:"123_open_callback_url",value:"",type:"string",help:"123 Open Callback URL",group:14,flag:0},{key:"pikpak_temp_dir",value:"",type:"string",help:"PikPak Temp Directory",group:14,flag:0},{key:"thunder_temp_dir",value:"",type:"string",help:"Thunder Temp Directory",group:14,flag:0},{key:"thunder_browser_temp_dir",value:"",type:"string",help:"Thunder Browser Temp Directory",group:14,flag:0},{key:"thunderx_temp_dir",value:"",type:"string",help:"ThunderX Temp Directory",group:14,flag:0},{key:"token",value:"",type:"string",help:"115 / PikPak / Thunder Token",group:14,flag:0},{key:"package_download_disabled",value:"false",type:"bool",help:"Disable Package Download",group:14,flag:0}],storages:[],users:[{id:1,username:"admin",password:"",role:2,permission:0,base_path:"/",disabled:!1,sso_id:"",allow_ldap:!1,pwd_update_at:new Date().toISOString()},{id:2,username:"guest",password:"",role:1,permission:0,base_path:"/",disabled:!1,sso_id:"",allow_ldap:!1,pwd_update_at:new Date().toISOString()}],metas:[],shares:[],plugins:[]},ht=null,Fr=null,Ss=!1,Of=!1,Qa=null;eG={logo:{from:["","/logo.png","https://res.oplist.org/logo/logo.png"],to:"https://res.oplist.org/logo/logo.svg"},favicon:{from:["","/favicon.png"],to:"https://res.oplist.org/logo/logo.svg"},home_container:{from:["hope_container"],to:"max_980px"},text_types:{from:[WK],to:ix},share_summary_content:{from:["",XK],to:nx}},x2=t=>{if(!t)return;t.settings||(t.settings=[]);let e=!1,r=[],i=new Set;for(let n of Vo.settings){i.add(n.key);let s=t.settings.filter(a=>a.key===n.key);if(s.length===0)r.push(JSON.parse(JSON.stringify(n))),e=!0;else{let a=s.find(c=>c.value&&c.value.trim()!=="")||s[0];(a.group!==n.group||a.help!==n.help||a.type!==n.type||a.options!==n.options||a.flag!==n.flag)&&(a.group=n.group,a.help=n.help,a.type=n.type,a.options=n.options,a.flag=n.flag,e=!0),s.length>1&&(e=!0);let o=eG[n.key];o&&o.from.includes(a.value)&&(a.value=o.to,e=!0),r.push(a)}}for(let n of t.settings)n.key&&!i.has(n.key)&&(i.add(n.key),r.push(n));t.settings=r},Qf=t=>{t&&(!t.storages||!Array.isArray(t.storages)?t.storages=[]:t.storages=t.storages.filter(e=>e&&typeof e=="object"&&typeof e.driver=="string"&&e.driver.trim()!==""&&e.driver!=="undefined"&&e.driver!=="null"&&typeof e.mount_path=="string"&&e.mount_path.trim()!==""))},Tf=t=>{t&&(t.shares||(t.shares=[]))},Pf=t=>{t&&(t.plugins||(t.plugins=[]))},Ff=t=>{t&&(!t.metas||!Array.isArray(t.metas))&&(t.metas=[])},tG=500,rG=Symbol.for("openlist.configVersion"),Dd=new WeakMap,Uf=new WeakMap,k2=new WeakMap,Sd=t=>vf(t),iG=()=>{Fr&&typeof Fr=="object"&&(Dd.delete(Fr),Uf.delete(Fr)),Fr=null,ht=null,Sd=t=>vf(t),Ss=!1,Qa=null,Of=!1,vs=null,_a=!1,_2=!1,Q2=!1,T2=!1,P2=!1,PS(),du.clear()},nG=t=>{Sd=t},ax=()=>{let t=Fr;return t&&typeof t=="object"?t:null},ex=async t=>{t&&(Fr=t);let e=t||Fr,r=null;try{r=await Sd(e);let i=await r.load(e);if(i){let n=gG(i);n&&Jo(e)==="none"&&!P2&&(P2=!0,console.log("[DB] DB_CIPHER=none: existing encrypted values were decrypted; the next save will write them back as PLAINTEXT (per-field migration, no explicit step needed). Set DB_CIPHER to keep them encrypted."));let s=n?await ux(e,{needDecrypt:!0}):null;return await pG(i,s),ht=i,x2(ht),Qf(ht),Tf(ht),Pf(ht),Ff(ht),Ss=!0,Qa=null,ht}if(Ss&&ht)return console.warn(`[DB] Backend ${r?.name??"storage"} returned empty while a trusted snapshot exists; keeping the in-memory snapshot to avoid overwriting real config.`),x2(ht),Qf(ht),Tf(ht),Pf(ht),Ff(ht),ht;Ss=!1,Qa=null}catch(i){console.error(`[DB] Error reading config from ${r?.name??"storage"}:`,i?.message||i),Qa=String(i?.message||i),Ss=!1}return ht&&Ss?(x2(ht),Qf(ht),Tf(ht),Pf(ht),Ff(ht),ht):(ht=JSON.parse(JSON.stringify(Vo)),Qf(ht),Tf(ht),Pf(ht),Ff(ht),ht)},se=async t=>{t&&(Fr=t);let e=t||ax();if(!e)return ex(t);let r=t||Fr,i=Uf.get(e);if(i)return i;let n=Dd.get(e);if(n&&Date.now()-n.ts<tG)return n.db;if(n?.db){let a=sG(n.db);if(a!==null&&await aG(r,e)===a)return Dd.set(e,{ts:Date.now(),db:n.db}),n.db}let s=ex(t).then(a=>(Dd.set(e,{ts:Date.now(),db:a}),a)).finally(()=>{Uf.delete(e)});return Uf.set(e,s),s};R2=new Set(["token","sso_client_secret","sso_client_id","ldap_bind_password","ldap_bind_dn","ocr_api","handle_hook_after_writing"]),_2=!1,Q2=!1,T2=!1,P2=!1,Ta="openlist_encryption_secret";ox=32;vs=null,_a=!1;bd=null,tx=6,uG=100,lG=1e3;AG=4096,du=new Map;rx=16;de=async(t,e,r)=>{e&&(Fr=e);let i=e||Fr;if(sx(t)&&!r?.force){Of=!0;let c=Qa?`last load failed: ${Qa}`:Ss?"payload is an empty/shell database":"database was never successfully loaded from the persistence backend";return console.error(`[DB] saveDb BLOCKED: refusing to persist an empty/shell database (${c}). This guard prevents an empty payload from wiping real config. Pass saveDb(db, env, { force: true }) to override intentionally.`),!1}ht=t,Of=!1;let s=e||ax();s&&Dd.set(s,{ts:Date.now(),db:t});let a=await Sd(i);if(!(a.isConfigured?await a.isConfigured(i):!0))return console.warn("[DB] WARNING: No persistence backend configured! Storage configuration changes will exist only in memory!"),!1;try{let c=Jo(i);console.log(`[DB] saveDb: cipher=${c}, persisting to ${a.name}, storages=${t.storages?.length||0}`);let u=c==="none"?null:await ux(i);c!=="none"&&!u&&!T2&&(T2=!0,console.error(`[DB] DB_CIPHER=${c} but no encryption key is available; sensitive fields will be stored in PLAINTEXT. Set JWT_SECRET.`));let l=await fG(t,u);console.log(`[DB] saveDb: sealed data size=${JSON.stringify(l).length} bytes`),await a.save(l,i)}catch(c){throw console.error(`[DB] saveDb FAILED: backend=${a.name}, error=${c?.message||c}`,`stack=${c?.stack?.substring(0,500)||""}`),new Error(`[DB] Failed to persist config (${a.name}); the change was NOT saved: ${c?.message||c}`)}return console.log(`[DB] Successfully persisted ${t.storages?.length||0} storages to ${a.name}`),Ss=!0,Qa=null,!0}});function xs(t){return(t.startsWith("/")?t:`/${t}`).replace(/[^A-Za-z0-9\-_.~$&+,:;=@/]/gu,r=>{try{return encodeURIComponent(r)}catch{return r}})}var Au=G(()=>{"use strict"});function dx(t){if(!t)return{};if(typeof t=="object")return t;if(typeof t=="string")try{let e=JSON.parse(t||"{}");return e&&typeof e=="object"?e:{}}catch{return{}}return{}}function M2(t){return typeof t=="string"?t.toLowerCase()==="true":t===!0}function Yo(t){if(typeof t=="number"&&Number.isFinite(t))return Math.trunc(t);if(typeof t=="string"&&t.trim()!==""){let e=parseInt(t,10);if(Number.isFinite(e))return e}return null}function Ax(t){let e=t?.proxy_range??t?.proxyRange;return e==null||e===""?!0:M2(e)}function hx(t){return t?M2(t.enable_sign??t.enableSign):!1}function gx(t){return t?M2(t.disable_index??t.disableIndex):!1}function EG(t){let e=Yo(t?.cache_expiration??t?.cacheExpiration);return e===null||e<0?30:e}function CG(t){let e=t?.custom_cache_policies??t?.customCachePolicies;if(!e)return[];if(typeof e=="string"){let i=e.trim();if(!i)return[];try{e=JSON.parse(i)}catch{let n=[];for(let s of i.split(",")){let a=s.lastIndexOf(":");if(a<=0)continue;let o=s.slice(0,a).trim(),c=Yo(s.slice(a+1).trim());o&&c!==null&&n.push({path:o,cacheExpiration:c})}return n}}let r=[];if(Array.isArray(e)){for(let i of e)if(i){if(typeof i=="string"){let n=i.lastIndexOf(":");if(n<=0)continue;let s=i.slice(0,n).trim(),a=Yo(i.slice(n+1).trim());s&&a!==null&&r.push({path:s,cacheExpiration:a});continue}if(typeof i=="object"){let n=i.path??i.Path,s=Yo(i.cache_expiration??i.cacheExpiration)??Yo(i.max_age??i.maxAge);if(typeof n=="string"&&n&&s!==null){let a=Yo(i.max_age??i.maxAge);r.push({path:n,cacheExpiration:s,...a!==null?{maxAge:a}:{}})}}}return r}if(typeof e=="object")for(let[i,n]of Object.entries(e)){let s=Yo(n);i&&s!==null&&r.push({path:i,cacheExpiration:s})}return r}function lx(t,e){if(!t)return!1;if(t===e)return!0;if(t.length>BG||e.length>bG)return!1;let r=t.split("/"),i=e.split("/"),n=r.length,s=i.length,a=new Array(s+1).fill(!1);a[s]=!0;for(let o=n-1;o>=0;o--){let c=r[o],u=new Array(s+1).fill(!1);if(/^\*{2,}$/.test(c)){u[s]=a[s];for(let d=s-1;d>=0;d--)u[d]=a[d]||u[d+1]}else for(let d=s-1;d>=0;d--)u[d]=DG(c,i[d])&&a[d+1];a=u}return a[0]}function DG(t,e){let r=0,i=0,n=-1,s=-1,a=t.length,o=e.length;for(;i<o;){let c=r<a?t[r]:void 0;if(c==="*"){n=r,s=i,r++;continue}if(c==="?"||c===e[i]){r++,i++;continue}if(n!==-1){s++,i=s,r=n+1;continue}return!1}for(;r<a&&t[r]==="*";)r++;return r===a}function fx(t,e){let r="/"+String(e||"").split("/").filter(Boolean).join("/"),i=EG(t),n=CG(t);if(n.length===0)return i;let s=null;for(let a of n){let o=a.path.trim();o&&(!o.startsWith("/")&&!o.startsWith("*")&&(o="/"+o),(lx(o,r)||lx(o,r.slice(1)))&&(s=a))}return s?s.cacheExpiration:i}var BG,bG,vd=G(()=>{"use strict";BG=1024,bG=4096});function $o(t){return String(t??"").toLowerCase().replace(/[^a-z0-9]/g,"")}function Wo(t){let e=Array.isArray(t)?t.join(","):t;return String(e??"").split(",").map(r=>r.trim().toLowerCase().replace(/^\./,"")).filter(Boolean)}function yx(t){let e=String(t??"").split("/").pop()?.trim();if(!e)return"";let r=e.lastIndexOf(".");return r<0||r===e.length-1?"":e.slice(r+1).toLowerCase()}function Ix(t){return px.has($o(t))}function xG(t){let e=dx(t?.addition),r=String(e.storage_zone_name??"").trim(),i=String(e.cdn_base_url??"").trim();return r!==""&&i===""}function qf(t,e){let r=$o(e??t?.driver);return px.has(r)?!0:r==="bunnystorage"?xG(t):!1}function q2(t){return SG.has($o(t))}function wx(t){if(!t)return"";let e=t.webdav_policy??t.webdavPolicy??t.policy??t.webdavPolicyType;return typeof e=="string"?e.trim():""}function Ex(t){if(!t)return"";for(let r of["down_proxy_url","downProxyUrl"]){let i=t[r];if(typeof i=="string"&&i.trim())return i.split(`
|
|
51
51
|
`)[0].trim()}let e=t.addition;if(typeof e=="string")try{e=JSON.parse(e||"{}")}catch{return""}if(!e||typeof e!="object")return"";for(let r of vG){let i=e[r];if(typeof i=="string"&&i.trim())return i.split(`
|
|
52
|
-
`)[0].trim()}return""}function Cx(t){if(!t)return!1;let e=t.disable_proxy_sign??t.disableProxySign;return typeof e=="string"?e.toLowerCase()==="true":!!e}function Bx(t,e){let r=t?.web_proxy??t?.webProxy;return r===!0||r==="true"?!0:r===!1||r==="false"?!1:q2(e)}function bx(t,e,r,i={}){let n=$o(e);if(qf(t,n))return{mode:"native_proxy",needsProxy:!0,source:"force"};if(Bx(t,n))return{mode:"native_proxy",needsProxy:!0,source:"web_proxy"};if(r)return{mode:"native_proxy",needsProxy:!0,source:"proxy_path"};if(L2(yx(i.filename),i.proxyTypes))return{mode:"native_proxy",needsProxy:!0,source:"proxy_types"};let s=wx(t);return s?{mode:s,needsProxy:s!=="302_redirect",source:"storage_policy"}:{mode:"302_redirect",needsProxy:!1,source:"driver_default"}}function L2(t,e){return t?Wo(e).includes(t):!1}function Hf(t){let e=$o(t.driver);if(qf(t.storage,e)||Bx(t.storage,e)||wx(t.storage)==="use_proxy_url")return!0;let r=yx(t.filename);return r?L2(r,t.proxyTypes)||L2(r,t.textTypes):!1}var px,SG,mx,vG,xd=G(()=>{"use strict";vd();px=new Set(["weiyun","sftp","ftp","smb","crypt","virtual","strm","meganz","protondrive","chunk","googledrive","googlephoto","quarkopen","quarkuc","chaoxing","local"]),SG=new Set(["webdav","baidunetdisk","123pan","123open","123panshare"]),mx=new Set(["139yun","alias","alistv3","openlist"]),vG=["down_proxy_url","download_proxy_url","proxy_url"]});function W(t,e){if(e)return 1;let r=(t.split(".").pop()||"").toLowerCase();return["mp4","mkv","avi","mov","flv","wmv","ts","m2ts","m4v","rmvb","webm","3gp","asf","vob","ogv","rm","f4v"].includes(r)?2:["mp3","flac","aac","wav","ogg","m4a","opus","wma","ape","alac","aiff","mid","midi"].includes(r)?3:["txt","md","markdown","json","js","ts","jsx","tsx","css","scss","html","htm","xml","yaml","yml","ini","conf","env","log","sql","py","java","c","cpp","h","hpp","go","rs","sh","bat","cmd","ps1","php","rb","swift","kt","cs","vue","svelte","json5","toml"].includes(r)?4:["jpg","jpeg","png","gif","bmp","webp","svg","ico","tiff","tif","heic","heif","avif","vvc","avc","psd","ai"].includes(r)?5:0}var Ee=G(()=>{"use strict"});function le(t,e,r){let i=r!=="desc",n=String(e||"name").toLowerCase(),s=[...t];return s.sort((a,o)=>{if(a.is_dir!==o.is_dir)return a.is_dir?-1:1;let c;return n.includes("size")?c=(a.size||0)-(o.size||0):n.includes("time")||n.includes("modified")||n.includes("created")?c=new Date(a.modified).getTime()-new Date(o.modified).getTime():c=String(a.name).localeCompare(String(o.name)),i?c:-c}),s}var Me=G(()=>{"use strict"});var Ln,H2=G(()=>{"use strict";Ln={global:{oauth:"https://login.microsoftonline.com",api:"https://graph.microsoft.com"},cn:{oauth:"https://login.partner.microsoftonline.cn",api:"https://microsoftgraph.chinacloudapi.cn"},us:{oauth:"https://login.microsoftonline.us",api:"https://graph.microsoft.us"},de:{oauth:"https://login.microsoftonline.de",api:"https://graph.microsoft.de"}}});function K2(t,e){let r="";return t.thumbnails&&t.thumbnails.length>0&&(r=t.thumbnails[0].medium?.url||""),{id:t.id,name:t.name,size:t.size,modified:t.lastModifiedDateTime||t.fileSystemInfo?.lastModifiedDateTime||"",isFolder:!!t.folder||!t.file,thumbnail:r,parentID:e,url:t["@microsoft.graph.downloadUrl"]||""}}var Dx=G(()=>{"use strict"});async function G2(t){if(t.use_online_api&&t.api_url_address){let s=new URLSearchParams({refresh_ui:t.refresh_token,server_use:"true",driver_txt:"onedrive_pr"}).toString(),o=await(await fetch(`${t.api_url_address}?${s}`)).json();if(!o.refresh_token||!o.access_token)throw o.text?new Error(`failed to refresh token: ${o.text}`):new Error("empty token returned from official API");t.accessToken=o.access_token,t.refresh_token=o.refresh_token,await t.onTokenUpdate?.(t.refresh_token);return}if(!t.client_id||!t.client_secret)throw new Error("empty ClientID or ClientSecret");let r=`${(Ln[t.region]||Ln.global).oauth}/common/oauth2/v2.0/token`,n=await(await fetch(r,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"refresh_token",client_id:t.client_id,client_secret:t.client_secret,redirect_uri:t.redirect_uri,refresh_token:t.refresh_token}).toString()})).json();if(!n.refresh_token)throw new Error("Empty token");t.refresh_token=n.refresh_token,t.accessToken=n.access_token,await t.onTokenUpdate?.(t.refresh_token)}async function ki(t,e,r,i,n){let s=i!==void 0&&(i instanceof Uint8Array||i instanceof ArrayBuffer||typeof Buffer<"u"&&Buffer.isBuffer(i)),a={method:r.toUpperCase(),headers:{Authorization:`Bearer ${t.accessToken}`,...i!==void 0?{"Content-Type":s?"application/octet-stream":"application/json"}:{}},...i!==void 0?{body:s?i:JSON.stringify(i)}:{}},o=await fetch(e,a);if(!o.ok){let c;try{c=(await o.json()).error}catch{c=null}let u=c?.code;if((u==="InvalidAuthenticationToken"||u==="ExpiredAuthenticationToken"||o.status===401)&&!n)return await G2(t),ki(t,e,r,i,!0);throw new Error(c?.message||`Request failed: ${o.status}`)}if(o.status!==204)return o.json()}function Sx(t,e,r){let i=e.replace(/\\/g,"/");if(!i||i==="/")return r?`${t}/drive/root/${r}`:`${t}/drive/root`;let n=i.startsWith("/")?i.slice(1):i;if(n.endsWith("/")&&(n=n.slice(0,-1)),!n||n==="")return r?`${t}/drive/root/${r}`:`${t}/drive/root`;let s=n.split("/").map(encodeURIComponent).join("/");return r?`${t}/drive/root:/${s}:/${r}`:`${t}/drive/root:/${s}:`}async function vx(t,e){let r=Ln[t.region]||Ln.global,i=t.is_sharepoint?`${r.api}/v1.0/sites/${t.site_id}`:`${r.api}/v1.0/me`,s=Sx(i,e,"children?$top=1000&$expand=thumbnails($select=medium)&$select=id,name,size,fileSystemInfo,@microsoft.graph.downloadUrl,file,folder,parentReference"),a=[];for(;s;){let o=await ki(t,s,"GET");o.value&&a.push(...o.value),s=o["@odata.nextLink"]}return a}async function xx(t,e){let r=Ln[t.region]||Ln.global,i=t.is_sharepoint?`${r.api}/v1.0/sites/${t.site_id}`:`${r.api}/v1.0/me`,n=Sx(i,e);return ki(t,n,"GET")}var kx=G(()=>{"use strict";H2()});var Kf,_x=G(()=>{"use strict";Me();H2();Dx();kx();Kf=class{root_folder_path="/";region="global";is_sharepoint=!1;use_online_api=!0;api_url_address="https://api.oplist.org/onedrive/renewapi";client_id="";client_secret="";redirect_uri="https://api.oplist.org/onedrive/callback";refresh_token="";site_id="";chunk_size=5;custom_host="";disable_disk_usage=!1;enable_direct_upload=!1;order_by="filename";order_direction="asc";accessToken="";onTokenUpdate;constructor(e,r){e&&(e.root_folder_path!==void 0&&(this.root_folder_path=String(e.root_folder_path)),e.region!==void 0&&(this.region=String(e.region)),e.is_sharepoint!==void 0&&(this.is_sharepoint=!!e.is_sharepoint),e.use_online_api!==void 0&&(this.use_online_api=!!e.use_online_api),e.api_url_address!==void 0&&(this.api_url_address=String(e.api_url_address)),e.client_id!==void 0&&(this.client_id=String(e.client_id)),e.client_secret!==void 0&&(this.client_secret=String(e.client_secret)),e.redirect_uri!==void 0&&(this.redirect_uri=String(e.redirect_uri)),e.refresh_token!==void 0&&(this.refresh_token=String(e.refresh_token)),e.site_id!==void 0&&(this.site_id=String(e.site_id)),e.chunk_size!==void 0&&(this.chunk_size=Number(e.chunk_size)||5),e.custom_host!==void 0&&(this.custom_host=String(e.custom_host)),e.disable_disk_usage!==void 0&&(this.disable_disk_usage=!!e.disable_disk_usage),e.enable_direct_upload!==void 0&&(this.enable_direct_upload=!!e.enable_direct_upload),e.order_by!==void 0&&(this.order_by=String(e.order_by)),e.order_direction!==void 0&&(this.order_direction=String(e.order_direction))),this.onTokenUpdate=r}async init(){typeof this.is_sharepoint=="string"&&(this.is_sharepoint=this.is_sharepoint.toLowerCase()==="true"),typeof this.use_online_api=="string"&&(this.use_online_api=this.use_online_api.toLowerCase()==="true"),typeof this.chunk_size=="string"&&(this.chunk_size=parseInt(this.chunk_size)||5),typeof this.disable_disk_usage=="string"&&(this.disable_disk_usage=this.disable_disk_usage.toLowerCase()==="true"),typeof this.enable_direct_upload=="string"&&(this.enable_direct_upload=this.enable_direct_upload.toLowerCase()==="true"),this.chunk_size<1&&(this.chunk_size=5),this.refresh_token&&await G2(this)}getMetaUrl(e,r,i){let n=Ln[this.region]||Ln.global;if(e)return n.oauth;let s=this.is_sharepoint?`${n.api}/v1.0/sites/${this.site_id}`:`${n.api}/v1.0/me`,a=r.replace(/\\/g,"/");if(!a||a==="/")return i?`${s}/drive/root/${i}`:`${s}/drive/root`;let o=a.startsWith("/")?a.slice(1):a;if(o.endsWith("/")&&(o=o.slice(0,-1)),!o||o==="")return i?`${s}/drive/root/${i}`:`${s}/drive/root`;let c=o.split("/").map(u=>{try{return encodeURIComponent(decodeURIComponent(u))}catch{return encodeURIComponent(u)}}).join("/");return i?`${s}/drive/root:/${c}:/${i}`:`${s}/drive/root:/${c}:`}async list(e,r){let n=(await vx(this,r)).map(s=>{let a=K2(s,""),o=s["@microsoft.graph.downloadUrl"]||a.url||"";if(this.custom_host&&o)try{let c=new URL(o);c.host=this.custom_host,o=c.toString()}catch{}return{name:a.name,size:a.size,is_dir:a.isFolder,modified:a.modified,sign:"",type:a.isFolder?1:0,thumb:a.thumbnail||"",raw_url:o}});return le(n,this.order_by,this.order_direction)}async get(e,r){let i=await xx(this,r),n=K2(i,""),s=i["@microsoft.graph.downloadUrl"]||n.url||"";if(this.custom_host&&s)try{let a=new URL(s);a.host=this.custom_host,s=a.toString()}catch{}return{name:n.name,size:n.size,is_dir:n.isFolder,modified:n.modified,sign:"",type:n.isFolder?1:0,thumb:n.thumbnail||"",raw_url:s}}async mkdir(e,r){let i=r.split("/").slice(0,-1).join("/")||"/",n=r.split("/").filter(Boolean).pop()||"",s=this.getMetaUrl(!1,i,"children");await ki(this,s,"POST",{name:n,folder:{},"@microsoft.graph.conflictBehavior":"rename"})}async rename(e,r,i){let n={name:i},s=this.getMetaUrl(!1,r);await ki(this,s,"PATCH",n)}async remove(e,r,i){let n=this.getMetaUrl(!1,r);await ki(this,n,"DELETE")}async move(e,r,i,n,s){let a=s.split("/").slice(0,-1).join("/")||"/",o=this.getMetaUrl(!1,a),c=await ki(this,o,"GET"),u=c.id,l=c.parentReference?.driveId,d={parentReference:{id:u,...l?{driveId:l}:{}},name:s.split("/").filter(Boolean).pop()||""},A=this.getMetaUrl(!1,n);await ki(this,A,"PATCH",d)}async copy(e,r,i,n,s){let a=s.split("/").slice(0,-1).join("/")||"/",o=this.getMetaUrl(!1,a),c=await ki(this,o,"GET"),u=c.id,l=c.parentReference?.driveId,d={parentReference:{id:u,...l?{driveId:l}:{}},name:s.split("/").filter(Boolean).pop()||""},A=this.getMetaUrl(!1,n,"copy");await ki(this,A,"POST",d)}async put(e,r,i){if(i.length<=4*1024*1024){let n=this.getMetaUrl(!1,r,"content");await ki(this,n,"PUT",i)}else{let n=this.getMetaUrl(!1,r,"createUploadSession"),o=(await ki(this,n,"POST",{item:{"@microsoft.graph.conflictBehavior":"rename"}})).uploadUrl,c=this.chunk_size*1024*1024,u=0,l=i.length;for(;u<l;){let d=l-u,A=Math.min(d,c),g=i.slice(u,u+A);await fetch(o,{method:"PUT",headers:{"Content-Length":String(A),"Content-Range":`bytes ${u}-${u+A-1}/${l}`},body:g}),u+=A}}}}});function z2(t,e){let r="";return t.thumbnails&&t.thumbnails.length>0&&(r=t.thumbnails[0].medium?.url||""),{id:t.id,name:t.name,size:t.size,modified:t.lastModifiedDateTime||t.fileSystemInfo?.lastModifiedDateTime||"",isFolder:!!t.folder||!t.file,thumbnail:r,parentID:e,url:t["@microsoft.graph.downloadUrl"]||""}}var Qx=G(()=>{"use strict"});var Xo,Tx=G(()=>{"use strict";Xo={global:{oauth:"https://login.microsoftonline.com",api:"https://graph.microsoft.com"},cn:{oauth:"https://login.chinacloudapi.cn",api:"https://microsoftgraph.chinacloudapi.cn"},us:{oauth:"https://login.microsoftonline.us",api:"https://graph.microsoft.us"},de:{oauth:"https://login.microsoftonline.de",api:"https://graph.microsoft.de"}}});function _i(t,e,r,i){let n=Xo[t.region]||Xo.global;if(e)return n.oauth;let s=r?r.replace(/\\/g,"/"):"";if(!s||s==="/")return i?`${n.api}/v1.0/users/${t.email}/drive/root/${i}`:`${n.api}/v1.0/users/${t.email}/drive/root`;let a=s.startsWith("/")?s.slice(1):s;if(a.endsWith("/")&&(a=a.slice(0,-1)),!a||a==="")return i?`${n.api}/v1.0/users/${t.email}/drive/root/${i}`:`${n.api}/v1.0/users/${t.email}/drive/root`;let o=a.split("/").map(c=>{try{return encodeURIComponent(decodeURIComponent(c))}catch{return encodeURIComponent(c)}}).join("/");return i?`${n.api}/v1.0/users/${t.email}/drive/root:/${o}:/${i}`:`${n.api}/v1.0/users/${t.email}/drive/root:/${o}:`}async function J2(t){let e=null;for(let r=0;r<3;r++)try{await kG(t);return}catch(i){e=i}throw e||new Error("Failed to get access token")}async function kG(t){if(!t.client_id||!t.client_secret)throw new Error("empty client_id or client_secret");if(!t.tenant_id)throw new Error("empty tenant_id");let e=Xo[t.region]||Xo.global,r=`${e.oauth}/${t.tenant_id}/oauth2/token`,i=new URLSearchParams({grant_type:"client_credentials",client_id:t.client_id,client_secret:t.client_secret,resource:`${e.api}/`,scope:`${e.api}/.default`}).toString(),s=await(await fetch(r,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:i})).json();if(s.error)throw new Error(s.error_description||s.error);if(!s.access_token)throw new Error("empty token returned from Microsoft identity platform");t.accessToken=s.access_token,t.onTokenUpdate?.(t.accessToken)}async function Xr(t,e,r,i,n){let s=i!==void 0&&(typeof i=="string"||i instanceof Uint8Array||i instanceof ArrayBuffer||typeof Buffer<"u"&&Buffer.isBuffer(i)),a={method:r.toUpperCase(),headers:{Authorization:`Bearer ${t.accessToken}`,...i!==void 0&&!s?{"Content-Type":"application/json"}:{}},...i!==void 0?{body:s?i:JSON.stringify(i)}:{}},o=await fetch(e,a);if(!o.ok){let c;try{c=(await o.json()).error}catch{c=null}let u=c?.code;if((u==="InvalidAuthenticationToken"||u==="ExpiredAuthenticationToken"||o.status===401)&&!n)return await J2(t),Xr(t,e,r,i,!0);throw new Error(c?.message||`Request failed: ${o.status}`)}if(o.status!==204)return o.json()}async function Px(t,e){let i=_i(t,!1,e,"children?$top=1000&$expand=thumbnails($select=medium)&$select=id,name,size,fileSystemInfo,lastModifiedDateTime,@microsoft.graph.downloadUrl,file,folder,parentReference"),n=[];for(;i;){let s=await Xr(t,i,"GET");s.value&&n.push(...s.value),i=s["@odata.nextLink"]}return n}async function Fx(t,e){let r=_i(t,!1,e);return Xr(t,r,"GET")}async function Nx(t){let r=`${(Xo[t.region]||Xo.global).api}/v1.0/users/${t.email}/drive`;return Xr(t,r,"GET",void 0,!0)}async function Rx(t,e){let r=_i(t,!1,e,"createUploadSession"),s=(await Xr(t,r,"POST",{item:{"@microsoft.graph.conflictBehavior":"rename"}})).uploadUrl;if(!s)throw new Error("failed to get upload URL from response");return{UploadURL:s,ChunkSize:(t.chunk_size||5)*1024*1024,Method:"PUT"}}var Ux=G(()=>{"use strict";Tx()});var Gf,Ox=G(()=>{"use strict";Me();Qx();Ux();Gf=class{root_folder_path="/";region="global";client_id="";client_secret="";tenant_id="";email="";chunk_size=5;custom_host="";disable_disk_usage=!1;enable_direct_upload=!1;order_by="filename";order_direction="asc";accessToken="";onTokenUpdate;constructor(e,r){e&&(e.root_folder_path!==void 0&&(this.root_folder_path=String(e.root_folder_path)),e.region!==void 0&&(this.region=String(e.region)),e.client_id!==void 0&&(this.client_id=String(e.client_id)),e.client_secret!==void 0&&(this.client_secret=String(e.client_secret)),e.tenant_id!==void 0&&(this.tenant_id=String(e.tenant_id)),e.email!==void 0&&(this.email=String(e.email)),e.chunk_size!==void 0&&(this.chunk_size=Number(e.chunk_size)||5),e.custom_host!==void 0&&(this.custom_host=String(e.custom_host)),e.disable_disk_usage!==void 0&&(this.disable_disk_usage=!!e.disable_disk_usage),e.enable_direct_upload!==void 0&&(this.enable_direct_upload=!!e.enable_direct_upload),e.order_by!==void 0&&(this.order_by=String(e.order_by)),e.order_direction!==void 0&&(this.order_direction=String(e.order_direction))),this.onTokenUpdate=r}async init(){typeof this.chunk_size=="string"&&(this.chunk_size=parseInt(this.chunk_size)||5),typeof this.disable_disk_usage=="string"&&(this.disable_disk_usage=this.disable_disk_usage.toLowerCase()==="true"),typeof this.enable_direct_upload=="string"&&(this.enable_direct_upload=this.enable_direct_upload.toLowerCase()==="true"),this.chunk_size<1&&(this.chunk_size=5),this.client_id&&this.client_secret&&this.tenant_id&&await J2(this)}async list(e,r){let n=(await Px(this,r)).map(s=>{let a=z2(s,""),o=s["@microsoft.graph.downloadUrl"]||a.url||"";if(this.custom_host&&o)try{let c=new URL(o);c.host=this.custom_host,o=c.toString()}catch{}return{name:a.name,size:a.size,is_dir:a.isFolder,modified:a.modified,sign:"",type:a.isFolder?1:0,thumb:a.thumbnail||"",raw_url:o}});return le(n,this.order_by,this.order_direction)}async get(e,r){let i=await Fx(this,r),n=z2(i,""),s=i["@microsoft.graph.downloadUrl"]||n.url||"";if(this.custom_host&&s)try{let a=new URL(s);a.host=this.custom_host,s=a.toString()}catch{}return{name:n.name,size:n.size,is_dir:n.isFolder,modified:n.modified,sign:"",type:n.isFolder?1:0,thumb:n.thumbnail||"",raw_url:s}}async mkdir(e,r){let i=r.split("/").slice(0,-1).join("/")||"/",n=r.split("/").filter(Boolean).pop()||"",s=_i(this,!1,i,"children");await Xr(this,s,"POST",{name:n,folder:{},"@microsoft.graph.conflictBehavior":"rename"})}async rename(e,r,i){let n={name:i},s=_i(this,!1,r);await Xr(this,s,"PATCH",n)}async remove(e,r,i){let n=_i(this,!1,r);await Xr(this,n,"DELETE")}async move(e,r,i,n,s){let a=s.split("/").slice(0,-1).join("/")||"/",o=_i(this,!1,a),c=await Xr(this,o,"GET"),u=c.id,l=c.parentReference?.driveId,d={parentReference:{id:u,...l?{driveId:l}:{}},name:s.split("/").filter(Boolean).pop()||""},A=_i(this,!1,n);await Xr(this,A,"PATCH",d)}async copy(e,r,i,n,s){let a=s.split("/").slice(0,-1).join("/")||"/",o=_i(this,!1,a),c=await Xr(this,o,"GET"),u=c.id,l=c.parentReference?.driveId,d={parentReference:{id:u,...l?{driveId:l}:{}},name:s.split("/").filter(Boolean).pop()||""},A=_i(this,!1,n,"copy");await Xr(this,A,"POST",d)}async put(e,r,i){if(i.length<=4*1024*1024){let n=_i(this,!1,r,"content");await Xr(this,n,"PUT",i)}else{let n=_i(this,!1,r,"createUploadSession"),o=(await Xr(this,n,"POST",{item:{"@microsoft.graph.conflictBehavior":"rename"}})).uploadUrl,c=this.chunk_size*1024*1024,u=0,l=i.length;for(;u<l;){let d=l-u,A=Math.min(d,c),g=i.slice(u,u+A);await fetch(o,{method:"PUT",headers:{"Content-Length":String(A),"Content-Range":`bytes ${u}-${u+A-1}/${l}`},body:g}),u+=A}}}async getDetails(){if(this.disable_disk_usage)return{};let e=await Nx(this);return{total:e.quota.total,used:e.quota.used,free:e.quota.remaining}}async getDirectUploadInfo(e){if(!this.enable_direct_upload)throw new Error("Direct upload is not enabled");return Rx(this,e)}}});function _G(t,e){try{let r=new URL(t);if(r.protocol!=="http:"&&r.protocol!=="https:")return!1;let i=r.hostname.toLowerCase().trim();if(!i)return!1;if(e&&new Set(e).has(i))return!0;let n=["localhost",".localhost",".local",".internal","metadata.google.internal","169.254.169.254","metadata.azure.com","metadata"];for(let u of n)if(i===u||i.endsWith(u))return!1;let s=["::1","[::1]","::ffff:127.","::ffff:10.","::ffff:172.","::ffff:192.168.","::ffff:169.254.","fe80:","fc00:","fd00:","[fe80:","[fc","[fd"];for(let u of s)if(i.includes(u))return!1;if(/^\d{1,3}(\.\d{1,3}){1,3}$/.test(i)&&/(^|\.)0\d+/.test(i))return!1;let a=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/,o=i.match(a);if(o){let[,u,l,d,A]=o,g=parseInt(u,10),f=parseInt(l,10),p=parseInt(d,10),y=parseInt(A,10);if(g>255||f>255||p>255||y>255||g===0||g===127||g===10||g===172&&f>=16&&f<=31||g===192&&f===168||g===169&&f===254||g===100&&f>=64&&f<=127||g===100&&f===100||g===224&&f===0&&p===0||g>=240)return!1}if(/^\d{8,}$/.test(i)||/^0x[0-9a-fA-F]{6,}$/i.test(i))return!1;let c=[/(^|\.)\d{1,3}-\d{1,3}-\d{1,3}-\d{1,3}(\.|$)/,/(^|\.)0x[0-9a-f]{6,8}(\.|$)/i,/(^|\.)\d{8,}(\.|$)/,/(^|\.)127\.0\.0\.1\.nip\.io$/,/(^|\.)localtest\.me$/,/(^|\.)vcap\.me$/,/(^|\.)xip\.io$/];for(let u of c)if(u.test(i))return!1;return!0}catch{return!1}}function Rr(t,e="Request",r){if(!_G(t,r))throw new Error(`${e} blocked: URL points to a restricted or private network destination (SSRF protection)`)}function QG(t){let e=new Set;if(t==null)return e;let r=t;if(typeof t=="string")try{r=JSON.parse(t)}catch{return e}if(typeof r!="object"||Array.isArray(r))return e;let i=/(url|host|address|endpoint|server|domain|site|base|gateway|api)/i,n=s=>{if(!(s==null||typeof s!="object"))for(let[a,o]of Object.entries(s))if(typeof o=="string"){if(i.test(a)){let c=Mx(o);c&&e.add(c)}}else o!=null&&typeof o=="object"&&n(o)};return n(r),e}function Mx(t){let e=t.trim();if(!e)return;let r=/^[a-z][a-z0-9+.-]*:\/\//i.test(e)?[e]:[`http://${e}`];for(let i of r)try{let n=new URL(i);if(n.protocol!=="http:"&&n.protocol!=="https:")continue;let s=n.hostname.toLowerCase().trim();if(s)return s}catch{}}function TG(t){let e=new Set;if(!t)return e;for(let r of t.split(/[,;\s]+/)){let i=Mx(r);i&&e.add(i)}return e}function zf(t,e){let r=QG(t),i=e?.SSRF_ALLOWED_HOSTS??(typeof process<"u"?process.env?.SSRF_ALLOWED_HOSTS:void 0);if(typeof i=="string"&&i.trim())for(let n of TG(i))r.add(n);return r}var Zo=G(()=>{"use strict"});var PG,FG,NG,Jf,Lx=G(()=>{"use strict";Zo();PG="https://openapi.aliyundrive.com/adrive/v1.0",FG=15e3,NG=6e4,Jf=class t{addition;accessToken="";refreshTokenVal="";driveId="";tokenExpiresAt=0;listCache=new Map;downloadUrlCache=new Map;static DOWNLOAD_URL_TTL_MS=3e3*1e3;fileDetailCache=new Map;static FILE_DETAIL_TTL_MS=600*1e3;constructor(e){this.addition=e,this.refreshTokenVal=e.refresh_token||"",this.driveId=e.drive_id||""}async init(){if(!this.refreshTokenVal||!this.refreshTokenVal.trim()){console.warn("[AliyundriveOpen] refresh_token is empty, skipping init.");return}try{await this.refreshAccessToken(),this.driveId||await this.resolveDriveId()}catch(e){console.warn("[AliyundriveOpen] init warning:",e.message)}}async resolveDriveId(e=!1){if(!e&&this.addition.drive_id&&this.addition.drive_id.trim()){this.driveId=this.addition.drive_id.trim();return}try{let r=await this.openApiRequest("/user/getDriveInfo",{}),i=e?"resource":this.addition.drive_type||"resource",n="";i==="resource"&&r.resource_drive_id?n=r.resource_drive_id:i==="backup"&&r.backup_drive_id?n=r.backup_drive_id:i==="default"&&r.default_drive_id&&(n=r.default_drive_id),n||(n=r.resource_drive_id||r.default_drive_id||r.backup_drive_id||""),this.driveId=n,console.log(`[AliyundriveOpen] Resolved drive_id: ${this.driveId} (driveType: ${i})`)}catch(r){console.warn("[AliyundriveOpen] resolveDriveId failed:",r.message)}}async refreshAccessToken(){if(!this.refreshTokenVal||!this.refreshTokenVal.trim())return;let e=this.refreshTokenVal.trim(),r=[];if(this.addition.api_url_address&&this.addition.api_url_address.trim()){let a=this.addition.api_url_address.trim();try{Rr(a,"AliyundriveOpen api_url_address"),r.push(a)}catch(o){console.warn(`[AliyundriveOpen] Skipping unsafe api_url_address: ${o.message}`)}}r.push("https://api.oplist.org/alicloud/renewapi","https://api.oplist.org/ali_open/token","https://api.oplist.org/aliyundrive/token","https://api.alist.nn.ci/alist/ali_open/token","https://api.alist.nn.ci/aliyundrive/token","https://api-sam.oplist.org/aliyundrive/token");let i=this.addition.alipan_type==="alipanTV"?"alicloud_tv":"alicloud_qr";for(let a of r)try{let o=new URLSearchParams({refresh_ui:e,refresh_token:e,server_use:"true",driver_txt:i}),c=await fetch(`${a}?${o.toString()}`,{method:"GET",headers:{"Content-Type":"application/json"}});if(!c.ok)throw new Error(`[Status ${c.status}]`);let u=await c.json(),l=u.refresh_token||u.data?.refresh_token||"",d=u.access_token||u.data?.access_token||"";if(!d)throw new Error(`Empty access_token from online API: ${JSON.stringify(u)}`);this.accessToken=d,l&&(this.refreshTokenVal=l),this.tokenExpiresAt=Date.now()+(u.expires_in||7200)*1e3-6e4;return}catch(o){console.warn(`[AliyundriveOpen] Online API '${a}' failed: ${o.message}`)}let n=(this.addition.client_id||"").trim()||"25ab4837190e48718a28f80073574a4d",s=(this.addition.client_secret||"").trim();try{let a={grant_type:"refresh_token",refresh_token:e,client_id:n};s&&(a.client_secret=s);let o=await fetch("https://openapi.aliyundrive.com/oauth/access_token",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!o.ok){let u=await o.text().catch(()=>"");throw new Error(`[Status ${o.status}] ${u}`)}let c=await o.json();if(!c.access_token)throw new Error(`Invalid response: ${JSON.stringify(c)}`);this.accessToken=c.access_token,c.refresh_token&&(this.refreshTokenVal=c.refresh_token),this.tokenExpiresAt=Date.now()+(c.expires_in||7200)*1e3-6e4;return}catch(a){console.warn(`[AliyundriveOpen] Direct OAuth failed: ${a.message}`)}throw new Error("[AliyundriveOpen] All token refresh strategies failed. Please check: 1) refresh_token is valid and not expired, 2) api_url_address is accessible, 3) If using direct OAuth, client_id and client_secret are correct.")}async ensureToken(){(!this.accessToken||Date.now()>=this.tokenExpiresAt)&&await this.refreshAccessToken()}getRootFolderId(){return this.addition.root_folder_id?.trim()||"root"}async openApiRequest(e,r,i=!0){await this.ensureToken();let n=e.startsWith("http")?e:`${PG}${e}`;try{Rr(n,"AliyundriveOpen openApiRequest")}catch(o){throw new Error(`[AliyundriveOpen] blocked unsafe URL: ${o.message}`)}let s=()=>fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.accessToken}`},body:JSON.stringify(r),signal:AbortSignal.timeout(FG)}),a;try{a=await s()}catch(o){if(o?.name==="AbortError"||o?.name==="TimeoutError")await new Promise(c=>setTimeout(c,400)),a=await s();else throw o}if(a.status===401&&i)return await this.refreshAccessToken(),this.openApiRequest(e,r,!1);if(!a.ok){let o=await a.text().catch(()=>"");throw new Error(`[AliyundriveOpen] API error [${a.status}] ${e}: ${o}`)}return a.json()}invalidateListCache(e){e?this.listCache.delete(this.driveId+":"+e):this.listCache.clear()}async listFiles(e){this.driveId||await this.resolveDriveId();let r=this.driveId+":"+e,i=this.listCache.get(r);if(i&&Date.now()-i.at<NG)return i.pages.flatMap(c=>c.items);let n=[],s,a=this.addition.order_by||"updated_at",o=this.addition.order_direction||"DESC";do{let c={drive_id:this.driveId,parent_file_id:e,limit:100,order_by:a,order_direction:o};s&&(c.marker=s);let u;try{u=await this.openApiRequest("/openFile/list",c)}catch(d){if(d.message?.includes("UserNotAllowedAccessDrive"))console.warn(`[AliyundriveOpen] UserNotAllowedAccessDrive for drive ${this.driveId}, auto re-resolving drive_id...`),await this.resolveDriveId(!0),c.drive_id=this.driveId,u=await this.openApiRequest("/openFile/list",c);else throw d}let l=u.items||[];n.push(...l),s=u.next_marker||void 0}while(s);return this.listCache.set(r,{at:Date.now(),pages:[{marker:void 0,items:n}]}),n}async getFile(e){let r=this.fileDetailCache.get(e);if(r&&Date.now()-r.at<t.FILE_DETAIL_TTL_MS)return r.data;this.driveId||await this.resolveDriveId();let i=await this.openApiRequest("/openFile/get",{drive_id:this.driveId,file_id:e});return i&&(this.fileDetailCache.size>3e3&&this.fileDetailCache.clear(),this.fileDetailCache.set(e,{data:i,at:Date.now()})),i}async getDownloadUrl(e){let r=this.downloadUrlCache.get(e);if(r&&Date.now()-r.at<t.DOWNLOAD_URL_TTL_MS)return r.url;let i=await this.openApiRequest("/openFile/getDownloadUrl",{drive_id:this.driveId,file_id:e,expire_sec:14400}),n=i.url||i.download_url||"";return n&&(this.downloadUrlCache.size>2e3&&this.downloadUrlCache.clear(),this.downloadUrlCache.set(e,{url:n,at:Date.now()})),n}async searchFiles(e,r,i,n){this.driveId||await this.resolveDriveId();let s=e.replace(/["\\]/g,""),a=r===1?' and type = "folder"':r===2?' and type = "file"':"",o={drive_id:this.driveId,query:`name match "${s}"${a}`,limit:Math.min(100,Math.max(10,i)),fields:"*"};n&&(o.marker=n);let c;try{c=await this.openApiRequest("/openFile/search",o)}catch(u){if(u.message?.includes("UserNotAllowedAccessDrive"))await this.resolveDriveId(!0),o.drive_id=this.driveId,c=await this.openApiRequest("/openFile/search",o);else throw u}return c}fileMetaCache=new Map;primeFileMeta(e,r,i){e&&(this.fileMetaCache.has(e)||this.fileMetaCache.set(e,{name:String(r||""),parent:String(i||"root")}))}async getFileMeta(e){let r=this.fileMetaCache.get(e);if(r)return r;let i=await this.openApiRequest("/openFile/get",{drive_id:this.driveId,file_id:e,fields:"name,parent_file_id,type,file_id"}),n={name:String(i?.name||""),parent:String(i?.parent_file_id||"root")};return this.fileMetaCache.size>4e3&&this.fileMetaCache.clear(),this.fileMetaCache.set(e,n),n}async getFilePath(e){this.driveId||await this.resolveDriveId();let r=[],i=e,n=new Set;for(let a=0;a<24&&!(!i||i==="root"||n.has(i));a++){n.add(i);let o=await this.getFileMeta(i);if(o.parent==="root")break;r.push(o.parent),i=o.parent}if(!r.length)return"/";let s=[];for(let a=r.length-1;a>=0;a--){let o=await this.getFileMeta(r[a]);o.name&&s.push(o.name)}return s.length?"/"+s.map(a=>a.split("/").map(encodeURIComponent).join("/")).join("/"):"/"}async getVideoPreviewPlayInfo(e){return this.openApiRequest("/openFile/getVideoPreviewPlayInfo",{drive_id:this.driveId,file_id:e,category:"live_transcoding",url_expire_sec:14400})}async probeOpenApi(e,r,i){let n=await this.openApiRequest(e,{drive_id:this.driveId,...r},!1);try{return JSON.parse(JSON.stringify(n,(s,a)=>typeof a=="string"&&a.length>160?a.slice(0,160)+"\u2026":a))}catch{return n}}async mkdir(e,r){await this.openApiRequest("/openFile/create",{drive_id:this.driveId,parent_file_id:e,name:r,type:"folder",check_name_mode:"refuse"})}async rename(e,r){await this.openApiRequest("/openFile/update",{drive_id:this.driveId,file_id:e,name:r,check_name_mode:"refuse"})}async remove(e){let r=this.addition.remove_way||"trash";await this.openApiRequest(r==="trash"?"/openFile/recyclebin":"/openFile/delete",{drive_id:this.driveId,file_id:e})}async move(e,r){await this.openApiRequest("/openFile/move",{drive_id:this.driveId,file_id:e,to_parent_file_id:r,check_name_mode:"refuse"})}async copy(e,r){await this.openApiRequest("/openFile/copy",{drive_id:this.driveId,file_id:e,to_parent_file_id:r,auto_rename:!0})}async putFile(e,r,i){let n=i.length,s=await this.openApiRequest("/openFile/create",{drive_id:this.driveId,parent_file_id:e,name:r,type:"file",size:n,check_name_mode:"auto_rename",part_info_list:[{part_number:1}]}),a=s.part_info_list?.[0]?.upload_url;if(!a)return;let o=await fetch(a,{method:"PUT",body:i});if(!o.ok)throw new Error(`[AliyundriveOpen] Upload failed: ${o.status}`);await this.openApiRequest("/openFile/complete",{drive_id:this.driveId,file_id:s.file_id,upload_id:s.upload_id})}async createMultiPartFile(e,r,i,n){let s=[];for(let a=0;a<n;a++)s.push({part_number:a+1});return this.openApiRequest("/openFile/create",{drive_id:this.driveId,parent_file_id:e,name:r,type:"file",check_name_mode:"auto_rename",size:i,part_info_list:s})}async getPartUploadUrl(e,r,i){return(await this.openApiRequest("/openFile/getUploadUrl",{drive_id:this.driveId,file_id:e,upload_id:r,part_info_list:[{part_number:i}]}))?.part_info_list?.[0]?.upload_url||""}async putPart(e,r){let i=await fetch(e,{method:"PUT",body:r});if(i.status!==200&&i.status!==409){let n=await i.text().catch(()=>"");throw new Error(`[AliyundriveOpen] part upload failed: HTTP ${i.status} ${n}`)}}async completeMultiPartFile(e,r){return this.openApiRequest("/openFile/complete",{drive_id:this.driveId,file_id:e,upload_id:r})}}});function UG(t){return Buffer.from(JSON.stringify(t),"utf8").toString("base64")}function j2(t){let e=JSON.parse(Buffer.from(t,"base64").toString("utf8"));if(!e||!e.file_id||!e.upload_id)throw new Error("[AliyundriveOpen] invalid upload session");return e}function V2(t){let e=t.split("/").filter(Boolean);return e.pop(),"/"+e.join("/")}function Y2(t){let e=t.type==="folder";return{name:t.name,size:t.size||0,is_dir:e,modified:t.updated_at||t.created_at||new Date().toISOString(),sign:"",type:W(t.name,e),thumb:t.thumbnail||"",raw_url:t.download_url||""}}var RG,jf,qx=G(()=>{"use strict";Ee();Me();Lx();RG=10*1024*1024;jf=class{client;addition;pathFileIdCache=new Map;constructor(e){this.addition=e,this.client=new Jf(e)}async init(){await this.client.init()}async list(e,r){let i=await this.resolveFileId(r),s=(await this.client.listFiles(i)).map(Y2);return le(s,this.addition.order_by,this.addition.order_direction)}async search(e,r,i,n){if(!r)return[];let s=[],a,o=0;do{let c=await this.client.searchFiles(r,i,n,a),u=(c.items||[]).slice(0,n-s.length);for(let d of u)this.client.primeFileMeta(d.file_id,d.name,d.parent_file_id);let l=5;for(let d=0;d<u.length;d+=l){let A=u.slice(d,d+l),g=await Promise.all(A.map(async f=>{let p=Y2(f);try{p.parent=await this.client.getFilePath(f.file_id)}catch{p.parent="/"}return p}));s.push(...g)}a=c.next_marker||void 0,o++}while(a&&s.length<n&&o<3);return s}async get(e,r){let i=await this.resolveFileId(r),n=await this.client.getFile(i).catch(()=>null),s=await this.client.getDownloadUrl(i).catch(()=>"");if(n){let c=Y2(n);return c.raw_url=s||c.raw_url,c}try{await this.client.listFiles(i);let c=r.split("/").filter(Boolean);return{name:c[c.length-1]||"root",size:0,is_dir:!0,modified:new Date().toISOString(),sign:"",type:1,raw_url:""}}catch{}let a=r.split("/").filter(Boolean);return{name:a[a.length-1]||"root",size:0,is_dir:!1,modified:new Date().toISOString(),sign:"",type:0,raw_url:s}}async mkdir(e,r){let i=r.split("/").filter(Boolean),n=i.pop()||"\u65B0\u6587\u4EF6\u5939",s="/"+i.join("/"),a=await this.resolveFileId(s);await this.client.mkdir(a,n),this.client.invalidateListCache(a)}async rename(e,r,i){let n=await this.resolveFileId(r),s=await this.resolveFileId(V2(r));await this.client.rename(n,i),this.client.invalidateListCache(s)}async remove(e,r,i){let n=await this.resolveFileId(r),s=await this.resolveFileId(V2(r));await this.client.remove(n),this.client.invalidateListCache(s)}async move(e,r,i,n,s){let a=await this.resolveFileId(n),o=await this.resolveFileId(V2(n)),c=await this.resolveFileId(r);await this.client.move(a,c),this.client.invalidateListCache(o),this.client.invalidateListCache(c)}async copy(e,r,i,n,s){let a=await this.resolveFileId(n),o=await this.resolveFileId(r);await this.client.copy(a,o),this.client.invalidateListCache(o)}async put(e,r,i){let n=r.split("/").filter(Boolean),s=n.pop()||"upload",a="/"+n.join("/"),o=await this.resolveFileId(a);await this.removeExistingFile(o,s),await this.client.putFile(o,s,i),this.client.invalidateListCache(o)}async removeExistingFile(e,r){try{let n=(await this.client.listFiles(e)).find(s=>s.type==="file"&&s.name===r);n&&await this.client.remove(n.file_id)}catch(i){console.warn(`[AliyundriveOpen] overwrite check failed for "${r}":`,i?.message||i)}}async createUploadSession(e,r,i,n,s){let a=RG,o=Math.max(1,Math.ceil(Math.max(0,Number(n)||0)/a)),c=await this.resolveFileId(r||"/");await this.removeExistingFile(c,i);let u=await this.client.createMultiPartFile(c,i,Math.max(0,Number(n)||0),o);if(u.rapid_upload)return this.client.invalidateListCache(c),{reuse:!0,partCount:0,chunkSize:a,session:""};let l=UG({file_id:u.file_id,upload_id:u.upload_id,partCount:o,chunkSize:a});return{reuse:!1,partCount:o,chunkSize:a,session:l}}async uploadPart(e,r,i){let n=j2(e);if(!Number.isInteger(r)||r<1||r>n.partCount)throw new Error(`[AliyundriveOpen] \u5206\u7247\u5E8F\u53F7\u65E0\u6548: ${r}`);let s=await this.client.getPartUploadUrl(n.file_id,n.upload_id,r);if(!s)throw new Error(`[AliyundriveOpen] \u83B7\u53D6\u7B2C ${r} \u7247\u76F4\u4F20\u5730\u5740\u5931\u8D25`);await this.client.putPart(s,i)}async getPartUploadUrl(e,r){let i=j2(e);if(!Number.isInteger(r)||r<1||r>i.partCount)throw new Error(`[AliyundriveOpen] \u5206\u7247\u5E8F\u53F7\u65E0\u6548: ${r}`);let n=await this.client.getPartUploadUrl(i.file_id,i.upload_id,r);if(!n)throw new Error(`[AliyundriveOpen] \u83B7\u53D6\u7B2C ${r} \u7247\u76F4\u4F20\u5730\u5740\u5931\u8D25`);return n}async completeUploadSession(e){let r=j2(e);await this.client.completeMultiPartFile(r.file_id,r.upload_id),this.client.invalidateListCache()}async other(e,r,i){if(e==="video_preview"){let n=await this.resolveFileId(r),s=await this.client.getVideoPreviewPlayInfo(n);return{video_preview_play_info:s?.video_preview_play_info??s}}if(e==="ym_pdf_probe"){let n=await this.resolveFileId(r),s={},a=[["getPreviewPlayInfo:doc_live",{api:"/openFile/getPreviewPlayInfo",body:{file_id:n,category:"doc_live_transcoding"}}],["getPreviewPlayInfo:live",{api:"/openFile/getPreviewPlayInfo",body:{file_id:n,category:"live_transcoding"}}],["videoPlayInfo:doc_live",{api:"/openFile/getVideoPreviewPlayInfo",body:{file_id:n,category:"doc_live_transcoding"}}]];for(let[o,c]of a)try{let u=await this.client.probeOpenApi(c.api,c.body,n);s[o]=u}catch(u){s[o]={error:String(u?.message||u).slice(0,200)}}return s}throw new Error(`[AliyundriveOpen] unsupported other method '${e}'`)}async resolveFileId(e){let r=e.split("/").filter(Boolean).join("/");if(!r)return this.client.getRootFolderId();if(this.pathFileIdCache.has(r))return this.pathFileIdCache.get(r);let i=r.split("/"),n=this.client.getRootFolderId();for(let s=0;s<i.length;s++){let a=i[s],o=(()=>{try{return decodeURIComponent(a)}catch{return a}})(),c=i.slice(0,s+1).join("/");if(this.pathFileIdCache.has(c)){n=this.pathFileIdCache.get(c);continue}let l=(await this.client.listFiles(n)).find(d=>d.name===a||d.name===o||d.file_id===a);if(!l)throw new Error(`[AliyundriveOpen] Path '${a}' not found`);n=l.file_id,this.pathFileIdCache.set(c,n)}return n}}});var kd,Hx,Kx,$2=G(()=>{"use strict";kd="application/vnd.google-apps.folder",Hx="application/vnd.google-apps.shortcut",Kx="files(id,name,mimeType,size,modifiedTime,createdTime,thumbnailLink,shortcutDetails,md5Checksum,sha1Checksum,sha256Checksum),nextPageToken"});var Pa,Gx,OG,Vf,zx=G(()=>{"use strict";$2();Pa="https://www.googleapis.com/drive/v3",Gx="https://www.googleapis.com/upload/drive/v3",OG="https://oauth2.googleapis.com/token",Vf=class{addition;accessToken="";refreshTokenVal="";tokenExpiresAt=0;constructor(e){this.addition=e,this.refreshTokenVal=e.refresh_token||""}getRootFolderId(){return this.addition.root_folder_id?.trim()||"root"}async init(){if(!this.refreshTokenVal||!this.refreshTokenVal.trim()){console.warn("[GoogleDrive] refresh_token is empty, skipping init.");return}try{await this.refreshAccessToken()}catch(e){console.warn("[GoogleDrive] init token refresh warning:",e.message)}}async refreshAccessToken(){let e=this.refreshTokenVal.trim();if(!e)return;let r=this.addition.use_online_api!==!1,i=[];r&&(this.addition.api_url_address?.trim()&&i.push(this.addition.api_url_address.trim()),i.push("https://api.oplist.org/google/token","https://api.oplist.org/google/renewapi","https://api.oplist.org/googledrive/token","https://api-sam.oplist.org/google/token","https://api-sam.oplist.org/googledrive/token","https://api.alist.nn.ci/google/token","https://api.alist.nn.ci/googledrive/token"));for(let a of i)try{let o=new URLSearchParams({refresh_ui:e,server_use:"true",driver_txt:"googleui_go"}),c=await fetch(`${a}?${o.toString()}`,{method:"GET"});if(!c.ok)throw new Error(`[Status ${c.status}]`);let u=await c.json(),l=u.access_token||u.data?.access_token||"",d=u.refresh_token||u.data?.refresh_token||"";if(!l){let A=u.text||u.error||"empty access_token";throw new Error(A)}this.accessToken=l,d&&(this.refreshTokenVal=d),this.tokenExpiresAt=Date.now()+(u.expires_in||3600)*1e3-6e4;return}catch(o){console.warn(`[GoogleDrive] Online API '${a}' failed: ${o.message}`)}let n=(this.addition.client_id||"").trim()||"202264815644-2n82p2e49c7o6026u87j9e22v1n25c27.apps.googleusercontent.com",s=(this.addition.client_secret||"").trim()||"GOCSPX-4bH5Kx3s_89_j6j2x-2x3-8x";if(n&&s)try{let a=await fetch(OG,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({client_id:n,client_secret:s,refresh_token:e,grant_type:"refresh_token"}).toString()});if(!a.ok){let c=await a.text().catch(()=>"");throw new Error(`[Status ${a.status}] ${c}`)}let o=await a.json();if(!o.access_token)throw new Error(`Invalid OAuth response: ${JSON.stringify(o)}`);this.accessToken=o.access_token,o.refresh_token&&(this.refreshTokenVal=o.refresh_token),this.tokenExpiresAt=Date.now()+(o.expires_in||3600)*1e3-6e4;return}catch(a){console.warn(`[GoogleDrive] Direct OAuth failed: ${a.message}`)}throw new Error("[GoogleDrive] All token refresh strategies failed. Please check: 1) refresh_token is valid, 2) api_url_address is accessible, 3) If using direct OAuth: client_id and client_secret are correct.")}async ensureToken(){(!this.accessToken||Date.now()>=this.tokenExpiresAt)&&await this.refreshAccessToken()}async request(e,r={},i=!0){await this.ensureToken();let n=await fetch(e,{...r,headers:{Authorization:`Bearer ${this.accessToken}`,...r.headers||{}}});if(n.status===401&&i)return console.warn("[GoogleDrive] 401 Unauthorized, refreshing token..."),await this.refreshAccessToken(),this.request(e,r,!1);if(!n.ok){let s=await n.text().catch(()=>"");throw new Error(`[GoogleDrive] API error [${n.status}]: ${s}`)}return n.status===204?null:n.json()}async listFiles(e){let r=[],i,n=this.addition.order_by||"folder,name,modifiedTime desc";do{let s=new URLSearchParams({q:`'${e}' in parents and trashed = false`,fields:Kx,orderBy:n,pageSize:"1000",includeItemsFromAllDrives:"true",supportsAllDrives:"true"});i&&s.set("pageToken",i);let a=`${Pa}/files?${s.toString()}`,o=await this.request(a),c=o.files||[];for(let u of c)u.mimeType===Hx&&u.shortcutDetails?.targetId&&(u.id=u.shortcutDetails.targetId,u.mimeType=u.shortcutDetails.targetMimeType||u.mimeType);r.push(...c),i=o.nextPageToken}while(i);return r}async getFile(e){let r=new URLSearchParams({fields:"id,name,mimeType,size,modifiedTime,md5Checksum",includeItemsFromAllDrives:"true",supportsAllDrives:"true"});return this.request(`${Pa}/files/${e}?${r.toString()}`)}getDownloadUrl(e){return`${Pa}/files/${e}?includeItemsFromAllDrives=true&supportsAllDrives=true&alt=media&acknowledgeAbuse=true`}getDownloadHeaders(){return{Authorization:`Bearer ${this.accessToken}`}}async mkdir(e,r){await this.request(`${Pa}/files?supportsAllDrives=true`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:r,parents:[e],mimeType:kd})})}async rename(e,r){await this.request(`${Pa}/files/${e}?supportsAllDrives=true`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:r})})}async remove(e){await this.request(`${Pa}/files/${e}?supportsAllDrives=true`,{method:"DELETE"})}async move(e,r,i){let n=new URLSearchParams({addParents:i,removeParents:r,supportsAllDrives:"true"});await this.request(`${Pa}/files/${e}?${n.toString()}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:"{}"})}async copy(e,r,i){await this.request(`${Pa}/files/${e}/copy?supportsAllDrives=true`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:i,parents:[r]})})}async putFile(e,r,i,n="application/octet-stream"){let s=(this.addition.chunk_size||5)*1024*1024;if(i.length<=s){let a=new URLSearchParams({uploadType:"multipart",supportsAllDrives:"true"}),o=`----GoogleDriveBoundary${Date.now()}`,c=JSON.stringify({name:r,parents:[e]}),u=`--${o}\r
|
|
52
|
+
`)[0].trim()}return""}function Cx(t){if(!t)return!1;let e=t.disable_proxy_sign??t.disableProxySign;return typeof e=="string"?e.toLowerCase()==="true":!!e}function Bx(t,e){let r=t?.web_proxy??t?.webProxy;return r===!0||r==="true"?!0:r===!1||r==="false"?!1:q2(e)}function bx(t,e,r,i={}){let n=$o(e);if(qf(t,n))return{mode:"native_proxy",needsProxy:!0,source:"force"};if(Bx(t,n))return{mode:"native_proxy",needsProxy:!0,source:"web_proxy"};if(r)return{mode:"native_proxy",needsProxy:!0,source:"proxy_path"};if(L2(yx(i.filename),i.proxyTypes))return{mode:"native_proxy",needsProxy:!0,source:"proxy_types"};let s=wx(t);return s?{mode:s,needsProxy:s!=="302_redirect",source:"storage_policy"}:{mode:"302_redirect",needsProxy:!1,source:"driver_default"}}function L2(t,e){return t?Wo(e).includes(t):!1}function Hf(t){let e=$o(t.driver);if(qf(t.storage,e)||Bx(t.storage,e)||wx(t.storage)==="use_proxy_url")return!0;let r=yx(t.filename);return r?L2(r,t.proxyTypes)||L2(r,t.textTypes):!1}var px,SG,mx,vG,xd=G(()=>{"use strict";vd();px=new Set(["weiyun","sftp","ftp","smb","crypt","virtual","strm","meganz","protondrive","chunk","googledrive","googlephoto","quarkopen","quarkuc","chaoxing","local"]),SG=new Set(["webdav","baidunetdisk","123pan","123open","123panshare"]),mx=new Set(["139yun","alias","alistv3","openlist"]),vG=["down_proxy_url","download_proxy_url","proxy_url"]});function W(t,e){if(e)return 1;let r=(t.split(".").pop()||"").toLowerCase();return["mp4","mkv","avi","mov","flv","wmv","ts","m2ts","m4v","rmvb","webm","3gp","asf","vob","ogv","rm","f4v"].includes(r)?2:["mp3","flac","aac","wav","ogg","m4a","opus","wma","ape","alac","aiff","mid","midi"].includes(r)?3:["txt","md","markdown","json","js","ts","jsx","tsx","css","scss","html","htm","xml","yaml","yml","ini","conf","env","log","sql","py","java","c","cpp","h","hpp","go","rs","sh","bat","cmd","ps1","php","rb","swift","kt","cs","vue","svelte","json5","toml"].includes(r)?4:["jpg","jpeg","png","gif","bmp","webp","svg","ico","tiff","tif","heic","heif","avif","vvc","avc","psd","ai"].includes(r)?5:0}var Ee=G(()=>{"use strict"});function le(t,e,r){let i=r!=="desc",n=String(e||"name").toLowerCase(),s=[...t];return s.sort((a,o)=>{if(a.is_dir!==o.is_dir)return a.is_dir?-1:1;let c;return n.includes("size")?c=(a.size||0)-(o.size||0):n.includes("time")||n.includes("modified")||n.includes("created")?c=new Date(a.modified).getTime()-new Date(o.modified).getTime():c=String(a.name).localeCompare(String(o.name)),i?c:-c}),s}var Me=G(()=>{"use strict"});var Ln,H2=G(()=>{"use strict";Ln={global:{oauth:"https://login.microsoftonline.com",api:"https://graph.microsoft.com"},cn:{oauth:"https://login.partner.microsoftonline.cn",api:"https://microsoftgraph.chinacloudapi.cn"},us:{oauth:"https://login.microsoftonline.us",api:"https://graph.microsoft.us"},de:{oauth:"https://login.microsoftonline.de",api:"https://graph.microsoft.de"}}});function K2(t,e){let r="";return t.thumbnails&&t.thumbnails.length>0&&(r=t.thumbnails[0].medium?.url||""),{id:t.id,name:t.name,size:t.size,modified:t.lastModifiedDateTime||t.fileSystemInfo?.lastModifiedDateTime||"",isFolder:!!t.folder||!t.file,thumbnail:r,parentID:e,url:t["@microsoft.graph.downloadUrl"]||""}}var Dx=G(()=>{"use strict"});async function G2(t){if(t.use_online_api&&t.api_url_address){let s=new URLSearchParams({refresh_ui:t.refresh_token,server_use:"true",driver_txt:"onedrive_pr"}).toString(),o=await(await fetch(`${t.api_url_address}?${s}`)).json();if(!o.refresh_token||!o.access_token)throw o.text?new Error(`failed to refresh token: ${o.text}`):new Error("empty token returned from official API");t.accessToken=o.access_token,t.refresh_token=o.refresh_token,await t.onTokenUpdate?.(t.refresh_token);return}if(!t.client_id||!t.client_secret)throw new Error("empty ClientID or ClientSecret");let r=`${(Ln[t.region]||Ln.global).oauth}/common/oauth2/v2.0/token`,n=await(await fetch(r,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"refresh_token",client_id:t.client_id,client_secret:t.client_secret,redirect_uri:t.redirect_uri,refresh_token:t.refresh_token}).toString()})).json();if(!n.refresh_token)throw new Error("Empty token");t.refresh_token=n.refresh_token,t.accessToken=n.access_token,await t.onTokenUpdate?.(t.refresh_token)}async function ki(t,e,r,i,n){let s=i!==void 0&&(i instanceof Uint8Array||i instanceof ArrayBuffer||typeof Buffer<"u"&&Buffer.isBuffer(i)),a={method:r.toUpperCase(),headers:{Authorization:`Bearer ${t.accessToken}`,...i!==void 0?{"Content-Type":s?"application/octet-stream":"application/json"}:{}},...i!==void 0?{body:s?i:JSON.stringify(i)}:{}},o=await fetch(e,a);if(!o.ok){let c;try{c=(await o.json()).error}catch{c=null}let u=c?.code;if((u==="InvalidAuthenticationToken"||u==="ExpiredAuthenticationToken"||o.status===401)&&!n)return await G2(t),ki(t,e,r,i,!0);throw new Error(c?.message||`Request failed: ${o.status}`)}if(o.status!==204)return o.json()}function Sx(t,e,r){let i=e.replace(/\\/g,"/");if(!i||i==="/")return r?`${t}/drive/root/${r}`:`${t}/drive/root`;let n=i.startsWith("/")?i.slice(1):i;if(n.endsWith("/")&&(n=n.slice(0,-1)),!n||n==="")return r?`${t}/drive/root/${r}`:`${t}/drive/root`;let s=n.split("/").map(encodeURIComponent).join("/");return r?`${t}/drive/root:/${s}:/${r}`:`${t}/drive/root:/${s}:`}async function vx(t,e){let r=Ln[t.region]||Ln.global,i=t.is_sharepoint?`${r.api}/v1.0/sites/${t.site_id}`:`${r.api}/v1.0/me`,s=Sx(i,e,"children?$top=1000&$expand=thumbnails($select=medium)&$select=id,name,size,fileSystemInfo,@microsoft.graph.downloadUrl,file,folder,parentReference"),a=[];for(;s;){let o=await ki(t,s,"GET");o.value&&a.push(...o.value),s=o["@odata.nextLink"]}return a}async function xx(t,e){let r=Ln[t.region]||Ln.global,i=t.is_sharepoint?`${r.api}/v1.0/sites/${t.site_id}`:`${r.api}/v1.0/me`,n=Sx(i,e);return ki(t,n,"GET")}var kx=G(()=>{"use strict";H2()});var Kf,_x=G(()=>{"use strict";Me();H2();Dx();kx();Kf=class{root_folder_path="/";region="global";is_sharepoint=!1;use_online_api=!0;api_url_address="https://api.oplist.org/onedrive/renewapi";client_id="";client_secret="";redirect_uri="https://api.oplist.org/onedrive/callback";refresh_token="";site_id="";chunk_size=5;custom_host="";disable_disk_usage=!1;enable_direct_upload=!1;order_by="filename";order_direction="asc";accessToken="";onTokenUpdate;constructor(e,r){e&&(e.root_folder_path!==void 0&&(this.root_folder_path=String(e.root_folder_path)),e.region!==void 0&&(this.region=String(e.region)),e.is_sharepoint!==void 0&&(this.is_sharepoint=!!e.is_sharepoint),e.use_online_api!==void 0&&(this.use_online_api=!!e.use_online_api),e.api_url_address!==void 0&&(this.api_url_address=String(e.api_url_address)),e.client_id!==void 0&&(this.client_id=String(e.client_id)),e.client_secret!==void 0&&(this.client_secret=String(e.client_secret)),e.redirect_uri!==void 0&&(this.redirect_uri=String(e.redirect_uri)),e.refresh_token!==void 0&&(this.refresh_token=String(e.refresh_token)),e.site_id!==void 0&&(this.site_id=String(e.site_id)),e.chunk_size!==void 0&&(this.chunk_size=Number(e.chunk_size)||5),e.custom_host!==void 0&&(this.custom_host=String(e.custom_host)),e.disable_disk_usage!==void 0&&(this.disable_disk_usage=!!e.disable_disk_usage),e.enable_direct_upload!==void 0&&(this.enable_direct_upload=!!e.enable_direct_upload),e.order_by!==void 0&&(this.order_by=String(e.order_by)),e.order_direction!==void 0&&(this.order_direction=String(e.order_direction))),this.onTokenUpdate=r}async init(){typeof this.is_sharepoint=="string"&&(this.is_sharepoint=this.is_sharepoint.toLowerCase()==="true"),typeof this.use_online_api=="string"&&(this.use_online_api=this.use_online_api.toLowerCase()==="true"),typeof this.chunk_size=="string"&&(this.chunk_size=parseInt(this.chunk_size)||5),typeof this.disable_disk_usage=="string"&&(this.disable_disk_usage=this.disable_disk_usage.toLowerCase()==="true"),typeof this.enable_direct_upload=="string"&&(this.enable_direct_upload=this.enable_direct_upload.toLowerCase()==="true"),this.chunk_size<1&&(this.chunk_size=5),this.refresh_token&&await G2(this)}getMetaUrl(e,r,i){let n=Ln[this.region]||Ln.global;if(e)return n.oauth;let s=this.is_sharepoint?`${n.api}/v1.0/sites/${this.site_id}`:`${n.api}/v1.0/me`,a=r.replace(/\\/g,"/");if(!a||a==="/")return i?`${s}/drive/root/${i}`:`${s}/drive/root`;let o=a.startsWith("/")?a.slice(1):a;if(o.endsWith("/")&&(o=o.slice(0,-1)),!o||o==="")return i?`${s}/drive/root/${i}`:`${s}/drive/root`;let c=o.split("/").map(u=>{try{return encodeURIComponent(decodeURIComponent(u))}catch{return encodeURIComponent(u)}}).join("/");return i?`${s}/drive/root:/${c}:/${i}`:`${s}/drive/root:/${c}:`}async list(e,r){let n=(await vx(this,r)).map(s=>{let a=K2(s,""),o=s["@microsoft.graph.downloadUrl"]||a.url||"";if(this.custom_host&&o)try{let c=new URL(o);c.host=this.custom_host,o=c.toString()}catch{}return{name:a.name,size:a.size,is_dir:a.isFolder,modified:a.modified,sign:"",type:a.isFolder?1:0,thumb:a.thumbnail||"",raw_url:o}});return le(n,this.order_by,this.order_direction)}async get(e,r){let i=await xx(this,r),n=K2(i,""),s=i["@microsoft.graph.downloadUrl"]||n.url||"";if(this.custom_host&&s)try{let a=new URL(s);a.host=this.custom_host,s=a.toString()}catch{}return{name:n.name,size:n.size,is_dir:n.isFolder,modified:n.modified,sign:"",type:n.isFolder?1:0,thumb:n.thumbnail||"",raw_url:s}}async mkdir(e,r){let i=r.split("/").slice(0,-1).join("/")||"/",n=r.split("/").filter(Boolean).pop()||"",s=this.getMetaUrl(!1,i,"children");await ki(this,s,"POST",{name:n,folder:{},"@microsoft.graph.conflictBehavior":"rename"})}async rename(e,r,i){let n={name:i},s=this.getMetaUrl(!1,r);await ki(this,s,"PATCH",n)}async remove(e,r,i){let n=this.getMetaUrl(!1,r);await ki(this,n,"DELETE")}async move(e,r,i,n,s){let a=s.split("/").slice(0,-1).join("/")||"/",o=this.getMetaUrl(!1,a),c=await ki(this,o,"GET"),u=c.id,l=c.parentReference?.driveId,d={parentReference:{id:u,...l?{driveId:l}:{}},name:s.split("/").filter(Boolean).pop()||""},A=this.getMetaUrl(!1,n);await ki(this,A,"PATCH",d)}async copy(e,r,i,n,s){let a=s.split("/").slice(0,-1).join("/")||"/",o=this.getMetaUrl(!1,a),c=await ki(this,o,"GET"),u=c.id,l=c.parentReference?.driveId,d={parentReference:{id:u,...l?{driveId:l}:{}},name:s.split("/").filter(Boolean).pop()||""},A=this.getMetaUrl(!1,n,"copy");await ki(this,A,"POST",d)}async put(e,r,i){if(i.length<=4*1024*1024){let n=this.getMetaUrl(!1,r,"content");await ki(this,n,"PUT",i)}else{let n=this.getMetaUrl(!1,r,"createUploadSession"),o=(await ki(this,n,"POST",{item:{"@microsoft.graph.conflictBehavior":"rename"}})).uploadUrl,c=this.chunk_size*1024*1024,u=0,l=i.length;for(;u<l;){let d=l-u,A=Math.min(d,c),g=i.slice(u,u+A);await fetch(o,{method:"PUT",headers:{"Content-Length":String(A),"Content-Range":`bytes ${u}-${u+A-1}/${l}`},body:g}),u+=A}}}}});function z2(t,e){let r="";return t.thumbnails&&t.thumbnails.length>0&&(r=t.thumbnails[0].medium?.url||""),{id:t.id,name:t.name,size:t.size,modified:t.lastModifiedDateTime||t.fileSystemInfo?.lastModifiedDateTime||"",isFolder:!!t.folder||!t.file,thumbnail:r,parentID:e,url:t["@microsoft.graph.downloadUrl"]||""}}var Qx=G(()=>{"use strict"});var Xo,Tx=G(()=>{"use strict";Xo={global:{oauth:"https://login.microsoftonline.com",api:"https://graph.microsoft.com"},cn:{oauth:"https://login.chinacloudapi.cn",api:"https://microsoftgraph.chinacloudapi.cn"},us:{oauth:"https://login.microsoftonline.us",api:"https://graph.microsoft.us"},de:{oauth:"https://login.microsoftonline.de",api:"https://graph.microsoft.de"}}});function _i(t,e,r,i){let n=Xo[t.region]||Xo.global;if(e)return n.oauth;let s=r?r.replace(/\\/g,"/"):"";if(!s||s==="/")return i?`${n.api}/v1.0/users/${t.email}/drive/root/${i}`:`${n.api}/v1.0/users/${t.email}/drive/root`;let a=s.startsWith("/")?s.slice(1):s;if(a.endsWith("/")&&(a=a.slice(0,-1)),!a||a==="")return i?`${n.api}/v1.0/users/${t.email}/drive/root/${i}`:`${n.api}/v1.0/users/${t.email}/drive/root`;let o=a.split("/").map(c=>{try{return encodeURIComponent(decodeURIComponent(c))}catch{return encodeURIComponent(c)}}).join("/");return i?`${n.api}/v1.0/users/${t.email}/drive/root:/${o}:/${i}`:`${n.api}/v1.0/users/${t.email}/drive/root:/${o}:`}async function J2(t){let e=null;for(let r=0;r<3;r++)try{await kG(t);return}catch(i){e=i}throw e||new Error("Failed to get access token")}async function kG(t){if(!t.client_id||!t.client_secret)throw new Error("empty client_id or client_secret");if(!t.tenant_id)throw new Error("empty tenant_id");let e=Xo[t.region]||Xo.global,r=`${e.oauth}/${t.tenant_id}/oauth2/token`,i=new URLSearchParams({grant_type:"client_credentials",client_id:t.client_id,client_secret:t.client_secret,resource:`${e.api}/`,scope:`${e.api}/.default`}).toString(),s=await(await fetch(r,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:i})).json();if(s.error)throw new Error(s.error_description||s.error);if(!s.access_token)throw new Error("empty token returned from Microsoft identity platform");t.accessToken=s.access_token,t.onTokenUpdate?.(t.accessToken)}async function Xr(t,e,r,i,n){let s=i!==void 0&&(typeof i=="string"||i instanceof Uint8Array||i instanceof ArrayBuffer||typeof Buffer<"u"&&Buffer.isBuffer(i)),a={method:r.toUpperCase(),headers:{Authorization:`Bearer ${t.accessToken}`,...i!==void 0&&!s?{"Content-Type":"application/json"}:{}},...i!==void 0?{body:s?i:JSON.stringify(i)}:{}},o=await fetch(e,a);if(!o.ok){let c;try{c=(await o.json()).error}catch{c=null}let u=c?.code;if((u==="InvalidAuthenticationToken"||u==="ExpiredAuthenticationToken"||o.status===401)&&!n)return await J2(t),Xr(t,e,r,i,!0);throw new Error(c?.message||`Request failed: ${o.status}`)}if(o.status!==204)return o.json()}async function Px(t,e){let i=_i(t,!1,e,"children?$top=1000&$expand=thumbnails($select=medium)&$select=id,name,size,fileSystemInfo,lastModifiedDateTime,@microsoft.graph.downloadUrl,file,folder,parentReference"),n=[];for(;i;){let s=await Xr(t,i,"GET");s.value&&n.push(...s.value),i=s["@odata.nextLink"]}return n}async function Fx(t,e){let r=_i(t,!1,e);return Xr(t,r,"GET")}async function Nx(t){let r=`${(Xo[t.region]||Xo.global).api}/v1.0/users/${t.email}/drive`;return Xr(t,r,"GET",void 0,!0)}async function Rx(t,e){let r=_i(t,!1,e,"createUploadSession"),s=(await Xr(t,r,"POST",{item:{"@microsoft.graph.conflictBehavior":"rename"}})).uploadUrl;if(!s)throw new Error("failed to get upload URL from response");return{UploadURL:s,ChunkSize:(t.chunk_size||5)*1024*1024,Method:"PUT"}}var Ux=G(()=>{"use strict";Tx()});var Gf,Ox=G(()=>{"use strict";Me();Qx();Ux();Gf=class{root_folder_path="/";region="global";client_id="";client_secret="";tenant_id="";email="";chunk_size=5;custom_host="";disable_disk_usage=!1;enable_direct_upload=!1;order_by="filename";order_direction="asc";accessToken="";onTokenUpdate;constructor(e,r){e&&(e.root_folder_path!==void 0&&(this.root_folder_path=String(e.root_folder_path)),e.region!==void 0&&(this.region=String(e.region)),e.client_id!==void 0&&(this.client_id=String(e.client_id)),e.client_secret!==void 0&&(this.client_secret=String(e.client_secret)),e.tenant_id!==void 0&&(this.tenant_id=String(e.tenant_id)),e.email!==void 0&&(this.email=String(e.email)),e.chunk_size!==void 0&&(this.chunk_size=Number(e.chunk_size)||5),e.custom_host!==void 0&&(this.custom_host=String(e.custom_host)),e.disable_disk_usage!==void 0&&(this.disable_disk_usage=!!e.disable_disk_usage),e.enable_direct_upload!==void 0&&(this.enable_direct_upload=!!e.enable_direct_upload),e.order_by!==void 0&&(this.order_by=String(e.order_by)),e.order_direction!==void 0&&(this.order_direction=String(e.order_direction))),this.onTokenUpdate=r}async init(){typeof this.chunk_size=="string"&&(this.chunk_size=parseInt(this.chunk_size)||5),typeof this.disable_disk_usage=="string"&&(this.disable_disk_usage=this.disable_disk_usage.toLowerCase()==="true"),typeof this.enable_direct_upload=="string"&&(this.enable_direct_upload=this.enable_direct_upload.toLowerCase()==="true"),this.chunk_size<1&&(this.chunk_size=5),this.client_id&&this.client_secret&&this.tenant_id&&await J2(this)}async list(e,r){let n=(await Px(this,r)).map(s=>{let a=z2(s,""),o=s["@microsoft.graph.downloadUrl"]||a.url||"";if(this.custom_host&&o)try{let c=new URL(o);c.host=this.custom_host,o=c.toString()}catch{}return{name:a.name,size:a.size,is_dir:a.isFolder,modified:a.modified,sign:"",type:a.isFolder?1:0,thumb:a.thumbnail||"",raw_url:o}});return le(n,this.order_by,this.order_direction)}async get(e,r){let i=await Fx(this,r),n=z2(i,""),s=i["@microsoft.graph.downloadUrl"]||n.url||"";if(this.custom_host&&s)try{let a=new URL(s);a.host=this.custom_host,s=a.toString()}catch{}return{name:n.name,size:n.size,is_dir:n.isFolder,modified:n.modified,sign:"",type:n.isFolder?1:0,thumb:n.thumbnail||"",raw_url:s}}async mkdir(e,r){let i=r.split("/").slice(0,-1).join("/")||"/",n=r.split("/").filter(Boolean).pop()||"",s=_i(this,!1,i,"children");await Xr(this,s,"POST",{name:n,folder:{},"@microsoft.graph.conflictBehavior":"rename"})}async rename(e,r,i){let n={name:i},s=_i(this,!1,r);await Xr(this,s,"PATCH",n)}async remove(e,r,i){let n=_i(this,!1,r);await Xr(this,n,"DELETE")}async move(e,r,i,n,s){let a=s.split("/").slice(0,-1).join("/")||"/",o=_i(this,!1,a),c=await Xr(this,o,"GET"),u=c.id,l=c.parentReference?.driveId,d={parentReference:{id:u,...l?{driveId:l}:{}},name:s.split("/").filter(Boolean).pop()||""},A=_i(this,!1,n);await Xr(this,A,"PATCH",d)}async copy(e,r,i,n,s){let a=s.split("/").slice(0,-1).join("/")||"/",o=_i(this,!1,a),c=await Xr(this,o,"GET"),u=c.id,l=c.parentReference?.driveId,d={parentReference:{id:u,...l?{driveId:l}:{}},name:s.split("/").filter(Boolean).pop()||""},A=_i(this,!1,n,"copy");await Xr(this,A,"POST",d)}async put(e,r,i){if(i.length<=4*1024*1024){let n=_i(this,!1,r,"content");await Xr(this,n,"PUT",i)}else{let n=_i(this,!1,r,"createUploadSession"),o=(await Xr(this,n,"POST",{item:{"@microsoft.graph.conflictBehavior":"rename"}})).uploadUrl,c=this.chunk_size*1024*1024,u=0,l=i.length;for(;u<l;){let d=l-u,A=Math.min(d,c),g=i.slice(u,u+A);await fetch(o,{method:"PUT",headers:{"Content-Length":String(A),"Content-Range":`bytes ${u}-${u+A-1}/${l}`},body:g}),u+=A}}}async getDetails(){if(this.disable_disk_usage)return{};let e=await Nx(this);return{total:e.quota.total,used:e.quota.used,free:e.quota.remaining}}async getDirectUploadInfo(e){if(!this.enable_direct_upload)throw new Error("Direct upload is not enabled");return Rx(this,e)}}});function _G(t,e){try{let r=new URL(t);if(r.protocol!=="http:"&&r.protocol!=="https:")return!1;let i=r.hostname.toLowerCase().trim();if(!i)return!1;if(e&&new Set(e).has(i))return!0;let n=["localhost",".localhost",".local",".internal","metadata.google.internal","169.254.169.254","metadata.azure.com","metadata"];for(let u of n)if(i===u||i.endsWith(u))return!1;let s=["::1","[::1]","::ffff:127.","::ffff:10.","::ffff:172.","::ffff:192.168.","::ffff:169.254.","fe80:","fc00:","fd00:","[fe80:","[fc","[fd"];for(let u of s)if(i.includes(u))return!1;if(/^\d{1,3}(\.\d{1,3}){1,3}$/.test(i)&&/(^|\.)0\d+/.test(i))return!1;let a=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/,o=i.match(a);if(o){let[,u,l,d,A]=o,g=parseInt(u,10),f=parseInt(l,10),p=parseInt(d,10),y=parseInt(A,10);if(g>255||f>255||p>255||y>255||g===0||g===127||g===10||g===172&&f>=16&&f<=31||g===192&&f===168||g===169&&f===254||g===100&&f>=64&&f<=127||g===100&&f===100||g===224&&f===0&&p===0||g>=240)return!1}if(/^\d{8,}$/.test(i)||/^0x[0-9a-fA-F]{6,}$/i.test(i))return!1;let c=[/(^|\.)\d{1,3}-\d{1,3}-\d{1,3}-\d{1,3}(\.|$)/,/(^|\.)0x[0-9a-f]{6,8}(\.|$)/i,/(^|\.)\d{8,}(\.|$)/,/(^|\.)127\.0\.0\.1\.nip\.io$/,/(^|\.)localtest\.me$/,/(^|\.)vcap\.me$/,/(^|\.)xip\.io$/];for(let u of c)if(u.test(i))return!1;return!0}catch{return!1}}function Rr(t,e="Request",r){if(!_G(t,r))throw new Error(`${e} blocked: URL points to a restricted or private network destination (SSRF protection)`)}function QG(t){let e=new Set;if(t==null)return e;let r=t;if(typeof t=="string")try{r=JSON.parse(t)}catch{return e}if(typeof r!="object"||Array.isArray(r))return e;let i=/(url|host|address|endpoint|server|domain|site|base|gateway|api)/i,n=s=>{if(!(s==null||typeof s!="object"))for(let[a,o]of Object.entries(s))if(typeof o=="string"){if(i.test(a)){let c=Mx(o);c&&e.add(c)}}else o!=null&&typeof o=="object"&&n(o)};return n(r),e}function Mx(t){let e=t.trim();if(!e)return;let r=/^[a-z][a-z0-9+.-]*:\/\//i.test(e)?[e]:[`http://${e}`];for(let i of r)try{let n=new URL(i);if(n.protocol!=="http:"&&n.protocol!=="https:")continue;let s=n.hostname.toLowerCase().trim();if(s)return s}catch{}}function TG(t){let e=new Set;if(!t)return e;for(let r of t.split(/[,;\s]+/)){let i=Mx(r);i&&e.add(i)}return e}function zf(t,e){let r=QG(t),i=e?.SSRF_ALLOWED_HOSTS??(typeof process<"u"?process.env?.SSRF_ALLOWED_HOSTS:void 0);if(typeof i=="string"&&i.trim())for(let n of TG(i))r.add(n);return r}var Zo=G(()=>{"use strict"});var PG,FG,NG,Jf,Lx=G(()=>{"use strict";Zo();PG="https://openapi.aliyundrive.com/adrive/v1.0",FG=15e3,NG=6e4,Jf=class t{addition;accessToken="";refreshTokenVal="";driveId="";tokenExpiresAt=0;listCache=new Map;downloadUrlCache=new Map;static DOWNLOAD_URL_TTL_MS=3e3*1e3;fileDetailCache=new Map;static FILE_DETAIL_TTL_MS=600*1e3;constructor(e){this.addition=e,this.refreshTokenVal=e.refresh_token||"",this.driveId=e.drive_id||""}async init(){if(!this.refreshTokenVal||!this.refreshTokenVal.trim()){console.warn("[AliyundriveOpen] refresh_token is empty, skipping init.");return}try{await this.refreshAccessToken(),this.driveId||await this.resolveDriveId()}catch(e){console.warn("[AliyundriveOpen] init warning:",e.message)}}async resolveDriveId(e=!1){if(!e&&this.addition.drive_id&&this.addition.drive_id.trim()){this.driveId=this.addition.drive_id.trim();return}try{let r=await this.openApiRequest("/user/getDriveInfo",{}),i=e?"resource":this.addition.drive_type||"resource",n="";i==="resource"&&r.resource_drive_id?n=r.resource_drive_id:i==="backup"&&r.backup_drive_id?n=r.backup_drive_id:i==="default"&&r.default_drive_id&&(n=r.default_drive_id),n||(n=r.resource_drive_id||r.default_drive_id||r.backup_drive_id||""),this.driveId=n,console.log(`[AliyundriveOpen] Resolved drive_id: ${this.driveId} (driveType: ${i})`)}catch(r){console.warn("[AliyundriveOpen] resolveDriveId failed:",r.message)}}async refreshAccessToken(){if(!this.refreshTokenVal||!this.refreshTokenVal.trim())return;let e=this.refreshTokenVal.trim(),r=[];if(this.addition.api_url_address&&this.addition.api_url_address.trim()){let a=this.addition.api_url_address.trim();try{Rr(a,"AliyundriveOpen api_url_address"),r.push(a)}catch(o){console.warn(`[AliyundriveOpen] Skipping unsafe api_url_address: ${o.message}`)}}r.push("https://api.oplist.org/alicloud/renewapi","https://api.oplist.org/ali_open/token","https://api.oplist.org/aliyundrive/token","https://api.alist.nn.ci/alist/ali_open/token","https://api.alist.nn.ci/aliyundrive/token","https://api-sam.oplist.org/aliyundrive/token");let i=this.addition.alipan_type==="alipanTV"?"alicloud_tv":"alicloud_qr";for(let a of r)try{let o=new URLSearchParams({refresh_ui:e,refresh_token:e,server_use:"true",driver_txt:i}),c=await fetch(`${a}?${o.toString()}`,{method:"GET",headers:{"Content-Type":"application/json"}});if(!c.ok)throw new Error(`[Status ${c.status}]`);let u=await c.json(),l=u.refresh_token||u.data?.refresh_token||"",d=u.access_token||u.data?.access_token||"";if(!d)throw new Error(`Empty access_token from online API: ${JSON.stringify(u)}`);this.accessToken=d,l&&(this.refreshTokenVal=l),this.tokenExpiresAt=Date.now()+(u.expires_in||7200)*1e3-6e4;return}catch(o){console.warn(`[AliyundriveOpen] Online API '${a}' failed: ${o.message}`)}let n=(this.addition.client_id||"").trim()||"25ab4837190e48718a28f80073574a4d",s=(this.addition.client_secret||"").trim();try{let a={grant_type:"refresh_token",refresh_token:e,client_id:n};s&&(a.client_secret=s);let o=await fetch("https://openapi.aliyundrive.com/oauth/access_token",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!o.ok){let u=await o.text().catch(()=>"");throw new Error(`[Status ${o.status}] ${u}`)}let c=await o.json();if(!c.access_token)throw new Error(`Invalid response: ${JSON.stringify(c)}`);this.accessToken=c.access_token,c.refresh_token&&(this.refreshTokenVal=c.refresh_token),this.tokenExpiresAt=Date.now()+(c.expires_in||7200)*1e3-6e4;return}catch(a){console.warn(`[AliyundriveOpen] Direct OAuth failed: ${a.message}`)}throw new Error("[AliyundriveOpen] All token refresh strategies failed. Please check: 1) refresh_token is valid and not expired, 2) api_url_address is accessible, 3) If using direct OAuth, client_id and client_secret are correct.")}async ensureToken(){(!this.accessToken||Date.now()>=this.tokenExpiresAt)&&await this.refreshAccessToken()}getRootFolderId(){return this.addition.root_folder_id?.trim()||"root"}async openApiRequest(e,r,i=!0){await this.ensureToken();let n=e.startsWith("http")?e:`${PG}${e}`;try{Rr(n,"AliyundriveOpen openApiRequest")}catch(o){throw new Error(`[AliyundriveOpen] blocked unsafe URL: ${o.message}`)}let s=()=>fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.accessToken}`},body:JSON.stringify(r),signal:AbortSignal.timeout(FG)}),a;try{a=await s()}catch(o){if(o?.name==="AbortError"||o?.name==="TimeoutError")await new Promise(c=>setTimeout(c,400)),a=await s();else throw o}if(a.status===401&&i)return await this.refreshAccessToken(),this.openApiRequest(e,r,!1);if(!a.ok){let o=await a.text().catch(()=>"");throw new Error(`[AliyundriveOpen] API error [${a.status}] ${e}: ${o}`)}return a.json()}invalidateListCache(e){e?this.listCache.delete(this.driveId+":"+e):this.listCache.clear()}async listFiles(e){this.driveId||await this.resolveDriveId();let r=this.driveId+":"+e,i=this.listCache.get(r);if(i&&Date.now()-i.at<NG)return i.pages.flatMap(c=>c.items);let n=[],s,a=this.addition.order_by||"updated_at",o=this.addition.order_direction||"DESC";do{let c={drive_id:this.driveId,parent_file_id:e,limit:100,order_by:a,order_direction:o};s&&(c.marker=s);let u;try{u=await this.openApiRequest("/openFile/list",c)}catch(d){if(d.message?.includes("UserNotAllowedAccessDrive"))console.warn(`[AliyundriveOpen] UserNotAllowedAccessDrive for drive ${this.driveId}, auto re-resolving drive_id...`),await this.resolveDriveId(!0),c.drive_id=this.driveId,u=await this.openApiRequest("/openFile/list",c);else throw d}let l=u.items||[];n.push(...l),s=u.next_marker||void 0}while(s);return this.listCache.set(r,{at:Date.now(),pages:[{marker:void 0,items:n}]}),n}async getFile(e){let r=this.fileDetailCache.get(e);if(r&&Date.now()-r.at<t.FILE_DETAIL_TTL_MS)return r.data;this.driveId||await this.resolveDriveId();let i=await this.openApiRequest("/openFile/get",{drive_id:this.driveId,file_id:e});return i&&(this.fileDetailCache.size>3e3&&this.fileDetailCache.clear(),this.fileDetailCache.set(e,{data:i,at:Date.now()})),i}async getDownloadUrl(e){let r=this.downloadUrlCache.get(e);if(r&&Date.now()-r.at<t.DOWNLOAD_URL_TTL_MS)return r.url;let i=await this.openApiRequest("/openFile/getDownloadUrl",{drive_id:this.driveId,file_id:e,expire_sec:14400}),n=i.url||i.download_url||"";return n&&(this.downloadUrlCache.size>2e3&&this.downloadUrlCache.clear(),this.downloadUrlCache.set(e,{url:n,at:Date.now()})),n}async searchFiles(e,r,i,n){this.driveId||await this.resolveDriveId();let s=e.replace(/["\\]/g,""),a=r===1?' and type = "folder"':r===2?' and type = "file"':"",o={drive_id:this.driveId,query:`name match "${s}"${a}`,limit:Math.min(100,Math.max(10,i)),fields:"*"};n&&(o.marker=n);let c;try{c=await this.openApiRequest("/openFile/search",o)}catch(u){if(u.message?.includes("UserNotAllowedAccessDrive"))await this.resolveDriveId(!0),o.drive_id=this.driveId,c=await this.openApiRequest("/openFile/search",o);else throw u}return c}fileMetaCache=new Map;primeFileMeta(e,r,i){e&&(this.fileMetaCache.has(e)||this.fileMetaCache.set(e,{name:String(r||""),parent:String(i||"root")}))}async getFileMeta(e){let r=this.fileMetaCache.get(e);if(r)return r;let i=await this.openApiRequest("/openFile/get",{drive_id:this.driveId,file_id:e,fields:"name,parent_file_id,type,file_id"}),n={name:String(i?.name||""),parent:String(i?.parent_file_id||"root")};return this.fileMetaCache.size>4e3&&this.fileMetaCache.clear(),this.fileMetaCache.set(e,n),n}async getFilePath(e){this.driveId||await this.resolveDriveId();let r=[],i=e,n=new Set;for(let a=0;a<24&&!(!i||i==="root"||n.has(i));a++){n.add(i);let o=await this.getFileMeta(i);if(o.parent==="root")break;r.push(o.parent),i=o.parent}if(!r.length)return"/";let s=[];for(let a=r.length-1;a>=0;a--){let o=await this.getFileMeta(r[a]);o.name&&s.push(o.name)}return s.length?"/"+s.map(a=>a.split("/").map(encodeURIComponent).join("/")).join("/"):"/"}async getVideoPreviewPlayInfo(e){return this.openApiRequest("/openFile/getVideoPreviewPlayInfo",{drive_id:this.driveId,file_id:e,category:"live_transcoding",url_expire_sec:14400})}async mkdir(e,r){await this.openApiRequest("/openFile/create",{drive_id:this.driveId,parent_file_id:e,name:r,type:"folder",check_name_mode:"refuse"})}async rename(e,r){await this.openApiRequest("/openFile/update",{drive_id:this.driveId,file_id:e,name:r,check_name_mode:"refuse"})}async remove(e){let r=this.addition.remove_way||"trash";await this.openApiRequest(r==="trash"?"/openFile/recyclebin":"/openFile/delete",{drive_id:this.driveId,file_id:e})}async move(e,r){await this.openApiRequest("/openFile/move",{drive_id:this.driveId,file_id:e,to_parent_file_id:r,check_name_mode:"refuse"})}async copy(e,r){await this.openApiRequest("/openFile/copy",{drive_id:this.driveId,file_id:e,to_parent_file_id:r,auto_rename:!0})}async putFile(e,r,i){let n=i.length,s=await this.openApiRequest("/openFile/create",{drive_id:this.driveId,parent_file_id:e,name:r,type:"file",size:n,check_name_mode:"auto_rename",part_info_list:[{part_number:1}]}),a=s.part_info_list?.[0]?.upload_url;if(!a)return;let o=await fetch(a,{method:"PUT",body:i});if(!o.ok)throw new Error(`[AliyundriveOpen] Upload failed: ${o.status}`);await this.openApiRequest("/openFile/complete",{drive_id:this.driveId,file_id:s.file_id,upload_id:s.upload_id})}async createMultiPartFile(e,r,i,n){let s=[];for(let a=0;a<n;a++)s.push({part_number:a+1});return this.openApiRequest("/openFile/create",{drive_id:this.driveId,parent_file_id:e,name:r,type:"file",check_name_mode:"auto_rename",size:i,part_info_list:s})}async getPartUploadUrl(e,r,i){return(await this.openApiRequest("/openFile/getUploadUrl",{drive_id:this.driveId,file_id:e,upload_id:r,part_info_list:[{part_number:i}]}))?.part_info_list?.[0]?.upload_url||""}async putPart(e,r){let i=await fetch(e,{method:"PUT",body:r});if(i.status!==200&&i.status!==409){let n=await i.text().catch(()=>"");throw new Error(`[AliyundriveOpen] part upload failed: HTTP ${i.status} ${n}`)}}async completeMultiPartFile(e,r){return this.openApiRequest("/openFile/complete",{drive_id:this.driveId,file_id:e,upload_id:r})}}});function UG(t){return Buffer.from(JSON.stringify(t),"utf8").toString("base64")}function j2(t){let e=JSON.parse(Buffer.from(t,"base64").toString("utf8"));if(!e||!e.file_id||!e.upload_id)throw new Error("[AliyundriveOpen] invalid upload session");return e}function V2(t){let e=t.split("/").filter(Boolean);return e.pop(),"/"+e.join("/")}function Y2(t){let e=t.type==="folder";return{name:t.name,size:t.size||0,is_dir:e,modified:t.updated_at||t.created_at||new Date().toISOString(),sign:"",type:W(t.name,e),thumb:t.thumbnail||"",raw_url:t.download_url||""}}var RG,jf,qx=G(()=>{"use strict";Ee();Me();Lx();RG=10*1024*1024;jf=class{client;addition;pathFileIdCache=new Map;constructor(e){this.addition=e,this.client=new Jf(e)}async init(){await this.client.init()}async list(e,r){let i=await this.resolveFileId(r),s=(await this.client.listFiles(i)).map(Y2);return le(s,this.addition.order_by,this.addition.order_direction)}async search(e,r,i,n){if(!r)return[];let s=[],a,o=0;do{let c=await this.client.searchFiles(r,i,n,a),u=(c.items||[]).slice(0,n-s.length);for(let d of u)this.client.primeFileMeta(d.file_id,d.name,d.parent_file_id);let l=5;for(let d=0;d<u.length;d+=l){let A=u.slice(d,d+l),g=await Promise.all(A.map(async f=>{let p=Y2(f);try{p.parent=await this.client.getFilePath(f.file_id)}catch{p.parent="/"}return p}));s.push(...g)}a=c.next_marker||void 0,o++}while(a&&s.length<n&&o<3);return s}async get(e,r){let i=await this.resolveFileId(r),n=await this.client.getFile(i).catch(()=>null),s=await this.client.getDownloadUrl(i).catch(()=>"");if(n){let c=Y2(n);return c.raw_url=s||c.raw_url,c}try{await this.client.listFiles(i);let c=r.split("/").filter(Boolean);return{name:c[c.length-1]||"root",size:0,is_dir:!0,modified:new Date().toISOString(),sign:"",type:1,raw_url:""}}catch{}let a=r.split("/").filter(Boolean);return{name:a[a.length-1]||"root",size:0,is_dir:!1,modified:new Date().toISOString(),sign:"",type:0,raw_url:s}}async mkdir(e,r){let i=r.split("/").filter(Boolean),n=i.pop()||"\u65B0\u6587\u4EF6\u5939",s="/"+i.join("/"),a=await this.resolveFileId(s);await this.client.mkdir(a,n),this.client.invalidateListCache(a)}async rename(e,r,i){let n=await this.resolveFileId(r),s=await this.resolveFileId(V2(r));await this.client.rename(n,i),this.client.invalidateListCache(s)}async remove(e,r,i){let n=await this.resolveFileId(r),s=await this.resolveFileId(V2(r));await this.client.remove(n),this.client.invalidateListCache(s)}async move(e,r,i,n,s){let a=await this.resolveFileId(n),o=await this.resolveFileId(V2(n)),c=await this.resolveFileId(r);await this.client.move(a,c),this.client.invalidateListCache(o),this.client.invalidateListCache(c)}async copy(e,r,i,n,s){let a=await this.resolveFileId(n),o=await this.resolveFileId(r);await this.client.copy(a,o),this.client.invalidateListCache(o)}async put(e,r,i){let n=r.split("/").filter(Boolean),s=n.pop()||"upload",a="/"+n.join("/"),o=await this.resolveFileId(a);await this.removeExistingFile(o,s),await this.client.putFile(o,s,i),this.client.invalidateListCache(o)}async removeExistingFile(e,r){try{let n=(await this.client.listFiles(e)).find(s=>s.type==="file"&&s.name===r);n&&await this.client.remove(n.file_id)}catch(i){console.warn(`[AliyundriveOpen] overwrite check failed for "${r}":`,i?.message||i)}}async createUploadSession(e,r,i,n,s){let a=RG,o=Math.max(1,Math.ceil(Math.max(0,Number(n)||0)/a)),c=await this.resolveFileId(r||"/");await this.removeExistingFile(c,i);let u=await this.client.createMultiPartFile(c,i,Math.max(0,Number(n)||0),o);if(u.rapid_upload)return this.client.invalidateListCache(c),{reuse:!0,partCount:0,chunkSize:a,session:""};let l=UG({file_id:u.file_id,upload_id:u.upload_id,partCount:o,chunkSize:a});return{reuse:!1,partCount:o,chunkSize:a,session:l}}async uploadPart(e,r,i){let n=j2(e);if(!Number.isInteger(r)||r<1||r>n.partCount)throw new Error(`[AliyundriveOpen] \u5206\u7247\u5E8F\u53F7\u65E0\u6548: ${r}`);let s=await this.client.getPartUploadUrl(n.file_id,n.upload_id,r);if(!s)throw new Error(`[AliyundriveOpen] \u83B7\u53D6\u7B2C ${r} \u7247\u76F4\u4F20\u5730\u5740\u5931\u8D25`);await this.client.putPart(s,i)}async getPartUploadUrl(e,r){let i=j2(e);if(!Number.isInteger(r)||r<1||r>i.partCount)throw new Error(`[AliyundriveOpen] \u5206\u7247\u5E8F\u53F7\u65E0\u6548: ${r}`);let n=await this.client.getPartUploadUrl(i.file_id,i.upload_id,r);if(!n)throw new Error(`[AliyundriveOpen] \u83B7\u53D6\u7B2C ${r} \u7247\u76F4\u4F20\u5730\u5740\u5931\u8D25`);return n}async completeUploadSession(e){let r=j2(e);await this.client.completeMultiPartFile(r.file_id,r.upload_id),this.client.invalidateListCache()}async other(e,r,i){if(e==="video_preview"){let n=await this.resolveFileId(r),s=await this.client.getVideoPreviewPlayInfo(n);return{video_preview_play_info:s?.video_preview_play_info??s}}throw new Error(`[AliyundriveOpen] unsupported other method '${e}'`)}async resolveFileId(e){let r=e.split("/").filter(Boolean).join("/");if(!r)return this.client.getRootFolderId();if(this.pathFileIdCache.has(r))return this.pathFileIdCache.get(r);let i=r.split("/"),n=this.client.getRootFolderId();for(let s=0;s<i.length;s++){let a=i[s],o=(()=>{try{return decodeURIComponent(a)}catch{return a}})(),c=i.slice(0,s+1).join("/");if(this.pathFileIdCache.has(c)){n=this.pathFileIdCache.get(c);continue}let l=(await this.client.listFiles(n)).find(d=>d.name===a||d.name===o||d.file_id===a);if(!l)throw new Error(`[AliyundriveOpen] Path '${a}' not found`);n=l.file_id,this.pathFileIdCache.set(c,n)}return n}}});var kd,Hx,Kx,$2=G(()=>{"use strict";kd="application/vnd.google-apps.folder",Hx="application/vnd.google-apps.shortcut",Kx="files(id,name,mimeType,size,modifiedTime,createdTime,thumbnailLink,shortcutDetails,md5Checksum,sha1Checksum,sha256Checksum),nextPageToken"});var Pa,Gx,OG,Vf,zx=G(()=>{"use strict";$2();Pa="https://www.googleapis.com/drive/v3",Gx="https://www.googleapis.com/upload/drive/v3",OG="https://oauth2.googleapis.com/token",Vf=class{addition;accessToken="";refreshTokenVal="";tokenExpiresAt=0;constructor(e){this.addition=e,this.refreshTokenVal=e.refresh_token||""}getRootFolderId(){return this.addition.root_folder_id?.trim()||"root"}async init(){if(!this.refreshTokenVal||!this.refreshTokenVal.trim()){console.warn("[GoogleDrive] refresh_token is empty, skipping init.");return}try{await this.refreshAccessToken()}catch(e){console.warn("[GoogleDrive] init token refresh warning:",e.message)}}async refreshAccessToken(){let e=this.refreshTokenVal.trim();if(!e)return;let r=this.addition.use_online_api!==!1,i=[];r&&(this.addition.api_url_address?.trim()&&i.push(this.addition.api_url_address.trim()),i.push("https://api.oplist.org/google/token","https://api.oplist.org/google/renewapi","https://api.oplist.org/googledrive/token","https://api-sam.oplist.org/google/token","https://api-sam.oplist.org/googledrive/token","https://api.alist.nn.ci/google/token","https://api.alist.nn.ci/googledrive/token"));for(let a of i)try{let o=new URLSearchParams({refresh_ui:e,server_use:"true",driver_txt:"googleui_go"}),c=await fetch(`${a}?${o.toString()}`,{method:"GET"});if(!c.ok)throw new Error(`[Status ${c.status}]`);let u=await c.json(),l=u.access_token||u.data?.access_token||"",d=u.refresh_token||u.data?.refresh_token||"";if(!l){let A=u.text||u.error||"empty access_token";throw new Error(A)}this.accessToken=l,d&&(this.refreshTokenVal=d),this.tokenExpiresAt=Date.now()+(u.expires_in||3600)*1e3-6e4;return}catch(o){console.warn(`[GoogleDrive] Online API '${a}' failed: ${o.message}`)}let n=(this.addition.client_id||"").trim()||"202264815644-2n82p2e49c7o6026u87j9e22v1n25c27.apps.googleusercontent.com",s=(this.addition.client_secret||"").trim()||"GOCSPX-4bH5Kx3s_89_j6j2x-2x3-8x";if(n&&s)try{let a=await fetch(OG,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({client_id:n,client_secret:s,refresh_token:e,grant_type:"refresh_token"}).toString()});if(!a.ok){let c=await a.text().catch(()=>"");throw new Error(`[Status ${a.status}] ${c}`)}let o=await a.json();if(!o.access_token)throw new Error(`Invalid OAuth response: ${JSON.stringify(o)}`);this.accessToken=o.access_token,o.refresh_token&&(this.refreshTokenVal=o.refresh_token),this.tokenExpiresAt=Date.now()+(o.expires_in||3600)*1e3-6e4;return}catch(a){console.warn(`[GoogleDrive] Direct OAuth failed: ${a.message}`)}throw new Error("[GoogleDrive] All token refresh strategies failed. Please check: 1) refresh_token is valid, 2) api_url_address is accessible, 3) If using direct OAuth: client_id and client_secret are correct.")}async ensureToken(){(!this.accessToken||Date.now()>=this.tokenExpiresAt)&&await this.refreshAccessToken()}async request(e,r={},i=!0){await this.ensureToken();let n=await fetch(e,{...r,headers:{Authorization:`Bearer ${this.accessToken}`,...r.headers||{}}});if(n.status===401&&i)return console.warn("[GoogleDrive] 401 Unauthorized, refreshing token..."),await this.refreshAccessToken(),this.request(e,r,!1);if(!n.ok){let s=await n.text().catch(()=>"");throw new Error(`[GoogleDrive] API error [${n.status}]: ${s}`)}return n.status===204?null:n.json()}async listFiles(e){let r=[],i,n=this.addition.order_by||"folder,name,modifiedTime desc";do{let s=new URLSearchParams({q:`'${e}' in parents and trashed = false`,fields:Kx,orderBy:n,pageSize:"1000",includeItemsFromAllDrives:"true",supportsAllDrives:"true"});i&&s.set("pageToken",i);let a=`${Pa}/files?${s.toString()}`,o=await this.request(a),c=o.files||[];for(let u of c)u.mimeType===Hx&&u.shortcutDetails?.targetId&&(u.id=u.shortcutDetails.targetId,u.mimeType=u.shortcutDetails.targetMimeType||u.mimeType);r.push(...c),i=o.nextPageToken}while(i);return r}async getFile(e){let r=new URLSearchParams({fields:"id,name,mimeType,size,modifiedTime,md5Checksum",includeItemsFromAllDrives:"true",supportsAllDrives:"true"});return this.request(`${Pa}/files/${e}?${r.toString()}`)}getDownloadUrl(e){return`${Pa}/files/${e}?includeItemsFromAllDrives=true&supportsAllDrives=true&alt=media&acknowledgeAbuse=true`}getDownloadHeaders(){return{Authorization:`Bearer ${this.accessToken}`}}async mkdir(e,r){await this.request(`${Pa}/files?supportsAllDrives=true`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:r,parents:[e],mimeType:kd})})}async rename(e,r){await this.request(`${Pa}/files/${e}?supportsAllDrives=true`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:r})})}async remove(e){await this.request(`${Pa}/files/${e}?supportsAllDrives=true`,{method:"DELETE"})}async move(e,r,i){let n=new URLSearchParams({addParents:i,removeParents:r,supportsAllDrives:"true"});await this.request(`${Pa}/files/${e}?${n.toString()}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:"{}"})}async copy(e,r,i){await this.request(`${Pa}/files/${e}/copy?supportsAllDrives=true`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:i,parents:[r]})})}async putFile(e,r,i,n="application/octet-stream"){let s=(this.addition.chunk_size||5)*1024*1024;if(i.length<=s){let a=new URLSearchParams({uploadType:"multipart",supportsAllDrives:"true"}),o=`----GoogleDriveBoundary${Date.now()}`,c=JSON.stringify({name:r,parents:[e]}),u=`--${o}\r
|
|
53
53
|
Content-Type: application/json\r
|
|
54
54
|
\r
|
|
55
55
|
${c}\r
|
|
@@ -269,7 +269,7 @@ Minimum version required to store current data is: `+s+`.
|
|
|
269
269
|
`).map(r=>r.trim()).filter(Boolean);for(let r of e)try{new RegExp(r)}catch{return r}return null}Ye();bi();Tr();vd();function yne(t,e){if(typeof t!="string"||typeof e!="string"||t.length!==e.length)return!1;let r=0;for(let i=0;i<t.length;i++)r|=t.charCodeAt(i)^e.charCodeAt(i);return r===0}async function m1(t){try{let e=await se(t?.env),r={};for(let s of e.settings||[])r[s.key]=s.value;let i=r.sign_all==="true",n=parseInt(r.link_expiration,10)||0;return!i&&n<=0?{enabled:!1,expiresIn:0}:{enabled:!0,expiresIn:n>0?n*3600:0}}catch{return{enabled:!1,expiresIn:0}}}function vl(t){return"/"+String(t||"").split("/").filter(Boolean).join("/")}function Ine(t,e,r){let i=vl(t).toLowerCase(),n=vl(e).toLowerCase();if(i===n)return!0;if(!r)return!1;for(;n!=="/";)if(n=vl(n.split("/").slice(0,-1).join("/")),i===n)return!0;return!1}async function wne(t,e){try{let i=(await se(t?.env)).metas||[];if(!i.length)return null;let n=vl(e);for(;;){let s=i.find(a=>vl(a.path).toLowerCase()===n.toLowerCase());if(s)return s;if(n==="/")return null;n=vl(n.split("/").slice(0,-1).join("/"))}}catch{return null}}async function Ene(t,e){try{let{resolvePath:r}=await Promise.resolve().then(()=>(Ye(),Nr)),i=await r(e);return i?.storage?hx(i.storage):!1}catch{return!1}}async function y1(t,e){if(await Ene(t,e))return!0;let r=await wne(t,e);return!r||!r.password?!1:Ine(r.path,e,!!r.p_sub)}async function KU(t,e){return(await m1(t)).enabled?!0:await y1(t,e)}async function xl(t){try{let e=await se(t?.env);for(let r of e.settings||[])if(r.key==="link_expiration"){let i=parseInt(r.value,10)||0;if(i>0)return i*3600;break}}catch{}return 0}async function kl(t,e,r){let i=await Er(t),n=r===0?0:Math.floor(Date.now()/1e3)+r,s=await Vw(`${e}:${n}`,i);return`${n}.${s}`}async function GU(t,e,r){let i=r.lastIndexOf(".");if(i<=0)return!1;let n=parseInt(r.slice(0,i),10),s=r.slice(i+1);if(!Number.isFinite(n)||n!==0&&n<=Math.floor(Date.now()/1e3))return!1;let a=await Er(t),o=await Vw(`${e}:${n}`,a);return yne(o,s)}Co();Au();Yt();async function _l(t={},e){let r=(t.parent||"/").replace(/\/+/g,"/")||"/",i=String(t.keywords||"").trim().toLowerCase(),n=t.scope??0,s=Math.max(1,t.page||1),a=Math.max(1,Math.min(100,t.per_page||30)),o=Math.min(20,Math.max(0,t.max_depth??10)),c=Math.min(2e3,Math.max(1,t.max_results??500)),u=[],l=6,d=0,A=!1,g=[];async function f(){d>=l&&await new Promise(F=>g.push(F)),d++}function p(){d--;let F=g.shift();F&&F()}function y(F,Q){return Q.some(P=>P==="/"?!0:F===P||F.startsWith(P+"/"))}async function m(F,Q,P=[]){if(y(F,P)||A||Q>o||u.length>=c)return;let T=[];try{T=(await Xt(F)).content||[]}catch{return}let D=[];for(let x of T){if(u.length>=c){A=!0;break}let _=!i||x.name.toLowerCase().includes(i),U=!!x.is_dir,R=U&&!x.sign,j=!0;n===1&&!U&&(j=!1),n===2&&U&&(j=!1),!R&&_&&j&&u.push({...x,parent:F.endsWith("/")&&F!=="/"?F.slice(0,-1):F}),U&&D.push(F==="/"?`/${x.name}`:`${F}/${x.name}`)}let v=[];for(let x of D){if(A||u.length>=c)break;await f();let _=m(x,Q+1,P).finally(p);v.push(_)}await Promise.all(v)}let E=[r],b=[];if(r==="/"&&i)try{let F=await HB(i,n,c,e);if(F.supportedMounts.length>0&&(u.push(...F.rows.slice(0,c)),b=[...new Set([...F.supportedMounts,...F.failedMounts])]),F.supportedMounts.length>0&&F.unsupportedMounts.length===0&&F.failedMounts.length===0){let Q=u.length,P=(s-1)*a;return{content:u.slice(P,P+a),total:Q}}}catch{}for(let F of E){if(A||u.length>=c)break;await m(F,0,b)}let C=u.length,B=(s-1)*a;return{content:u.slice(B,B+a),total:C}}vd();function I1(t){let e=new DataView(t),r=t.byteLength,i=-1,n=Math.max(0,r-22-65557);for(let u=r-22;u>=n;u--)if(e.getUint32(u,!0)===101010256){i=u;break}if(i===-1)throw new Error("Invalid ZIP: End of Central Directory not found");let s=e.getUint16(i+10,!0),a=e.getUint32(i+16,!0),o=[],c=a;for(let u=0;u<s&&e.getUint32(c,!0)===33639248;u++){let l=e.getUint16(c+10,!0),d=e.getUint32(c+20,!0),A=e.getUint32(c+24,!0),g=e.getUint16(c+28,!0),f=e.getUint16(c+30,!0),p=e.getUint16(c+32,!0),y=e.getUint32(c+42,!0),m=e.getUint16(c+12,!0),E=e.getUint16(c+14,!0),b=Cne(E,m),C=new Uint8Array(t,c+46,g),B=new TextDecoder("utf-8").decode(C);if(c+=46+g+f+p,B.endsWith("/")||e.getUint32(y,!0)!==67324752)continue;let k=e.getUint16(y+26,!0),F=e.getUint16(y+28,!0),Q=y+30+k+F;o.push({name:B.replace(/\\/g,"/"),isDir:!1,size:A,compressedSize:d,compressionMethod:l,dataOffset:Q,modified:b})}return{entries:o}}async function zU(t,e){let r=new Uint8Array(t,e.dataOffset,e.compressedSize);if(e.compressionMethod===0)return new Uint8Array(r);if(e.compressionMethod===8){if(typeof DecompressionStream>"u")throw new Error("DecompressionStream is not supported in this runtime");let i=new DecompressionStream("deflate-raw"),n=i.writable.getWriter();n.write(r),n.close();let s=await new Response(i.readable).arrayBuffer();return new Uint8Array(s)}throw new Error(`Unsupported ZIP compression method: ${e.compressionMethod}`)}function Cne(t,e){let r=1980+(t>>9&127),i=t>>5&15,n=t&31,s=e>>11&31,a=e>>5&63,o=(e&31)*2,c=u=>String(u).padStart(2,"0");return`${r}-${c(i)}-${c(n)}T${c(s)}:${c(a)}:${c(o)}Z`}Zo();nr();bi();Zo();Co();Ye();Yt();Em();var w1="openlist-sharing-seed";var Bne={md5:32,sha1:40,sha256:64};function dr(t){return typeof t=="string"?t:""}var bne=64,Dne=4096;function JU(t){let e=dr(t).trim();if(e.length>Dne)throw new Error("Seed file path exceeds the maximum length");let r=e.split("/");if(r.length>bne)throw new Error("Seed file path exceeds the maximum depth");if(e.includes("\0")||e.includes("\\")||e.startsWith("/")||r.length===0||r.some(i=>!i||i==="."||i===".."))throw new Error("Seed file path must be a safe relative path");return r.join("/")}function Qh(t,e){let r=dr(t).toLowerCase();if(r&&!new RegExp(`^[0-9a-f]{${Bne[e]}}$`).test(r))throw new Error(`Invalid ${e} hash`);return r}function Sne(t){return Array.isArray(t)?t.map(e=>{if(!e||typeof e!="object")throw new Error("Invalid seed source");let r=dr(e.type),i=dr(e.url);if(!r||!i)throw new Error("Seed source type and URL are required");try{if(!new URL(i).protocol)throw new Error("missing scheme")}catch{throw new Error("Seed source URL must be absolute")}return{type:r,url:i,expires_at:dr(e.expires_at),share_id:dr(e.share_id)}}):[]}function Oi(t){if(!t||typeof t!="object")throw new Error("Invalid seed payload");let e=t;if(e.format!==void 0&&e.format!==w1)throw new Error("Unsupported seed format");if(e.version!==void 0&&Number(e.version)!==1)throw new Error("Unsupported seed version");let r=Number(e.piece_size||10485760);if(!Number.isSafeInteger(r)||r<16*1024||r>64*1024*1024)throw new Error("Invalid piece_size");if(!Array.isArray(e.files)||e.files.length===0||e.files.length>1e5)throw new Error("Seed file count must be between 1 and 100000");let i=e.files.map(a=>{if(!a||typeof a!="object")throw new Error("Invalid seed file");let o=Number(a.size);if(!Number.isSafeInteger(o)||o<0)throw new Error("Invalid seed file size");let c=a.hashes||{},u=c.pieces||{},l=o>0?Math.ceil(o/r):0,d=A=>{if(!Array.isArray(u[A]))return[];let g=u[A].map(f=>Qh(f,A));if(g.length!==0&&g.length!==l)throw new Error(`${A} piece count is ${g.length}, expected ${l}`);return g};return{path:JU(a.path),size:o,modified:dr(a.modified),comment:dr(a.comment),hashes:{md5:Qh(c.md5,"md5"),sha1:Qh(c.sha1,"sha1"),sha256:Qh(c.sha256,"sha256"),pieces:{md5:d("md5"),sha1:d("sha1"),sha256:d("sha256")}},sources:Sne(a.sources),cas_slice_md5:Qh(a.cas_slice_md5,"md5"),cas_create_time:dr(a.cas_create_time),cas_cloud:dr(a.cas_cloud).trim(),missing_channels:Array.isArray(a.missing_channels)?a.missing_channels.map(dr).filter(Boolean):[]}}),n=new Set;for(let a of i){if(n.has(a.path))throw new Error(`Duplicate seed file path: ${a.path}`);n.add(a.path)}let s=dr(e.name)||i[0].path.split("/")[0];if(!s.trim()||s==="."||s===".."||/[\\/\0]/.test(s))throw new Error("Invalid seed name");return{format:w1,version:1,name:s,comment:dr(e.comment),created_at:dr(e.created_at)||new Date().toISOString(),created_by:dr(e.created_by)||"OpenList",piece_size:r,trackers:Array.isArray(e.trackers)?e.trackers.map(dr).filter(Boolean):[],channels:Array.isArray(e.channels)?e.channels.map(a=>{if(!a||typeof a!="object"||!dr(a.driver).trim())throw new Error("Seed channel driver is required");let o=dr(a.mount_path);if(/[?#\0]/.test(o))throw new Error("Seed channel mount_path contains invalid characters");return{driver:dr(a.driver).trim(),mount_path:o}}):[],files:i}}function E1(t,e){let r=t&&typeof t=="object"?t:{},i=a=>({whole:!!r[a]?.whole,pieces:!!r[a]?.pieces}),n={md5:i("md5"),sha1:i("sha1"),sha256:i("sha256")};!n.md5.whole&&!n.md5.pieces&&!n.sha1.whole&&!n.sha1.pieces&&!n.sha256.whole&&!n.sha256.pieces&&(n={md5:{whole:!0,pieces:!0},sha1:{whole:!0,pieces:!0},sha256:{whole:!0,pieces:!0}});for(let a of e)a==="torrent"&&(n.sha1={whole:!0,pieces:!0}),a==="cas"&&(n.md5={whole:!0,pieces:!0});return n}function Db(t,e){let r={md5:e.md5.whole?t.hashes.md5:"",sha1:e.sha1.whole?t.hashes.sha1:"",sha256:e.sha256.whole?t.hashes.sha256:"",pieces:{md5:e.md5.pieces?t.hashes.pieces.md5:[],sha1:e.sha1.pieces?t.hashes.pieces.sha1:[],sha256:e.sha256.pieces?t.hashes.pieces.sha256:[]}};return{...t,hashes:r}}function jU(t){return JU(t)}var _n=new TextEncoder,So=new TextDecoder("utf-8",{fatal:!0}),xne=32,kne=1e5;function C1(t){let e=t.reduce((n,s)=>n+s.byteLength,0),r=new Uint8Array(e),i=0;for(let n of t)r.set(n,i),i+=n.byteLength;return r}function Ql(t){if(t instanceof Uint8Array)return C1([_n.encode(`${t.byteLength}:`),t]);if(typeof t=="string")return Ql(_n.encode(t));if(typeof t=="number"){if(!Number.isSafeInteger(t))throw new Error("Bencode integer is out of range");return _n.encode(`i${t}e`)}if(Array.isArray(t))return C1([_n.encode("l"),...t.map(Ql),_n.encode("e")]);let e=Object.entries(t).sort(([r],[i])=>{let n=_n.encode(r),s=_n.encode(i),a=Math.min(n.length,s.length);for(let o=0;o<a;o++)if(n[o]!==s[o])return n[o]-s[o];return n.length-s.length});return C1([_n.encode("d"),...e.flatMap(([r,i])=>[Ql(r),Ql(i)]),_n.encode("e")])}function _ne(t){let e=0,r=0,i=s=>{if(++r>kne)throw new Error("Bencode item limit exceeded");if(s>xne)throw new Error("Bencode nesting limit exceeded");let a=t[e];if(a===105){let o=t.indexOf(101,++e);if(o<0)throw new Error("Unterminated bencode integer");let c=So.decode(t.subarray(e,o));if(!/^(0|-?[1-9]\d*)$/.test(c))throw new Error("Invalid bencode integer");let u=Number(c);if(!Number.isSafeInteger(u))throw new Error("Bencode integer is out of range");return e=o+1,u}if(a===108){e++;let o=[];for(;e<t.length&&t[e]!==101;)o.push(i(s+1));if(t[e++]!==101)throw new Error("Unterminated bencode list");return o}if(a===100){e++;let o={};for(;e<t.length&&t[e]!==101;){let c=i(s+1);if(!(c instanceof Uint8Array))throw new Error("Bencode dictionary key is not a string");let u=So.decode(c);o[u]=i(s+1)}if(t[e++]!==101)throw new Error("Unterminated bencode dictionary");return o}if(a>=48&&a<=57){let o=t.indexOf(58,e);if(o<0)throw new Error("Invalid bencode byte string");let c=So.decode(t.subarray(e,o));if(!/^(0|[1-9]\d*)$/.test(c))throw new Error("Invalid bencode byte string length");let u=Number(c),l=o+1,d=l+u;if(!Number.isSafeInteger(u)||d>t.length)throw new Error("Truncated bencode byte string");return e=d,t.slice(l,d)}throw new Error("Invalid bencode value")},n=i(0);if(e!==t.length)throw new Error("Trailing bencode data");return n}function Tl(t,e){if(!t||typeof t!="object"||Array.isArray(t)||t instanceof Uint8Array)throw new Error(`${e} must be a dictionary`);return t}function Qne(t){return t instanceof Uint8Array?t:new Uint8Array}function rn(t){return t instanceof Uint8Array?So.decode(t):typeof t=="string"?t:""}function Do(t){return typeof t=="number"?t:0}function Tne(t){return Array.isArray(t)?t.map(e=>rn(e)).filter(Boolean):[]}function Sb(t){return t==null?"":typeof t=="string"||typeof t=="number"||t instanceof Uint8Array?t:typeof t=="boolean"?t?1:0:Array.isArray(t)?t.map(Sb):typeof t=="object"?Object.fromEntries(Object.entries(t).map(([e,r])=>[e,Sb(r)])):String(t)}function vb(t){return t instanceof Uint8Array?So.decode(t):Array.isArray(t)?t.map(vb):t&&typeof t=="object"?Object.fromEntries(Object.entries(t).map(([e,r])=>[e,vb(r)])):t}function Pne(t){if(!t||t.length%2!==0||!/^[0-9a-f]+$/i.test(t))return new Uint8Array;let e=new Uint8Array(t.length/2);for(let r=0;r<e.length;r++)e[r]=parseInt(t.slice(r*2,r*2+2),16);return e}function Fne(t){return Array.from(t,e=>e.toString(16).padStart(2,"0")).join("")}function Nne(t){if(t.files.length>1){for(let e of t.files.slice(0,-1))if(e.size%t.piece_size!==0)throw new Error("Cannot convert this multi-file seed to a standard torrent: a file boundary splits a piece")}return t.files.flatMap(e=>e.hashes.pieces.sha1)}async function Rne(t,e){if(!t.hashes.md5)return;let r=t.cas_slice_md5?t.cas_slice_md5.toUpperCase():"",i=t.hashes.pieces.md5.map(n=>n.toUpperCase());if(!r&&i.length>0&&e===10485760&&(r=i.length>1?(await wm(i.join(`
|
|
270
270
|
`))).toUpperCase():i[0]),!!r)return{cloud:t.cas_cloud||"189",file_md5:t.hashes.md5.toUpperCase(),slice_md5:r,slice_md5s:i,slice_size:e}}function Une(t){return _n.encode(JSON.stringify(Oi(t),null,2))}function xb(t){let e=JSON.parse(So.decode(t));if(e?.format!==w1||Number(e?.version)!==1||!e?.created_at||!e?.created_by)throw new Error("Invalid or incomplete OpenList sharing seed");return Oi(e)}async function VU(t,e){if(!t.hashes.md5)throw new Error(`CAS requires a whole-file MD5 for ${t.path}`);let r=t.cas_slice_md5?t.cas_slice_md5.toUpperCase():"";if(!r&&t.hashes.pieces.md5.length>0&&e===10485760){let n=t.hashes.pieces.md5.map(s=>s.toUpperCase());r=n.length>1?(await wm(n.join(`
|
|
271
271
|
`))).toUpperCase():n[0]}if(!r){if(t.size>10485760)throw new Error(`CAS requires a legacy slice MD5 or complete 10 MiB MD5 pieces for ${t.path}`);r=t.hashes.md5.toUpperCase()}let i={name:t.path.split("/").pop()||t.path,size:t.size,md5:t.hashes.md5,sliceMd5:r,create_time:t.cas_create_time||String(Math.floor(Date.now()/1e3)),cloud:t.cas_cloud||"189"};return t.hashes.pieces.md5.length>0&&(i.slice_md5s=t.hashes.pieces.md5.map(n=>n.toUpperCase()),i.slice_size=e||10485760),i}async function One(t){let e=Oi(t);if(e.files.length===0)throw new Error("CAS requires at least one file");let r;if(e.files.length===1){let i=await VU(e.files[0],e.piece_size);r={name:i.name,size:i.size,md5:i.md5,sliceMd5:i.sliceMd5,create_time:i.create_time,slice_md5s:i.slice_md5s,slice_size:i.slice_size,cloud:i.cloud}}else{let i=[],n=0;for(let s of e.files){let a=await VU(s,e.piece_size);i.push(a),n+=a.size}r={name:e.name,size:n,md5:"",sliceMd5:"",create_time:"",files:i}}return _n.encode(Buffer.from(JSON.stringify(r)).toString("base64"))}function YU(t){let e=So.decode(t).trim(),r=e;try{r=Buffer.from(e,"base64").toString("utf8"),JSON.parse(r)}catch{r=e}let i=JSON.parse(r),n=u=>{if(!u.name||!Number.isSafeInteger(u.size)||Number(u.size)<0||!u.md5)throw new Error("Invalid CAS file entry");let l=String(u.md5).toLowerCase(),d=String(u.sliceMd5||u.md5).toLowerCase();if(!/^[0-9a-f]{32}$/i.test(l)||!/^[0-9a-f]{32}$/i.test(d))throw new Error("Invalid CAS hash");let A=Array.isArray(u.slice_md5s)?u.slice_md5s.map(g=>String(g).toLowerCase()):[];return{path:u.name,size:Number(u.size),modified:"",comment:"",hashes:{md5:l,sha1:"",sha256:"",pieces:{md5:A,sha1:[],sha256:[]}},sources:[],cas_slice_md5:d,cas_create_time:u.create_time||"",cas_cloud:String(u.cloud||""),missing_channels:[]}};if(Array.isArray(i.files)&&i.files.length>0){let u=i.files.map(n);return{format:"cas",cas:{name:String(i.name),size:u.reduce((d,A)=>d+A.size,0),md5:"",sliceMd5:"",create_time:"",cloud:String(i.cloud||""),files:i.files},seed:Oi({name:i.name,comment:"Imported from OpenList CAS metadata",created_at:new Date().toISOString(),created_by:"OpenList",piece_size:10485760,files:u})}}if(!i.name||!Number.isSafeInteger(i.size)||Number(i.size)<0||!i.md5)throw new Error("Invalid CAS payload");let s=String(i.md5).toLowerCase(),a=String(i.sliceMd5||i.md5);if(!/^[0-9a-f]{32}$/i.test(s)||!/^[0-9a-f]{32}$/i.test(a))throw new Error("Invalid CAS hash");let o=Number(i.create_time);return{format:"cas",cas:{name:String(i.name),size:Number(i.size),md5:s,sliceMd5:a,create_time:String(i.create_time||""),slice_md5s:i.slice_md5s,slice_size:i.slice_size,cloud:String(i.cloud||"")},seed:Oi({name:i.name,comment:"Imported from OpenList CAS metadata",created_at:Number.isFinite(o)&&o>0?new Date(o*1e3).toISOString():new Date().toISOString(),created_by:"OpenList",piece_size:i.slice_size||10485760,files:[n({name:i.name,size:Number(i.size),md5:s,sliceMd5:a,create_time:String(i.create_time||""),slice_md5s:i.slice_md5s,slice_size:i.slice_size,cloud:i.cloud})]})}}async function kb(t,e){let r=Oi(t),i=e||Nne(r);if(i.some(a=>a.length!==40))throw new Error("Torrent conversion requires SHA-1 piece hashes");let n={name:r.name,"piece length":r.piece_size,pieces:C1(i.map(Pne))};r.files.length===1?(n.length=r.files[0].size,r.files[0].hashes.md5&&(n.md5sum=r.files[0].hashes.md5)):n.files=r.files.map(a=>{let o={length:a.size,path:a.path.split("/")};return a.hashes.md5&&(o.md5sum=a.hashes.md5),o});let s={info:n,comment:r.comment,"created by":r.created_by,"creation date":Math.floor(new Date(r.created_at).getTime()/1e3)||Math.floor(Date.now()/1e3),"x-openlist":Sb(r)};if(r.trackers.length&&(s.announce=r.trackers[0],s["announce-list"]=r.trackers.map(a=>[a])),r.files.length===1){let a=await Rne(r.files[0],r.piece_size);a&&(s["x-cas"]=a)}return Ql(s)}function Mne(t,e,r,i,n){let s=Array.isArray(t.files)?t.files:null,a=s?s.map(c=>{let u=Tl(c,"torrent file");return{path:(Array.isArray(u.path)?u.path.map(rn):[]).join("/"),size:Do(u.length),md5:rn(u.md5sum)}}):[{path:e,size:Do(t.length),md5:rn(t.md5sum)}],o=0;return a.map((c,u)=>{let l=c.size>0?Math.ceil(c.size/i):0,A=(u===a.length-1||c.size%i===0)&&o+l<=r.length?r.slice(o,o+l):[];o+=l;let g=a.length===1&&n?rn(n.slice_md5):"",f=a.length===1&&n?rn(n.create_time):"",p=a.length===1&&n?rn(n.cloud):"";return{path:c.path,size:c.size,modified:"",comment:"",hashes:{md5:c.md5.toLowerCase(),sha1:"",sha256:"",pieces:{md5:[],sha1:A,sha256:[]}},sources:[],cas_slice_md5:g.toLowerCase(),cas_create_time:f,cas_cloud:p,missing_channels:[]}})}async function $U(t){let e=Tl(_ne(t),"torrent root"),r=Tl(e.info,"torrent info"),i=await bQ(Ql(r)),n=rn(r.name),s=Do(r["piece length"]),a=Qne(r.pieces);if(!n||s<=0||a.length%20!==0)throw new Error("Invalid torrent info dictionary");let o=Array.isArray(r.files)?r.files.reduce((f,p)=>f+Do(Tl(p,"torrent file").length),0):Do(r.length),c=o>0?Math.ceil(o/s):0;if(a.length/20!==c)throw new Error("Torrent piece count mismatch");if(e["x-openlist"]){let f=Oi(vb(e["x-openlist"]));return Lne(f,r,n,s),{format:"torrent",seed:f,info_hash:i}}let u=[];for(let f=0;f<a.length;f+=20)u.push(Fne(a.subarray(f,f+20)));let l=[rn(e.announce),...Array.isArray(e["announce-list"])?e["announce-list"].flatMap(f=>Tne(f)):[]].filter((f,p,y)=>f&&y.indexOf(f)===p),d=Do(e["creation date"]),A=e["x-cas"]?Tl(e["x-cas"],"x-cas"):void 0;return{format:"torrent",seed:Oi({name:n,comment:rn(e.comment),created_at:d>0?new Date(d*1e3).toISOString():new Date().toISOString(),created_by:rn(e["created by"])||"OpenList",piece_size:s,trackers:l,channels:[],files:Mne(r,n,u,s,A)}),info_hash:i}}function Lne(t,e,r,i){if(t.name!==r||t.piece_size!==i)throw new Error("x-openlist metadata conflicts with torrent info");let n=Array.isArray(e.files)?e.files:null;if(!n){if(t.files.length!==1||t.files[0].size!==Do(e.length))throw new Error("x-openlist file list conflicts with torrent info");return}if(t.files.length!==n.length)throw new Error("x-openlist file count conflicts with torrent info");n.forEach((s,a)=>{let o=Tl(s,"torrent file"),c=(Array.isArray(o.path)?o.path.map(rn):[]).join("/");if(t.files[a].path!==c||t.files[a].size!==Do(o.length))throw new Error(`x-openlist file ${a} conflicts with torrent info`)})}async function XU(t,e){if(e==="oss")return{format:"oss",seed:xb(t)};if(e==="torrent")return $U(t);if(e==="cas")return YU(t);let r=So.decode(t.subarray(0,Math.min(t.length,32))).trimStart()[0];return r==="{"?{format:"oss",seed:xb(t)}:r==="d"?$U(t):YU(t)}async function Th(t,e){return e==="oss"?Une(t):e==="torrent"?kb(t):One(t)}Em();async function ZU(){let[t,e,r]=await Promise.all([CQ(),JE(),jE()]);return{md5:t.init(),sha1:e.init(),sha256:r.init()}}function eO(t,e){t.md5.update(e),t.sha1.update(e),t.sha256.update(e)}function _b(t){return{md5:t.md5.digest("hex").toLowerCase(),sha1:t.sha1.digest("hex").toLowerCase(),sha256:t.sha256.digest("hex").toLowerCase()}}function qne(t){t.md5.init(),t.sha1.init(),t.sha256.init()}var Ph=class t{constructor(e,r){this.pieceSize=r;this.hasher=e.init()}pieceSize;hasher;written=0;hashes=[];static async create(e){return new t(await JE(),e)}update(e){let r=0;for(;r<e.length;){let i=Math.min(this.pieceSize-this.written,e.length-r);this.hasher.update(e.subarray(r,r+i)),this.written+=i,r+=i,this.written===this.pieceSize&&this.finishPiece()}}digest(){return this.written>0&&this.finishPiece(),[...this.hashes]}finishPiece(){this.hashes.push(this.hasher.digest("hex").toLowerCase()),this.hasher.init(),this.written=0}};async function Qb(t,e,r,i,n){if(!Number.isSafeInteger(r)||r<0||r>i)throw new Error(`File exceeds the hashing limit of ${i} bytes`);let s=await ZU(),a=await ZU(),o={md5:[],sha1:[],sha256:[]},c=t.getReader(),u=0,l=0;try{for(;;){let{done:d,value:A}=await c.read();if(d)break;if(!A?.length)continue;if(u+A.length>i||u+A.length>r)throw new Error("Downloaded file size exceeds the declared or configured limit");u+=A.length,n?.update(A),eO(s,A);let g=0;for(;g<A.length;){let f=Math.min(e-l,A.length-g);if(eO(a,A.subarray(g,g+f)),l+=f,g+=f,l===e){let p=_b(a);o.md5.push(p.md5),o.sha1.push(p.sha1),o.sha256.push(p.sha256),qne(a),l=0}}}}finally{c.releaseLock()}if(u!==r)throw new Error(`Downloaded file size mismatch: expected ${r}, received ${u}`);if(l>0){let d=_b(a);o.md5.push(d.md5),o.sha1.push(d.sha1),o.sha256.push(d.sha256)}return{size:u,hashes:{..._b(s),pieces:o}}}var ds=new je,B1=10*1024*1024,Fb=512*1024*1024,tO=1e3,Hne=8*1024*1024,rO=4*1024*1024;function sn(t,e,r){let i=t.env?.[e]??(typeof process<"u"?process.env?.[e]:void 0),n=Number(i);return Number.isSafeInteger(n)&&n>0?n:r}function Fh(t){try{return typeof t.executionCtx?.waitUntil!="function"?void 0:{waitUntil:e=>t.executionCtx.waitUntil(e)}}catch{return}}function Qr(t,e,r){return t.json({code:e,message:r,data:null},e)}async function Fl(t){let e=sn(t,"SEED_MAX_METADATA_SIZE",B1);if(Number(t.req.header("Content-Length")||0)>e)throw new Error(`Seed request exceeds the ${e} byte limit`);let i=await t.req.text();if(new TextEncoder().encode(i).byteLength>e)throw new Error(`Seed request exceeds the ${e} byte limit`);return i.trim()?JSON.parse(i):{}}function aa(t,e="/"){let r=String(t||e).replace(/\\/g,"/").trim();if(r.includes("\0"))throw new Error("Path contains an illegal null byte");let i=r.split("/").filter(Boolean);if(i.some(n=>n==="."||n===".."))throw new Error("Path traversal is not allowed");return"/"+i.join("/")}function Nb(t,e){return aa(`${t.replace(/\/+$/,"")}/${e}`)}function iO(t,e){if(!ut(t))throw new Error("Permission denied");let r=aa(e);if(r==="/@s"||r.startsWith("/@s/"))throw new Error("Writing through a share path is not allowed");let i=Ve(t,r),n=aa(t?.base_path||"/");if(n!=="/"&&i!==n&&!i.startsWith(`${n}/`))throw new Error("Target path is outside the user base path");return i}function Kne(t,e){if(t instanceof Uint8Array)return t;if(Array.isArray(t)&&t.every(r=>Number.isInteger(r)&&r>=0&&r<=255))return Uint8Array.from(t);if(typeof t!="string")throw new Error("Seed content is required");return e==="text"||t.trimStart().startsWith("{")||t.trimStart().startsWith("d")?new TextEncoder().encode(t):new Uint8Array(Buffer.from(t,"base64"))}function b1(t){let e=String(t||"").toLowerCase().replace(/^\./,"");return e==="oss"||e==="torrent"||e==="cas"?e:void 0}function nO(t,e){return`${t.name.replace(/[\\/:*?"<>|\0]/g,"_")||"seed"}.${e==="torrent"?"torrent":e}`}function Tb(t){let e=t.split("/").pop()||t,r=e.lastIndexOf(".");return r>0?e.slice(0,r):e}function Gne(t){if(t.length===0)return"OpenList Seed";if(t.length===1)return Tb(t[0].virtualPath);let e=Tb(t[0].virtualPath);if(t.every(a=>Tb(a.virtualPath)===e)&&e)return e;let n=t[0].virtualPath.split("/").slice(0,-1);for(let a of t.slice(1)){let o=a.virtualPath.split("/").slice(0,-1),c=0;for(;c<n.length&&c<o.length&&n[c]===o[c];)c++;n=n.slice(0,c)}return n[n.length-1]||"OpenList Seed"}function Rb(t,e,r,i={}){let n=Buffer.from(r).toString("base64");return{format:e,file_name:nO(t,e),seed_data:n,size:r.byteLength,seed:t,...i}}function sO(t){let e=t.env?.ALLOW_SEED??(typeof process<"u"?process.env?.ALLOW_SEED:"");return String(e||"").split(/[\s,;]+/).map(r=>r.toLowerCase()).filter(Boolean)}function aO(t,e){let r=t.toLowerCase();return e.some(i=>i.startsWith("*.")?r.endsWith(i.slice(1))&&r!==i.slice(2):r===i)}function Pb(t,e){if(!e.url)throw new Error("Seed source URL is required");let r=new URL(t.req.url),i=new URL(e.url,r.origin);if(Rr(i.toString(),"Seed source"),i.username||i.password)throw new Error("Seed source URL credentials are not allowed");let n=e.type.toLowerCase(),s=i.origin===r.origin&&(/^\/(api\/)?p\//.test(i.pathname)||i.pathname.startsWith("/d/")||i.pathname.startsWith("/@s/")),a=["share","openlist-share"].includes(n)&&i.pathname.startsWith("/@s/"),o=["direct","openlist-direct"].includes(n)&&s;if(!a&&!o&&!aO(i.hostname,sO(t)))throw new Error("Seed source host is not an approved OpenList endpoint or configured domain");if(e.expires_at){let c=Date.parse(e.expires_at);if(!Number.isFinite(c)||c<=Date.now())throw new Error("Seed source has expired")}return i}async function D1(t,e,r={},i=!1){let n=e;for(let s=0;s<=3;s++){if(Rr(n.toString(),"Seed fetch"),i){let c=new URL(t.req.url);if(!(n.origin===c.origin&&(/^\/(api\/)?p\//.test(n.pathname)||n.pathname.startsWith("/@s/")))&&!aO(n.hostname,sO(t)))throw new Error("Seed fetch redirect left the approved source allowlist")}let a=await fetch(n,{...r,redirect:"manual"});if(a.status<300||a.status>=400)return a;let o=a.headers.get("Location");if(!o)throw new Error("Seed fetch redirect is missing a Location header");n=new URL(o,n)}throw new Error("Seed fetch exceeded the redirect limit")}async function zne(t,e,r){let i=Ve(e,aa(r)),{item:n,rawUrl:s}=await Bi(i,Fh(t)),a=sn(t,"SEED_MAX_METADATA_SIZE",B1);if(n.is_dir||n.size<0||n.size>a)throw new Error(`Seed file exceeds the ${a} byte limit`);let o=n.raw_url||new URL(s,t.req.url).toString(),c=n.raw_url_headers||{};!n.raw_url&&t.req.header("Authorization")&&(c.Authorization=t.req.header("Authorization"));let u=await D1(t,new URL(o,t.req.url),{headers:c});if(!u.ok)throw new Error(`Seed file download failed with HTTP ${u.status}`);if(Number(u.headers.get("Content-Length")||n.size)>a)throw new Error(`Seed file exceeds the ${a} byte limit`);let d=u.body?.getReader();if(!d)throw new Error("Seed file response has no body");let A=[],g=0;for(;;){let{done:y,value:m}=await d.read();if(y)break;if(m?.length){if(g+=m.length,g>a)throw new Error(`Seed file exceeds the ${a} byte limit`);A.push(m)}}let f=new Uint8Array(g),p=0;for(let y of A)f.set(y,p),p+=y.length;return f}async function Nh(t,e,r){if(r.seed&&typeof r.seed=="object")return{format:"oss",seed:Oi(r.seed)};let i=sn(t,"SEED_MAX_METADATA_SIZE",B1),n=r.seed_data||r.content||r.data||r.torrent_data,s=r.seed_path||r.path&&!n?await zne(t,e,String(r.seed_path||r.path)):Kne(r.seed_data??r.content??r.data??r.torrent_data,r.encoding);if(s.byteLength>i)throw new Error(`Seed content exceeds the ${i} byte limit`);return XU(s,b1(r.format||r.from_format||r.file_name?.split(".").pop()))}async function Ub(t,e,r){let i=Array.isArray(r)?r:[r];if(!i.length||i.some(o=>typeof o!="string"||!o.trim()))throw new Error("paths must contain at least one path");let n=sn(t,"SEED_MAX_FILES",tO),s=[],a=async(o,c)=>{if(s.length>=n)throw new Error(`Seed file count exceeds the ${n} file limit`);let u=Ve(e,o),{item:l,rawUrl:d}=await Bi(u,Fh(t));if(!l.is_dir){let g=l.raw_url||new URL(d,t.req.url).toString(),f={...l.raw_url_headers||{}};!l.raw_url&&t.req.header("Authorization")&&(f.Authorization=t.req.header("Authorization")),s.push({virtualPath:u,relativePath:jU(c),size:l.size,modified:l.modified||"",rawUrl:g,headers:f,hashes:l.hashes??(l.hash?{md5:l.hash}:{})});return}let{content:A}=await Xt(u,Fh(t));for(let g of A){let f=Nb(o,g.name),p=`${c.replace(/\/$/,"")}/${g.name}`;await a(f,p)}};for(let o of i){let c=aa(o),u=c.split("/").filter(Boolean).pop()||"root";await a(c,u)}if(!s.length)throw new Error("No files were found for seed generation");return s}function Pl(t,e){if(e==="cas"){let r=[];for(let i of t.files){i.hashes.md5||r.push(`${i.path}: missing whole-file MD5`);let n=!!i.cas_slice_md5,s=t.piece_size===10485760&&i.hashes.pieces.md5.length>0;i.size>10485760&&!n&&!s&&r.push(`${i.path}: missing legacy slice MD5 or complete 10 MiB MD5 pieces`)}return r}if(e==="torrent"){let r=[];return t.files.forEach((i,n)=>{i.hashes.pieces.sha1.length||r.push(`${i.path}: missing SHA-1 piece hashes`),t.files.length>1&&n<t.files.length-1&&i.size%t.piece_size!==0&&r.push(`${i.path}: piece boundary crosses the next file`)}),r}return[]}function Jne(t){return{oss:Pl(t,"oss"),torrent:Pl(t,"torrent"),cas:Pl(t,"cas")}}function jne(t){return Object.fromEntries(["oss","torrent","cas"].map(e=>{let r=Pl(t,e);return[e,{feasible:r.length===0,missing:r}]}))}async function Ob(t,e,r,i){if(!r)return;let n=iO(e,r);await kn(n,Buffer.from(i),Fh(t))}async function Vne(){try{let e=(await qi()).seed_default_matrix;if(e){let r=JSON.parse(String(e));if(r&&typeof r=="object")return r}}catch{}}async function Yne(t){try{let e=await qi(),r=String(e.seed_site_url||"").trim();if(r)return r.replace(/\/+$/,"")}catch{}return new URL(t.req.url).origin}async function $ne(t,e,r){let i=e&&typeof e=="object"?e:null,n=!!i?.md5||!!i?.sha1||!!i?.sha256;if(!n)try{let a=(await qi()).seed_default_matrix;if(a){let o=JSON.parse(String(a));if(o?.md5||o?.sha1||o?.sha256)return E1(o,r)}}catch{}return E1(n?e:void 0,r)}async function Wne(t,e,r,i){let n=i.includes("cas")?10485760:Number(r.piece_size||10485760);if(!Number.isSafeInteger(n)||n<16*1024||n>64*1024*1024)throw new Error("Invalid piece_size");let s=await $ne(t,r.hash_matrix,i),a=r.file_comments&&typeof r.file_comments=="object"?r.file_comments:{},o=await Ub(t,e,r.paths??r.path),c=sn(t,"SEED_MAX_HASH_BYTES",Fb),u=o.reduce((g,f)=>g+f.size,0);if(!Number.isSafeInteger(u)||u>c)throw new Error(`Seed input exceeds the ${c} byte hashing limit`);let l=await Ph.create(n),d=await Yne(t),A=[];for(let g of o){let f=await D1(t,new URL(g.rawUrl,t.req.url),{headers:g.headers});if(!f.ok)throw new Error(`Source download failed with HTTP ${f.status}: ${g.virtualPath}`);if(!f.body)throw new Error(`Source download has no body: ${g.virtualPath}`);let p=await Qb(f.body,n,g.size,c,l),y=String(a[g.relativePath]??a[g.virtualPath]??"");A.push(Db({path:g.relativePath,size:p.size,modified:g.modified,comment:y,hashes:p.hashes,cas_slice_md5:"",cas_create_time:"",cas_cloud:"",missing_channels:[],sources:r.include_direct_source===!0||r.include_sources===!0?[{type:"openlist-direct",url:`${d}/d${g.virtualPath}`,expires_at:"",share_id:""}]:[]},s))}return{torrentPieces:l.digest(),seed:Oi({name:String(r.name||Gne(o)),comment:String(r.comment||"Generated by OpenList"),created_at:new Date().toISOString(),created_by:String(r.created_by||"OpenList"),piece_size:n,trackers:Array.isArray(r.trackers)?r.trackers:[],channels:Array.isArray(r.channels)?r.channels:[],files:A})}}function Mb(t,e){for(let r of e.sources)try{return{source:r,url:Pb(t,r)}}catch{continue}}async function Xne(t,e,r,i,n,s=!1){let a=iO(e,i),o=a.split("/").filter(Boolean),c=o.pop();if(!c)throw new Error("Target file name is required");let u="/"+o.join("/"),l=await rt(a),d=await rt(u);if(l.isVirtual||d.isVirtual||!l.storage)throw new Error("Target storage was not found");let A=await et(l.storage.driver,l.storage),g=A,f={size:r.size,md5:r.hashes.md5,sha1:r.hashes.sha1,sha256:r.hashes.sha256,hashes:r.hashes};try{if(typeof g.rapidUpload=="function"){let E=await g.rapidUpload(a,l.physical,f);if(E===!0||E?.reuse||E?.success)return{status:"reused",method:"rapidUpload"}}if(typeof g.putRapid=="function"){let E=await g.putRapid(a,l.physical,f);if(E===!0||E?.reuse||E?.success)return{status:"reused",method:"putRapid"}}let p;if(typeof g.createUploadSession=="function"&&(p=await g.createUploadSession(u,d.physical,c,r.size,r.hashes.md5),p?.reuse))return{status:"reused",method:"multipart-rapid"};if(s)throw new Error("capability unavailable: target driver did not reuse the available hashes");if(!n)throw new Error("capability unavailable: no rapid-upload match and no approved source URL");let y=await D1(t,n.url,{},!0);if(!y.ok||!y.body)throw new Error(`Source download failed with HTTP ${y.status}`);if(p?.session&&typeof g.uploadPart=="function"&&typeof g.completeUploadSession=="function"){let E=Math.min(sn(t,"SEED_TRANSFER_CHUNK_SIZE",Hne),16777216),b=y.body.getReader(),C=new Uint8Array(0),B=1,k=0,F=[];for(;;){let{done:Q,value:P}=await b.read();if(P?.length){if(k+=P.length,k>r.size)throw new Error("Source exceeds the declared file size");let T=new Uint8Array(C.length+P.length);for(T.set(C),T.set(P,C.length),C=T;C.length>=E;){let D=C.slice(0,E);C=C.slice(E);let v=await g.uploadPart(p.session,B++,Buffer.from(D));v?.partMd5&&F.push(v.partMd5)}}if(Q)break}if(k!==r.size)throw new Error("Source size does not match seed metadata");if(C.length||r.size===0){let Q=await g.uploadPart(p.session,B,Buffer.from(C));Q?.partMd5&&F.push(Q.partMd5)}return await g.completeUploadSession(p.session,F),{status:"saved",method:"multipart-stream"}}if(typeof g.putStream=="function")return await g.putStream(a,l.physical,y.body,r.size,f),{status:"saved",method:"putStream"};let m=sn(t,"SEED_BUFFERED_TRANSFER_MAX",rO);if(r.size<=m){let E=new Uint8Array(await y.arrayBuffer());if(E.byteLength!==r.size)throw new Error("Source size does not match seed metadata");return await A.put(a,l.physical,Buffer.from(E)),{status:"saved",method:"bounded-buffer"}}throw new Error("capability unavailable: target driver has no streaming or multipart upload API")}finally{await Qt(l.storage.driver,l.storage,A,Fh(t))}}ds.get("/capabilities",async t=>{let e=await Ne(t);if(!e||e.disabled)return Qr(t,401,"Unauthorized");let r,i=t.req.query("path");if(i)try{let n=Ve(e,aa(i)),s=await rt(n);if(!s.isVirtual&&s.storage){let o=await et(s.storage.driver,s.storage);r={driver:s.storage.driver,rapid_upload:typeof o.rapidUpload=="function"||typeof o.putRapid=="function"||typeof o.createUploadSession=="function",stream_upload:typeof o.putStream=="function"||typeof o.createUploadSession=="function"&&typeof o.uploadPart=="function"&&typeof o.completeUploadSession=="function"}}}catch(n){r={error:Pe(n)}}return t.json({code:200,message:"success",data:{formats:["oss","torrent","cas"],version:1,hash_algorithms:["md5","sha1","sha256"],incremental_hashing:!0,torrent_v1:!0,extensions:["x-openlist","x-cas"],offline_download:"conditional",queue_adapter:!1,limits:{metadata_bytes:sn(t,"SEED_MAX_METADATA_SIZE",B1),hash_bytes:sn(t,"SEED_MAX_HASH_BYTES",Fb),files:sn(t,"SEED_MAX_FILES",tO)},target:r}})});ds.post("/capabilities",async t=>{let e=await Ne(t);if(!e||e.disabled)return Qr(t,401,"Unauthorized");try{let r=await Fl(t);if(Array.isArray(r.paths)&&r.paths.length>0){let f=await Ub(t,e,r.paths),p=await qi(),y=String(p.seed_default_trackers||"").split(`
|
|
272
|
-
`).map(B=>B.trim()).filter(Boolean),m=["md5","sha1","sha256"],E=f.map(B=>{let k=m.filter(Q=>!!B.hashes[Q]),F=k.length<m.length;return{path:B.virtualPath,name:B.relativePath,size:B.size,available_hashes:k,requires_download:F,requires_fetch:F,estimated_traffic:F?B.size:0,streamable:!0,share_available:!0,direct_source_available:!0}}),b=new Set;for(let B of f)for(let k of m)B.hashes[k]&&b.add(k);let C=m.filter(B=>b.has(B));return t.json({code:200,message:"success",data:{formats:{oss:!0,torrent:!0,cas:!0},files:E,existing_hashes:C,estimated_traffic:E.reduce((B,k)=>B+k.estimated_traffic,0),default_matrix:await Vne(),trackers:y}})}let i=await Nh(t,e,r),n=Ve(e,aa(r.path)),s=await rt(n);if(s.isVirtual||!s.storage)throw new Error("Target storage was not found");let o=await et(s.storage.driver,s.storage),c=typeof o.rapidUpload=="function"||typeof o.putRapid=="function"||typeof o.createUploadSession=="function",u=Array.isArray(o.rapidHashAlgos)?o.rapidHashAlgos.map(f=>String(f).toLowerCase()).filter(f=>["md5","sha1","sha256"].includes(f)):["md5","sha1"],l=typeof o.rapidHashNeedsPieces=="boolean"?o.rapidHashNeedsPieces:!1,d=typeof o.putStream=="function"||typeof o.createUploadSession=="function"&&typeof o.uploadPart=="function"&&typeof o.completeUploadSession=="function",A=sn(t,"SEED_BUFFERED_TRANSFER_MAX",rO),g=i.seed.files.map(f=>{let p=u.some(b=>!!f.hashes[b])||!1,y=l?p&&(f.hashes.pieces.md5.length>0||f.hashes.pieces.sha1.length>0):p,m=!!Mb(t,f),E="download_required";return c&&y?E="rapid_upload":m&&d?E="stream_upload":m&&f.size<=A&&(E="bounded_upload"),{path:f.path,method:E,requires_download:E==="download_required"}});return t.json({code:200,message:"success",data:{driver:s.storage.driver,policy:String(r.policy||"inherit"),driver_supports:{cas_rapid:c,rapid_hash_algos:u,rapid_uses_pieces:l},files:g}})}catch(r){return Qr(t,400,Pe(r))}});ds.post("/generate",async t=>{let e=await Ne(t);if(!e||e.disabled)return Qr(t,401,"Unauthorized");try{let r=await Fl(t);if((r.save_path||r.output_path)&&!ut(e))return Qr(t,403,"Permission denied");let n=(Array.isArray(r.formats)?r.formats:[r.format||"oss"]).map(b1);if(n.some(l=>!l))throw new Error("A valid output format is required");let s=n,{seed:a,torrentPieces:o}=await Wne(t,e,r,s),c=r.output_path||(Array.isArray(r.formats)?r.save_path:void 0),u=[];for(let l of s){let d=Pl(a,l);if(d.length){u.push({format:l,convertible:!1,diagnostics:d});continue}let A=l==="torrent"?await kb(a,o):await Th(a,l),g=c?Nb(aa(c),nO(a,l)):r.save_path;await Ob(t,e,g,A),u.push(Rb(a,l,A,{convertible:!0,...g?{path:g}:{}}))}return t.json({code:200,message:"success",data:Array.isArray(r.formats)?{seed:a,outputs:u,artifacts:u}:u[0]})}catch(r){let i=Pe(r);return Qr(t,i.includes("limit")||i.includes("exceeds")?413:400,i)}});ds.post("/parse",async t=>{let e=await Ne(t);if(!e||e.disabled)return Qr(t,401,"Unauthorized");try{let r=await Fl(t),i=await Nh(t,e,r),n=i.seed.files.reduce((o,c)=>o+c.size,0),s=i.seed.files.some(o=>!!Mb(t,o)),a=i.seed.files.some(o=>!!o.hashes.md5||!!o.hashes.sha1||!!o.hashes.sha256);return t.json({code:200,message:"success",data:{format:i.format,seed:i.seed,files:i.seed.files,total_size:n,diagnostics:Jne(i.seed),conversions:jne(i.seed),capabilities:{rapid_upload:a,offline_download:s,transfer:s,convert:!0,edit:!0,recalculate:!0},direct_preview:!1,...i.info_hash?{info_hash:i.info_hash}:{}}})}catch(r){return Qr(t,400,Pe(r))}});ds.post("/convert",async t=>{let e=await Ne(t);if(!e||e.disabled)return Qr(t,401,"Unauthorized");try{let r=await Fl(t);if(r.save_path&&!ut(e))return Qr(t,403,"Permission denied");let i=b1(r.to_format||r.target_format||r.output_format);if(!i)throw new Error("A valid target format is required");let n=await Nh(t,e,r),s=Pl(n.seed,i);if(s.length)return t.json({code:200,message:"success",data:{convertible:!1,diagnostics:s}});let a=await Th(n.seed,i);return await Ob(t,e,r.save_path,a),t.json({code:200,message:"success",data:Rb(n.seed,i,a,{convertible:!0})})}catch(r){return Qr(t,400,Pe(r))}});function Zne(t,e,r,i){if(!e)return;let n=!1;for(let s of i.values())if(s){n=!0;break}n&&!t.channels.some(s=>s.driver===e)&&t.channels.push({driver:e,mount_path:r});for(let s of t.files){if(!i.has(s.path))continue;i.get(s.path)?s.missing_channels=s.missing_channels.filter(o=>o!==e):s.missing_channels.includes(e)||s.missing_channels.push(e)}}async function oO(t,e){let r=await Ne(t);if(!ut(r))return Qr(t,403,"Permission denied");if(!e&&!bo(r,Bo.OFFLINE_DOWNLOAD))return Qr(t,403,"Offline download permission is required");try{let i=await Fl(t),n=await Nh(t,r,i),s=aa(i.target_path||i.destination||i.path||"/"),a=new Set(Array.isArray(i.files)?i.files.map(p=>String(p)):[]),o=new Set(Array.isArray(i.selected_files)?i.selected_files.map(p=>Number(p)):[]);if([...o].some(p=>!Number.isSafeInteger(p)||p<0||p>=n.seed.files.length))throw new Error("selected_files contains an invalid index");let c="",u="";try{let p=await rt(Ve(r,s));!p.isVirtual&&p.storage&&(c=p.storage.driver||"",u=p.storage.mount_path||"")}catch{}let l=n.seed.files.filter((p,y)=>a.size?a.has(p.path):o.size?o.has(y):!0),d=[],A=new Map,g=0;for(let p of l){let y=Nb(s,p.path),m=Mb(t,p);try{if(!e&&!m)throw new Error("capability unavailable: offline download requires an approved source URL");let E=await Xne(t,r,p,y,m,e);g++,A.set(p.path,!0),d.push({path:p.path,target:y,...E})}catch(E){A.set(p.path,!1),d.push({path:p.path,target:y,status:"unavailable",error:Pe(E)})}}if(g===0)return t.json({code:501,message:e?"capability unavailable: target driver cannot reuse hashes and no transferable source is available":"capability unavailable: no approved source and streaming upload combination is available",data:{results:d}},501);let f={total:d.length,saved:g,results:d};if(i.update_channel===!0&&c){Zne(n.seed,c,u,A);let p=await Th(n.seed,n.format);f.seed_data=Buffer.from(p).toString("base64"),f.seed=n.seed}return t.json({code:200,message:"success",data:f})}catch(i){return Qr(t,400,Pe(i))}}ds.post("/rapid_upload",t=>oO(t,!0));ds.post("/offline_download",t=>oO(t,!1));ds.post("/update",async t=>{let e=await Ne(t);if(!e||e.disabled)return Qr(t,401,"Unauthorized");try{let r=await Fl(t);if(r.save_path&&!ut(e))return Qr(t,403,"Permission denied");let i=await Nh(t,e,r),n=r.patch&&typeof r.patch=="object"?r.patch:r,s=r.options&&typeof r.options=="object"?r.options:{},a=n.comment??s.comment,o=!!(n.recalculate??s.recalculate),c=Oi({...i.seed,name:n.name??i.seed.name,comment:a??i.seed.comment,trackers:n.trackers??i.seed.trackers,channels:n.channels??i.seed.channels,files:n.files??i.seed.files}),u=r.file_comments&&typeof r.file_comments=="object"?r.file_comments:{},l=r.file_sources&&typeof r.file_sources=="object"?r.file_sources:{};for(let g of c.files)if(u[g.path]!==void 0&&(g.comment=String(u[g.path])),Array.isArray(l[g.path])){for(let f of l[g.path])Pb(t,f);g.sources=l[g.path]}if(o){let g=Number(r.piece_size||i.seed.piece_size||10485760);if(!Number.isSafeInteger(g)||g<16*1024||g>64*1024*1024)throw new Error("Invalid piece_size");c.piece_size=g;let f=E1(r.hash_matrix,[i.format]),p=Array.isArray(r.recalc_files)?r.recalc_files:[];if(!p.length)throw new Error("recalculate requires at least one recalc_files entry");let y=new Map;for(let b of p)typeof b?.source_path=="string"&&b.source_path.trim()&&y.set(String(b.path),b.source_path);let m=await Ph.create(g),E=sn(t,"SEED_MAX_HASH_BYTES",Fb);for(let b of c.files){let C=y.get(b.path);if(!C)continue;let B=await Ub(t,e,[C]);if(B.length!==1)throw new Error(`Recalculate path must resolve to exactly one file: ${C}`);let k=B[0],F=await D1(t,new URL(k.rawUrl,t.req.url),{headers:k.headers});if(!F.ok||!F.body)throw new Error(`Recalculate download failed with HTTP ${F.status}`);let Q=await Qb(F.body,g,k.size,E,m);b.hashes=Db({...b,hashes:Q.hashes},f).hashes,b.size=Q.size,b.cas_slice_md5="",b.cas_create_time=""}}for(let g of c.files)for(let f of g.sources)Pb(t,f);let d=b1(r.output_format||r.to_format)||i.format,A=await Th(c,d);return await Ob(t,e,r.save_path,A),t.json({code:200,message:"success",data:Rb(c,d,A)})}catch(r){return Qr(t,400,Pe(r))}});var S1=new Map,ese=1*1024*1024,tse=64*1024*1024,rse=10*1024*1024;function cO(t){return!Number.isFinite(t)||t<=0?rse:Math.min(tse,Math.max(ese,Math.floor(t)))}function ise(t){let e=Array.from(t).sort((s,a)=>s-a);if(e.length===0)return[];let r=[],i=e[0],n=e[0];for(let s=1;s<e.length;s++)e[s]===n+1?n=e[s]:(r.push([i,n]),i=n=e[s]);return r.push([i,n]),r}function oa(t){let e=ise(t.received),r=t.received.size*t.chunk_size,i=0;for(let s=0;s<t.total_chunks&&t.received.has(s);s++)i=s+1;let n=t.total_chunks>0?Math.floor(t.received.size/t.total_chunks*100):0;return{upload_id:t.upload_id,state:t.state,attempt:t.attempt,path:t.path,size:t.size,chunk_size:t.chunk_size,total_chunks:t.total_chunks,received:e,received_bytes:r,frontier:i,storage_progress:n,error:t.error}}function uO(t){return S1.get(t)}function lO(t,e){for(let r of S1.values())if(r.path===t&&r.size===e&&(r.state==="receiving"||r.state==="failed_retriable"))return r}function Nl(t){S1.set(t.upload_id,t)}function dO(t){S1.delete(t)}async function nse(t){try{let e=await rt(t);return e?.storage?gx(e.storage):!1}catch{return!1}}var at=new je;at.route("/seed",ds);var kt=t=>{try{let e=t.executionCtx;return!e||typeof e.waitUntil!="function"?void 0:{waitUntil:r=>e.waitUntil(r),env:t.env}}catch{return}},Gt=t=>t.json({code:403,message:"Permission denied",data:null},403),sse=25*1024*1024,ase=16*1024*1024,AO=1*1024*1024*1024;function ose(t,e){let r=t.env||{},i=e?"MAX_UPPART":"MAX_UPLOAD",n=r[i]||(typeof process<"u"?process.env?.[i]:"");if(n){let s=parseInt(String(n),10);if(Number.isFinite(s)&&s>0)return s}return e?ase:sse}function v1(t,e=!1){let r=parseInt(t.req.header("Content-Length")||"0",10);if(!r)return null;let i=ose(t,e);return r>i?i:null}var Lb=(t,e)=>{let r=e==="wrong password",i=e||"share error";return t.json({code:r?403:400,message:i,data:null},r?403:400)};at.post("/dirs",async t=>{let e=await t.req.json().catch(()=>({})),r=await Ne(t),i=e.path||"/";if(!i.startsWith("/@s")&&(!r||r.disabled))return t.json({code:401,message:"Unauthorized",data:null},401);let s=kt(t),a=i;(!e.force_root||!ls(r))&&(a=Ve(r,a));try{if(a.startsWith("/@s")){let u=await Bl(a,e.password||"",t.env);if(!u.ok)return Lb(t,u.error);if(u.virtualList){let A=[];for(let g of u.share.files||[])try{let{item:f}=await Bi(g,s);if(f.is_dir){let p=String(g).split("/").filter(Boolean);A.push({name:p[p.length-1]||g,modified:f.modified||new Date().toISOString()})}}catch{}return t.json({code:200,message:"success",data:A})}let{content:l}=await Xt(u.realPath,s),d=l.filter(A=>A.is_dir).map(A=>({name:A.name,modified:A.modified||new Date().toISOString()}));return t.json({code:200,message:"success",data:d})}let{content:o}=await Xt(a,s),c=o.filter(u=>u.is_dir).map(u=>({name:u.name,modified:u.modified||new Date().toISOString()}));return t.json({code:200,message:"success",data:c})}catch(o){return t.json({code:500,message:Pe(o),data:null})}});at.post("/list",async t=>{let e=await t.req.json().catch(()=>({})),r=await Ne(t);if(!(e.path||"/").startsWith("/@s")&&(!r||r.disabled))return t.json({code:401,message:"Unauthorized",data:null},401);let n=kt(t),s=Ve(r,e.path||"/"),a=parseInt(e.page,10)||1,o=parseInt(e.per_page,10)||0,c=u=>{let l=u.length;if(o<=0)return{content:u,total:l};let A=(Math.max(1,a)-1)*o,g=A+o;return{content:u.slice(A,g),total:l}};try{if(s.startsWith("/@s")){let D=await Bl(s,e.password||"",t.env);if(!D.ok)return Lb(t,D.error);if(D.virtualList){let j=[];for(let z of D.share.files||[]){let K=String(z).split("/").filter(Boolean),J=K[K.length-1]||z;try{let{item:ee}=await Bi(z,n);j.push({name:J,size:ee.size||0,is_dir:!!ee.is_dir,modified:ee.modified||new Date().toISOString(),sign:"",thumb:ee.thumb||"",type:ee.type??0})}catch{try{await Xt(z,n),j.push({name:J,size:0,is_dir:!0,modified:new Date().toISOString(),sign:"",thumb:"",type:1})}catch{j.push({name:J,size:0,is_dir:!1,modified:new Date().toISOString(),sign:"",thumb:"",type:0})}}}let{content:Y,total:L}=c(j);return t.json({code:200,message:"success",data:{content:Y,total:L,readme:D.share.readme||"",header:D.share.header||"",write:!1,write_content_bypass:!1,provider:"Share"}})}let{content:v,provider:x}=await Xt(D.realPath,n),_=v.map(j=>({name:j.name,size:j.size,is_dir:j.is_dir,created:j.created||j.modified||new Date().toISOString(),modified:j.modified||new Date().toISOString(),sign:j.sign||"",thumb:j.thumb||"",type:j.type??0})),{content:U,total:R}=c(_);return t.json({code:200,message:"success",data:{content:U,total:R,readme:D.share.readme||"",header:D.share.header||"",write:!1,write_content_bypass:!1,provider:x}})}let u=await yb(s,t.env);if(!Ib(r,u,s,e.password||""))return t.json({code:403,message:"Access denied (wrong password or not in read_users)",data:null},403);if(await nse(s))return t.json({code:403,message:"Index is disabled for this storage",data:null},403);let{content:l,provider:d,storage:A}=await Xt(s,n),g=ut(r)&&wb(r,u,s),f=Eb(u,s),p=await m1(t),y=await y1(t,s),m=p.enabled||y,E=m?p.expiresIn||await xl(t):0,b=await Promise.all(l.filter(D=>!HU(u,s,D.name)).map(async D=>{let v=`${s}/${D.name}`.replace(/\/{2,}/g,"/"),x=!D.is_dir&&m?await kl(t,v,E):"",_=D.hashinfo||D.hash_info_str||"",U=D.hash_info||{};return{name:D.name,size:D.size,is_dir:D.is_dir,created:D.created||D.modified||new Date().toISOString(),modified:D.modified||new Date().toISOString(),sign:x,thumb:D.thumb||"",type:D.type??0,hashinfo:_,hash_info:U}})),C=0;if(A&&(C=parseInt(A.page_size,10)||0,!C&&A.addition))try{let D=typeof A.addition=="string"?JSON.parse(A.addition):A.addition;C=parseInt(D?.page_size,10)||0}catch{}let B=o>0?o:C>0?C:0,k=D=>{let v=D.length;if(B<=0)return{content:D,total:v};let _=(Math.max(1,a)-1)*B,U=_+B;return{content:D.slice(_,U),total:v}},F=(()=>{if(!A)return[];let D=[],v=A;if(/^(s3|minio|cos|oss|r2|b2|cloudflare_r2)/i.test(v.driver||"")&&D.push("s3_presigned"),Array.isArray(v.direct_upload_tools))for(let x of v.direct_upload_tools)D.includes(x)||D.push(x);return D})(),{content:Q,total:P}=k(b),T=A?fx(A,s):void 0;return t.json({code:200,message:"success",data:{content:Q,total:P,readme:Cb(u,s),header:Bb(u,s),write:g,write_content_bypass:f,provider:d,direct_upload_tools:F,page_size:B>0?B:void 0,cache_expiration:T}})}catch(u){return t.json({code:500,message:Pe(u),data:null})}});at.post("/get",async t=>{let e=await t.req.json().catch(()=>({})),r=await Ne(t);if(!(e.path||"/").startsWith("/@s")&&(!r||r.disabled))return t.json({code:401,message:"Unauthorized",data:null},401);let n=kt(t),s=Ve(r,e.path||"/");try{if(s.startsWith("/@s")){let m=await Bl(s,e.password||"",t.env);if(!m.ok)return Lb(t,m.error);if(m.virtualList){let k=s.split("/").filter(Boolean)[1]||"share";return t.json({code:200,message:"success",data:{name:k,size:0,is_dir:!0,modified:new Date().toISOString(),sign:"",thumb:"",type:1,raw_url:"",readme:m.share.readme||"",header:m.share.header||"",provider:"Share",related:[],write:!1,write_content_bypass:!1}})}let E=s.split("/").filter(Boolean)[1]||"",{item:b,provider:C}=await Bi(m.realPath,n),B=s.replace(/^\/@s\/[^/]+/,"");return t.json({code:200,message:"success",data:{name:b.name,size:b.size,is_dir:b.is_dir,created:b.created||b.modified||new Date().toISOString(),modified:b.modified,sign:b.sign||"",thumb:b.thumb||"",type:b.type??0,raw_url:`/api/sd/${E}${B}`,readme:m.share.readme||"",header:m.share.header||"",provider:C,related:[],write:!1,write_content_bypass:!1}})}let a=await yb(s,t.env);if(!Ib(r,a,s,e.password||""))return t.json({code:403,message:"Access denied (wrong password or not in read_users)",data:null},403);let{item:o,provider:c,rawUrl:u}=await Bi(s,n),l=await m1(t),d=l.enabled||await y1(t,s),A=!o.is_dir&&d?await kl(t,s,l.expiresIn||await xl(t)):"",g=A&&u&&!/[?&]sign=/.test(u)?`${u}${u.includes("?")?"&":"?"}sign=${A}`:u,f=ut(r)&&wb(r,a,s),p=Eb(a,s),y=[];if(!o.is_dir)try{let m=s.includes("/")&&s.slice(0,s.lastIndexOf("/"))||"/",E=o.name.includes(".")?o.name.slice(0,o.name.lastIndexOf(".")):o.name,{content:b}=await Xt(m,n);y=b.filter(C=>C.name===o.name||C.is_dir?!1:(C.name.includes(".")?C.name.slice(0,C.name.lastIndexOf(".")):C.name)===E).map(C=>({name:C.name,size:C.size,is_dir:!1,modified:C.modified||new Date().toISOString(),sign:"",thumb:C.thumb||"",type:C.type??0}))}catch{y=[]}return t.json({code:200,message:"success",data:{name:o.name,size:o.size,is_dir:o.is_dir,created:o.created||o.modified||new Date().toISOString(),modified:o.modified,sign:A,thumb:o.thumb||"",type:o.type??0,raw_url:g,readme:Cb(a,s),header:Bb(a,s),provider:c,related:y,write:f,write_content_bypass:p}})}catch(a){return t.json({code:500,message:Pe(a),data:null})}});function Rl(t){if(typeof t!="string"||!t.trim())throw new Error("Invalid or empty file name");let e=t.trim();if(e==="."||e===".."||e.includes("/")||e.includes("\\")||e.includes("\0"))throw new Error(`Illegal file name '${e}'`);return e}function ca(t){if(typeof t!="string")throw new Error("Path must be a string");if(t.includes("\0"))throw new Error("Path contains illegal null byte");return t}at.post("/mkdir",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let i=(await t.req.json().catch(()=>({}))).path||"/";try{ca(i)}catch(a){return t.json({code:400,message:a.message,data:null},400)}let n=Ve(e,i),s=kt(t);try{return await bh(n,s),t.json({code:200,message:"success",data:null})}catch(a){return t.json({code:500,message:Pe(a),data:null})}});at.post("/rename",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let{path:r,name:i}=await t.req.json().catch(()=>({})),n="";try{ca(r||"/"),n=Rl(i)}catch(a){return t.json({code:400,message:a.message,data:null},400)}let s=kt(t);try{let a=Ve(e,r||"/");return await Dh(a,n,s),t.json({code:200,message:"success",data:null})}catch(a){return t.json({code:500,message:Pe(a),data:null})}});at.post("/remove",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let{dir:r,names:i}=await t.req.json().catch(()=>({}));if(!Array.isArray(i)||i.length===0)return t.json({code:400,message:"Parameter 'names' must be a non-empty array",data:null},400);let n=[];try{ca(r||"/"),n=i.map(a=>Rl(a))}catch(a){return t.json({code:400,message:a.message,data:null},400)}let s=kt(t);try{let a=Ve(e,r||"/");return await wo(a,n,s),t.json({code:200,message:"success",data:null})}catch(a){return t.json({code:500,message:Pe(a),data:null})}});at.post("/move",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let{src_dir:r,dst_dir:i,names:n}=await t.req.json().catch(()=>({}));if(!Array.isArray(n)||n.length===0)return t.json({code:400,message:"Parameter 'names' must be a non-empty array",data:null},400);let s=[];try{ca(r||"/"),ca(i||"/"),s=n.map(o=>Rl(o))}catch(o){return t.json({code:400,message:o.message,data:null},400)}let a=kt(t);try{let o=Ve(e,r||"/"),c=Ve(e,i||"/");return await Cl(o,c,s,a),t.json({code:200,message:"success",data:null})}catch(o){return t.json({code:500,message:Pe(o),data:null})}});at.post("/copy",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let{src_dir:r,dst_dir:i,names:n}=await t.req.json().catch(()=>({}));if(!Array.isArray(n)||n.length===0)return t.json({code:400,message:"Parameter 'names' must be a non-empty array",data:null},400);let s=[];try{ca(r||"/"),ca(i||"/"),s=n.map(o=>Rl(o))}catch(o){return t.json({code:400,message:o.message,data:null},400)}let a=kt(t);try{let o=Ve(e,r||"/"),c=Ve(e,i||"/");return await Sh(o,c,s,a),t.json({code:200,message:"success",data:null})}catch(o){return t.json({code:500,message:Pe(o),data:null})}});at.put("/put",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let r=decodeURIComponent(t.req.header("File-Path")||"");if(!r.trim())return t.json({code:400,message:"Missing File-Path header",data:null},400);try{ca(r)}catch(a){return t.json({code:400,message:a.message,data:null},400)}let i=Ve(e,r),n=kt(t),s=v1(t);if(s!==null)return t.json({code:413,message:`File too large (max ${s} bytes)`,data:null},413);try{let a=await t.req.arrayBuffer();return await kn(i,Buffer.from(a),n),t.json({code:200,message:"success",data:null})}catch(a){return t.json({code:500,message:Pe(a),data:null})}});at.put("/form",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let r=decodeURIComponent(t.req.header("File-Path")||"");if(!r.trim())return t.json({code:400,message:"Missing File-Path header",data:null},400);try{ca(r)}catch(a){return t.json({code:400,message:a.message,data:null},400)}let i=Ve(e,r),n=kt(t),s=v1(t);if(s!==null)return t.json({code:413,message:`File too large (max ${s} bytes)`,data:null},413);try{let o=(await t.req.formData()).get("file");if(!o||typeof o=="string")return t.json({code:400,message:"missing file in form data",data:null});let c=Buffer.from(await o.arrayBuffer());return await kn(i,c,n),t.json({code:200,message:"success",data:null})}catch(a){return t.json({code:500,message:Pe(a),data:null})}});at.post("/upload/create",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let{path:r,file_name:i,size:n,md5:s}=await t.req.json().catch(()=>({})),a=Ve(e,r||"/"),o=kt(t);if(!i)return t.json({code:400,message:"path and file_name are required",data:null});try{let c=await rt(a);if(c.isVirtual)throw new Error("failed get storage: storage not found");let u=await et(c.storage.driver,c.storage);if(typeof u.createUploadSession!="function")return t.json({code:200,message:"success",data:null});let l;try{l=await u.createUploadSession(a,c.physical,i,Number(n)||0,s||"")}finally{await Qt(c.storage.driver,c.storage,u,o)}return t.json({code:200,message:"success",data:l})}catch(c){return t.json({code:500,message:Pe(c),data:null})}});at.put("/upload/part",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let r=t.req.header("X-Upload-Session")||"",i=parseInt(t.req.header("X-Part-Number")||"0",10),n=decodeURIComponent(t.req.header("Upload-Path")||""),s=Ve(e,n),a=kt(t);if(!r||!(i>=1)||!s)return t.json({code:400,message:"missing X-Upload-Session / X-Part-Number / Upload-Path",data:null});let o=v1(t,!0);if(o!==null)return t.json({code:413,message:`Part too large (max ${o} bytes)`,data:null},413);try{let c=await rt(s);if(c.isVirtual)throw new Error("failed get storage: storage not found");let u=await et(c.storage.driver,c.storage);if(typeof u.uploadPart!="function")throw new Error("storage does not support chunked upload");let l=Buffer.from(await t.req.arrayBuffer()),d;try{d=await u.uploadPart(r,i,l)}finally{await Qt(c.storage.driver,c.storage,u,a)}return t.json({code:200,message:"success",data:d??null})}catch(c){return t.json({code:500,message:Pe(c),data:null})}});at.post("/upload/complete",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let{path:r,session:i,partMd5s:n}=await t.req.json().catch(()=>({})),s=Ve(e,r||"/"),a=kt(t);if(!i)return t.json({code:400,message:"path and session are required",data:null});try{let o=await rt(s);if(o.isVirtual)throw new Error("failed get storage: storage not found");let c=await et(o.storage.driver,o.storage);if(typeof c.completeUploadSession!="function")throw new Error("storage does not support chunked upload");try{await c.completeUploadSession(i,n)}finally{await Qt(o.storage.driver,o.storage,c,a)}return t.json({code:200,message:"success",data:null})}catch(o){return t.json({code:500,message:Pe(o),data:null})}});at.post("/add_offline_download",async t=>{let e=await Ne(t);if(!e||e.disabled)return t.json({code:401,message:"Unauthorized",data:null},401);let{path:r,urls:i}=await t.req.json().catch(()=>({})),n=Ve(e,r||"/");return!i||i.length===0?t.json({code:400,message:"No URLs provided"}):t.json({code:501,message:"capability unavailable: this runtime has no durable offline-download adapter; use /fs/seed/offline_download with an approved source and a streaming-capable target driver",data:{path:n,accepted:0}},501)});at.post("/search",async t=>{let e=await Ne(t);if(!e||e.disabled)return t.json({code:401,message:"Unauthorized",data:null},401);let r=await t.req.json().catch(()=>({})),i=Ve(e,r.parent||"/");try{let n=await _l({parent:i,keywords:r.keywords||"",scope:r.scope!==void 0?parseInt(r.scope,10):0,page:r.page?parseInt(r.page,10):1,per_page:r.per_page?parseInt(r.per_page,10):30},t.env);return t.json({code:200,message:"success",data:n})}catch(n){return t.json({code:500,message:Pe(n),data:null},500)}});at.post("/other",async t=>{let e=await Ne(t);if(!e||e.disabled)return t.json({code:401,message:"Unauthorized",data:null},401);let r=await t.req.json().catch(()=>({})),i=Ve(e,r.path||"/"),n=r.method;if(!n)return t.json({code:400,message:"Missing required parameter 'method'",data:null},400);if(!new Set(["video_preview","ym_pdf_probe"]).has(n)&&!ut(e))return Gt(t);try{let a=await rt(i);if(a.isVirtual||!a.storage)throw new Error("failed get storage: storage not found");let o=await et(a.storage.driver,a.storage);if(typeof o.other=="function"){let c=await o.other(n,a.relative,r);return t.json({code:200,message:"success",data:c})}return t.json({code:500,message:`Driver '${a.storage.driver}' does not support other method '${n}'`,data:null},500)}catch(a){return t.json({code:500,message:Pe(a),data:null},500)}});at.post("/batch_rename",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let{src_dir:r,rename_objects:i}=await t.req.json().catch(()=>({}));if(!Array.isArray(i)||i.length===0)return t.json({code:400,message:"rename_objects is required",data:null},400);let n=Ve(e,r||"/"),s=kt(t);try{for(let a of i){let o=a?.src_name,c=a?.new_name;if(!o||!c)continue;Rl(c);let u=`${n}/${o}`.replace(/\/{2,}/g,"/");await Dh(u,c,s)}return t.json({code:200,message:"success",data:null})}catch(a){return t.json({code:500,message:Pe(a),data:null},500)}});at.post("/regex_rename",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let{src_dir:r,src_name_regex:i,new_name_regex:n}=await t.req.json().catch(()=>({}));if(!i)return t.json({code:400,message:"src_name_regex is required",data:null},400);let s=Ve(e,r||"/"),a=kt(t);try{let o=new RegExp(i),{content:c}=await Xt(s,a);for(let u of c)if(!u.is_dir&&o.test(u.name)){let l=u.name.replace(o,n||"");Rl(l);let d=`${s}/${u.name}`.replace(/\/{2,}/g,"/");await Dh(d,l,a)}return t.json({code:200,message:"success",data:null})}catch(o){return t.json({code:500,message:Pe(o),data:null},500)}});at.post("/recursive_move",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let{src_dir:r,dst_dir:i,conflict_policy:n}=await t.req.json().catch(()=>({})),s=Ve(e,r||"/"),a=Ve(e,i||"/"),o=n||"overwrite",c=kt(t);try{let u=new Set;if(o!=="overwrite"){let A=await Xt(a,c);u=new Set(A.content.map(g=>g.name))}let l=[s],d=0;for(;l.length>0;){let A=l.shift(),{content:g}=await Xt(A,c);for(let f of g)if(f.is_dir)l.push(`${A}/${f.name}`.replace(/\/{2,}/g,"/"));else{if(u.has(f.name)){if(o==="cancel")return t.json({code:403,message:`file [${f.name}] exists`,data:null},403);if(o==="skip")continue}o!=="overwrite"&&u.add(f.name),await Cl(A,a,[f.name],c),d++}}return t.json({code:200,message:`Successfully moved ${d} files`,data:null})}catch(u){return t.json({code:500,message:Pe(u),data:null},500)}});at.post("/remove_empty_directory",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let{src_dir:r}=await t.req.json().catch(()=>({})),i=Ve(e,r||"/"),n=kt(t);try{let s=async a=>{let{content:o}=await Xt(a,n);for(let u of o)u.is_dir&&await s(`${a}/${u.name}`.replace(/\/{2,}/g,"/"));if(a===i)return;if((await Xt(a,n)).content.length===0){let u=a.split("/").slice(0,-1).join("/")||"/",l=a.split("/").pop();await wo(u,[l],n)}};return await s(i),t.json({code:200,message:"success",data:null})}catch(s){return t.json({code:500,message:Pe(s),data:null},500)}});at.post("/link",async t=>{let e=await Ne(t);if(!ls(e))return Gt(t);let{path:r}=await t.req.json().catch(()=>({})),i=Ve(e,r||"/"),n=kt(t);try{let s=await rt(i);if(s.isVirtual||!s.storage)return t.json({code:500,message:"storage not found",data:null},500);let a=await et(s.storage.driver,s.storage);try{let c=await a.get(i,s.physical??"/");if(c&&c.raw_url)return t.json({code:200,message:"success",data:{url:c.raw_url}})}finally{await Qt(s.storage.driver,s.storage,a,n)}let o=await kl(t,i,await xl(t));return t.json({code:200,message:"success",data:{url:`/api/p${xs(i)}?sign=${encodeURIComponent(o)}`}})}catch(s){return t.json({code:500,message:Pe(s),data:null},500)}});at.post("/get_direct_upload_info",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let{path:r,file_name:i,file_size:n}=await t.req.json().catch(()=>({})),s=Ve(e,r||"/");try{let a=await rt(s);if(a.isVirtual||!a.storage)return t.json({code:200,message:"success",data:null});let c=await et(a.storage.driver,a.storage);if(typeof c.getDirectUploadInfo=="function"){let u=await c.getDirectUploadInfo(a.relative,i,n);return t.json({code:200,message:"success",data:u})}if(typeof c.other=="function")for(let u of["direct_upload","get_direct_upload_info"])try{let l=await c.other(u,a.relative,{file_name:i,file_size:n});if(l)return t.json({code:200,message:"success",data:l})}catch{}return t.json({code:200,message:"success",data:null})}catch(a){return t.json({code:500,message:Pe(a),data:null},500)}});function x1(t){let r=(t.startsWith("/")?t:"/"+t).split("/").filter(Boolean),i=r.pop()||"";return{dir:"/"+r.join("/"),name:i}}function cse(t){let e={v:1,...t},r=JSON.stringify(e);return"mpt_"+(typeof btoa=="function"?btoa(String.fromCharCode(...new TextEncoder().encode(r))):Buffer.from(r,"utf8").toString("base64")).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function use(t){if(!t||t.indexOf("mpt_")!==0)return null;try{let e=t.slice(4).replace(/-/g,"+").replace(/_/g,"/"),r=e.length%4?"=".repeat(4-e.length%4):"",i=typeof atob=="function"?new TextDecoder().decode(Uint8Array.from(atob(e+r),s=>s.charCodeAt(0))):Buffer.from(e+r,"base64").toString("utf8"),n=JSON.parse(i);return!n||typeof n.path!="string"||!n.ds||!n.dss?null:n}catch{return null}}function lse(t){return{upload_id:"",state:"receiving",attempt:0,path:t.path,size:t.size,chunk_size:t.cs,total_chunks:t.tc,received:new Set,driver_session:t.dss,partMd5s:new Array(t.tc).fill(void 0),storage_driver:t.ds,created_at:Date.now()}}at.post("/multipart/init",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let r=decodeURIComponent(t.req.header("File-Path")||""),i=parseInt(t.req.header("X-File-Size")||"0",10),n=parseInt(t.req.header("X-Chunk-Size")||"0",10),s=t.req.header("X-File-Md5")||"";if(!r.trim()||i<=0)return t.json({code:400,message:"Missing File-Path / X-File-Size header",data:null},400);if(i>AO)return t.json({code:413,message:`File too large (max ${AO} bytes / 1GB)`,data:null},413);let{dir:a,name:o}=x1(r),c=Ve(e,a),u=kt(t);try{let l=await rt(c);if(l.isVirtual)throw new Error("failed get storage: storage not found");let d=await et(l.storage.driver,l.storage);if(typeof d.createUploadSession!="function")return t.json({code:200,message:"success",data:null});let A=cO(n),g=Math.max(1,Math.ceil(i/A)),f=lO(r,i),p=!1,y="";if(f)p=!0,y=f.upload_id;else{let E=await d.createUploadSession(c,l.physical,o,i,s);if(E?.reuse){let b={upload_id:"",state:"completed",attempt:0,path:r,size:i,chunk_size:A,total_chunks:g,received:new Set(Array.from({length:g},(B,k)=>k)),driver_session:"",partMd5s:new Array(g).fill(void 0),storage_driver:l.storage.driver,created_at:Date.now()},C=oa(b);return C.storage_progress=100,t.json({code:200,message:"success",data:C})}y=cse({path:r,size:i,cs:A,tc:g,ds:l.storage.driver,dss:E?.session||""}),f={upload_id:y,state:"receiving",attempt:0,path:r,size:i,chunk_size:A,total_chunks:g,received:new Set,driver_session:E?.session||"",partMd5s:new Array(g).fill(void 0),storage_driver:l.storage.driver,created_at:Date.now()},Nl(f)}await Qt(l.storage.driver,l.storage,d,u);let m=oa(f);return m.upload_id=y,t.json({code:200,message:"success",data:{...m,resumed:p}})}catch(l){return t.json({code:500,message:Pe(l),data:null},500)}});function Rh(t){let e=uO(t);if(e)return e;let r=use(t);if(!r)return null;let i=lse(r);return i.upload_id=t,i}at.put("/multipart/chunk",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let r=t.req.header("X-Upload-Id")||"",i=parseInt(t.req.header("X-Chunk-Index")||"-1",10),n=r?Rh(r):null;if(!n)return t.json({code:404,message:"upload session not found",data:null},404);if(i<0||i>=n.total_chunks)return t.json({code:400,message:"invalid X-Chunk-Index",data:null},400);if(n.received.has(i))return t.json({code:200,message:"success",data:oa(n)});let s=v1(t,!0);if(s!==null)return t.json({code:413,message:`Part too large (max ${s} bytes)`,data:null},413);let a=kt(t);try{let o=await rt(Ve(e,x1(n.path).dir));if(o.isVirtual)throw new Error("failed get storage: storage not found");let c=await et(o.storage.driver,o.storage);if(typeof c.uploadPart!="function")throw new Error("storage does not support chunked upload");let u=Buffer.from(await t.req.arrayBuffer()),l;try{l=await c.uploadPart(n.driver_session,i+1,u)}finally{await Qt(o.storage.driver,o.storage,c,a)}n.received.add(i),l?.partMd5&&(n.partMd5s[i]=l.partMd5),n.upload_id||(n.upload_id=r),Nl(n);let d=oa(n);return d.upload_id=r,t.json({code:200,message:"success",data:d})}catch(o){return t.json({code:500,message:Pe(o),data:null},500)}});at.get("/multipart/presign",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let r=t.req.query("upload_id")||"",i=parseInt(t.req.query("index")||"-1",10),n=r?Rh(r):null;if(!n)return t.json({code:404,message:"upload session not found",data:null},404);if(i<0||i>=n.total_chunks)return t.json({code:400,message:"invalid index",data:null},400);let s=kt(t);try{let a=await rt(Ve(e,x1(n.path).dir));if(a.isVirtual)throw new Error("failed get storage: storage not found");let o=await et(a.storage.driver,a.storage),c=o.getPartUploadUrl;if(typeof c!="function")return t.json({code:200,message:"success",data:null});let u=await c.call(o,n.driver_session,i+1);return await Qt(a.storage.driver,a.storage,o,s),t.json({code:200,message:"success",data:{index:i,part_number:i+1,url:u,total_chunks:n.total_chunks,chunk_size:n.chunk_size,path:n.path}})}catch(a){return t.json({code:500,message:Pe(a),data:null},500)}});at.get("/multipart/confirm",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let r=t.req.query("upload_id")||"",i=parseInt(t.req.query("index")||"-1",10),n=r?Rh(r):null;if(!n)return t.json({code:404,message:"upload session not found",data:null},404);if(i<0||i>=n.total_chunks)return t.json({code:400,message:"invalid index",data:null},400);n.received.add(i),n.upload_id||(n.upload_id=r),Nl(n);let s=oa(n);return s.upload_id=r,t.json({code:200,message:"success",data:s})});at.post("/multipart/complete",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let r=t.req.header("X-Upload-Id")||"",i=r?Rh(r):null;if(!i)return t.json({code:404,message:"upload session not found",data:null},404);if(i.state==="completed")return t.json({code:200,message:"success",data:oa(i)});let n=kt(t);try{let s=await rt(Ve(e,x1(i.path).dir));if(s.isVirtual)throw new Error("failed get storage: storage not found");let a=await et(s.storage.driver,s.storage);if(typeof a.completeUploadSession!="function")throw new Error("storage does not support chunked upload");try{await a.completeUploadSession(i.driver_session,i.partMd5s.filter(c=>c!==void 0))}finally{await Qt(s.storage.driver,s.storage,a,n)}i.state="completed",i.upload_id||(i.upload_id=r),Nl(i),dO(r);let o=oa(i);return o.upload_id=r,o.storage_progress=100,t.json({code:200,message:"success",data:o})}catch(s){return i.state="failed_permanent",i.error=Pe(s),Nl(i),t.json({code:500,message:Pe(s),data:null},500)}});at.get("/multipart/status",async t=>{let e=t.req.query("upload_id")||"",r=e?Rh(e):null;if(!r)return t.json({code:404,message:"upload session not found",data:null},404);let i=oa(r);return i.upload_id=e,t.json({code:200,message:"success",data:i})});function qb(t){let e=t.toLowerCase();return e.endsWith(".zip")?"zip":e.endsWith(".tar.gz")||e.endsWith(".tgz")?"tar.gz":e.endsWith(".tar.bz2")||e.endsWith(".tbz2")?"tar.bz2":e.endsWith(".tar.xz")||e.endsWith(".txz")?"tar.xz":e.endsWith(".tar")?"tar":e.endsWith(".7z")?"7z":e.endsWith(".rar")?"rar":null}function Hb(t){return t==="zip"}async function Kb(t,e,r){let i=Ve(e,r),n=await rt(i);if(n.isVirtual)throw new Error("failed get storage: storage not found");let s=await et(n.storage.driver,n.storage),a;try{a=await s.get(r,n.physical)}finally{await Qt(n.storage.driver,n.storage,s,kt(t))}if(!a||!a.raw_url)throw new Error("archive driver did not return download link");let o=zf(n.storage?.addition,t.env);Rr(a.raw_url,"Archive download",o);let c=await fetch(a.raw_url,{headers:a.raw_url_headers||{}});if(!c.ok)throw new Error(`archive download failed: HTTP ${c.status}`);return await c.arrayBuffer()}function dse(t){let e=[],r=new Map;for(let i of t.entries){let n=i.name.split("/").filter(Boolean);if(n.length===0)continue;let s=e,a="";for(let o=0;o<n.length;o++){let c=n[o],u=o===n.length-1;if(a=a?`${a}/${c}`:`/${c}`,u)s.push({name:c,size:i.size,is_dir:!1,modified:i.modified||new Date().toISOString(),type:hO(c,!1),children:[]});else{let l=r.get(a);l||(l={name:c,size:0,is_dir:!0,modified:i.modified||new Date().toISOString(),type:1,children:[]},r.set(a,l),s.push(l)),s=l.children}}}return e}function hO(t,e){let r=t.split(".").pop()?.toLowerCase()||"";if(e)return 1;let i=["mp4","mkv","webm","avi","mov","flv","m3u8"],n=["mp3","flac","wav","aac","ogg","m4a"],s=["jpg","jpeg","png","gif","webp","svg","bmp","ico"],a=["txt","md","json","js","ts","css","html","xml","yml","log"];return i.includes(r)?2:n.includes(r)?3:s.includes(r)?4:a.includes(r)?5:6}at.post("/archive/meta",async t=>{let e=await Ne(t);if(!e||e.disabled)return t.json({code:401,message:"Unauthorized",data:null},401);let r=await t.req.json().catch(()=>({})),i=String(r.path||t.req.query("path")||"").trim();if(!i)return t.json({code:400,message:"path is required",data:null},400);let n=qb(i);if(!n)return t.json({code:400,message:"unrecognized archive format",data:null},400);if(!Hb(n))return t.json({code:501,message:`archive format '${n}' is recognized but not supported in this runtime (Worker supports ZIP only); use the Go backend for ${n} archives`,data:null},501);try{let s=await Kb(t,e,i),a=I1(s),o=dse(a);return t.json({code:200,message:"success",data:{comment:"",encrypted:!1,content:o,raw_url:"",sign:""}})}catch(s){return t.json({code:500,message:Pe(s),data:null},500)}});at.post("/archive/list",async t=>{let e=await Ne(t);if(!e||e.disabled)return t.json({code:401,message:"Unauthorized",data:null},401);let r=await t.req.json().catch(()=>({})),i=String(r.path||t.req.query("path")||"").trim(),n=String(r.inner_path||"").trim().replace(/\/+/g,"/");if(!i)return t.json({code:400,message:"path is required",data:null},400);let s=qb(i);if(!s)return t.json({code:400,message:"unrecognized archive format",data:null},400);if(!Hb(s))return t.json({code:501,message:`archive format '${s}' is recognized but not supported in this runtime; use the Go backend for ${s} archives`,data:null},501);try{let a=await Kb(t,e,i),o=I1(a),c=n?n.replace(/^\/+|\/+$/g,"")+"/":"",u=o.entries.filter(A=>c?A.name.startsWith(c)&&A.name!==c.slice(0,-1):!A.name.includes("/")).map(A=>{let g=c?A.name.slice(c.length):A.name;return{name:g.split("/")[0],size:A.size,is_dir:!1,modified:A.modified||new Date().toISOString(),type:hO(g.split("/")[0],!1)}}),l=new Set,d=u.filter(A=>l.has(A.name)?!1:(l.add(A.name),!0));return t.json({code:200,message:"success",data:{content:d,total:d.length}})}catch(a){return t.json({code:500,message:Pe(a),data:null},500)}});at.post("/archive/decompress",async t=>{let e=await Ne(t);if(!ut(e))return t.json({code:403,message:"Permission denied",data:null},403);let r=await t.req.json().catch(()=>({})),i=String(r.src_dir||"").trim(),n=String(r.dst_dir||"").trim(),s=Array.isArray(r.name)?r.name:r.name?[String(r.name)]:[],a=String(r.inner_path||"").trim().replace(/\/+/g,"/");if(!s.length||!n)return t.json({code:400,message:"src_dir/dst_dir/name are required",data:null},400);try{let o=0;for(let c of s){let u=i?`${i}/${c}`:`/${c}`,l=qb(c);if(!l||!Hb(l))return t.json({code:400,message:`unsupported archive format: ${c} (only ZIP is supported)`,data:null},400);let d=await Kb(t,e,u),A=I1(d),g=a?a.replace(/^\/+|\/+$/g,"")+"/":"";for(let f of A.entries){if(g&&!f.name.startsWith(g))continue;let p=g?f.name.slice(g.length):f.name;if(!p||p.endsWith("/"))continue;let y=`${n.replace(/\/+$/,"")}/${p}`,m=await zU(d,f);await kn(y,Buffer.from(m),kt(t)),o++}}return t.json({code:200,message:"success",data:{task:null,count:o}})}catch(o){return t.json({code:500,message:Pe(o),data:null},500)}});jc();nr();Ye();Yt();g1();Co();async function H4(t,e,r,i=5){let n=t.req?.method;if(n!=="GET"&&n!=="HEAD")return r();let s=new URL(t.req.url);if(s.searchParams.has("token")||s.searchParams.has("access_token"))return r();let a=wL();if(!a)return r();let o;try{o=new Request(`${s.origin}${s.pathname}`,{method:"GET"})}catch{return r()}try{let u=await a.match(o);if(u)return u}catch{}let c=await r();if(c.status===200){let u=IL(c.clone(),i);try{await(t.executionCtx?.waitUntil?t.executionCtx.waitUntil(a.put(o,u.clone())):a.put(o,u.clone()))}catch{}return IL(c,i)}return c}function IL(t,e){let r=new Headers(t.headers);return r.set("Cache-Control",`public, max-age=0, must-revalidate, s-maxage=${e}`),new Response(t.body,{status:t.status,statusText:t.statusText,headers:r})}function wL(){try{if(typeof caches<"u"){let t=caches.default;if(t)return t}}catch{}return null}async function K4(t){let e=wL();if(!e)return;let r="";try{r=new URL(t.req.url).origin}catch{return}let i=["/api/public/settings","/api/public/init_status"];await Promise.all(i.map(async n=>{try{await e.delete(new Request(`${r}${n}`,{method:"GET"}))}catch{}}))}xd();nr();Ye();jc();jh();na();bi();P4();var Tn=new je;Tn.get("/list",async t=>{let r=((await se(t.env)).users||[]).map(i=>({id:i.id,username:i.username,role:i.role,permission:i.permission??0,base_path:i.base_path||"/",disabled:!!i.disabled,sso_id:i.sso_id||"",allow_ldap:!!i.allow_ldap,pwd_update_at:i.pwd_update_at||"",otp:!!i.otp_secret}));return t.json({code:200,message:"success",data:{content:r,total:r.length}})});Tn.get("/get",async t=>{let e=t.req.query("id");if(!e)return t.json({code:400,message:"Missing id parameter",data:null},400);let r=parseInt(e,10),n=((await se(t.env)).users||[]).find(s=>s.id===r);return n?t.json({code:200,message:"success",data:{id:n.id,username:n.username,password:"",role:n.role,permission:n.permission??0,base_path:n.base_path||"/",disabled:!!n.disabled,sso_id:n.sso_id||"",allow_ldap:!!n.allow_ldap,otp:!!n.otp_secret}}):t.json({code:404,message:"User not found",data:null},404)});Tn.post("/create",async t=>{let e=await t.req.json().catch(()=>({}));if(!e.username)return t.json({code:400,message:"Username is required",data:null},400);let r=await se(t.env);if(r.users||(r.users=[]),r.users.some(u=>u.username===e.username))return t.json({code:400,message:"Username already exists",data:null},400);let s=r.users.reduce((u,l)=>Math.max(u,l.id||0),0)+1,a=e.password||"",o=null;a||(o=Jl(),a=o);let c={id:s,username:e.username,role:e.role!==void 0?parseInt(e.role,10):0,permission:e.permission!==void 0?parseInt(e.permission,10):0,base_path:e.base_path||"/",disabled:!!e.disabled,sso_id:e.sso_id||"",allow_ldap:!!e.allow_ldap,pwd_update_at:new Date().toISOString()};return await Si(c,a),r.users.push(c),await de(r,t.env),t.json({code:200,message:o?"success (a random password was generated \u2014 pass one explicitly to choose your own)":"success",data:o?{password:o}:null})});Tn.post("/update",async t=>{let e=await t.req.json().catch(()=>({}));if(!e.id)return t.json({code:400,message:"User ID is required",data:null},400);let r=parseInt(e.id,10),i=await se(t.env);i.users||(i.users=[]);let n=i.users.findIndex(a=>a.id===r);if(n===-1)return t.json({code:404,message:"User not found",data:null},404);let s=i.users[n];if(e.username&&e.username!==s.username){if(i.users.some(o=>o.id!==r&&o.username===e.username))return t.json({code:400,message:"Username already in use",data:null},400);s.username=e.username}return e.password&&e.password.trim()!==""&&await Si(s,e.password.trim()),e.role!==void 0&&(s.role=parseInt(e.role,10)),e.permission!==void 0&&(s.permission=parseInt(e.permission,10)),e.base_path!==void 0&&(s.base_path=e.base_path),e.disabled!==void 0&&(s.disabled=!!e.disabled),e.sso_id!==void 0&&(s.sso_id=e.sso_id),e.allow_ldap!==void 0&&(s.allow_ldap=!!e.allow_ldap),i.users[n]=s,await de(i,t.env),t.json({code:200,message:"success",data:null})});var EL=async t=>{let e=t.req.query("id");if(!e)return t.json({code:400,message:"Missing id parameter",data:null},400);let r=parseInt(e,10);if(r===1)return t.json({code:400,message:"Cannot delete primary admin user",data:null},400);let i=await se(t.env);return i.users||(i.users=[]),i.users=i.users.filter(n=>n.id!==r),await de(i,t.env),t.json({code:200,message:"success",data:null})};Tn.post("/delete",EL);Tn.post("/cancel",EL);Tn.get("/sshkey/list",async t=>{let e=parseInt(t.req.query("uid")||"0",10),r=await Hl(e,t.env);return t.json({code:200,message:"success",data:{content:r,total:r.length}})});Tn.post("/sshkey/delete",async t=>{let e=parseInt(t.req.query("uid")||"0",10),r=t.req.query("id");if(!e||!r)return t.json({code:400,message:"Missing uid or id parameter",data:null},400);if(!await Z1(e,r,t.env))return t.json({code:404,message:"SSH key not found",data:null},404);let n=await Hl(e,t.env);return t.json({code:200,message:"success",data:n})});Tn.post("/cancel_2fa",async t=>{let e=parseInt(t.req.query("id")||"0",10);if(!e)return t.json({code:400,message:"Missing id parameter",data:null},400);let r=await se(t.env),i=(r.users||[]).find(n=>n.id===e);return i?(delete i.otp_secret,await de(r,t.env),t.json({code:200,message:"success",data:null})):t.json({code:404,message:"User not found",data:null},404)});var CL=async t=>{let e=t.req.header("Authorization");if(!e)return t.json({code:401,message:"Unauthorized",data:null},401);let r=e.startsWith("Bearer ")?e.substring(7):e;try{let i=await Er(t),n=await ra(r,i,"HS256"),s=await t.req.json().catch(()=>({})),a=s.old_password||"",o=s.new_password||"";if(!o)return t.json({code:400,message:"New password is required",data:null},400);let c=await se(t.env);c.users||(c.users=[]);let u=c.users.findIndex(d=>d.id===n.id||d.username===n.username);if(u===-1)return t.json({code:404,message:"User not found",data:null},404);let l=c.users[u];return!l.password||!await zl(l,a)?t.json({code:400,message:"Incorrect old password",data:null},400):(await Si(l,o),c.users[u]=l,await de(c,t.env),t.json({code:200,message:"success",data:null}))}catch(i){return t.json({code:401,message:`Unauthorized: ${i.message||"Invalid token"}`,data:null},401)}};var Fe=new je;Fe.use("*",async(t,e)=>{if(!await Sl(t))return t.json({code:401,message:"Unauthorized",data:null});await e()});function Qae(t=32){let e="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",r=new Uint8Array(t);if(typeof crypto<"u"&&typeof crypto.getRandomValues=="function")crypto.getRandomValues(r);else for(let n=0;n<t;n++)r[n]=(Math.random()*256|0)^Date.now()&255;let i="";for(let n=0;n<t;n++)i+=e.charAt(r[n]%e.length);return i}Fe.get("/storage/list",async t=>{let r=[...(await se(t.env)).storages||[]].sort((i,n)=>{let s=Number(i.order)||0,a=Number(n.order)||0;return s!==a?s-a:(Number(i.id)||0)-(Number(n.id)||0)});return t.json({code:200,message:"success",data:{content:r,total:r.length}})});Fe.post("/storage/load_all",async t=>{let e=await se(t.env),r=[],i=0,n=0;for(let s of e.storages||[])if(!s.disabled)try{await et(s.driver,s),i++,r.push({id:s.id,mount_path:s.mount_path,driver:s.driver,status:"ok"})}catch(a){n++,r.push({id:s.id,mount_path:s.mount_path,driver:s.driver,status:"failed",error:a?.message||String(a)})}return t.json({code:200,message:"success",data:{loaded:i,failed:n,results:r}})});Fe.get("/storage/get",async t=>{let e=parseInt(t.req.query("id")||"0",10),i=(await se(t.env)).storages.find(n=>n.id===e);return i?t.json({code:200,message:"success",data:i}):t.json({code:404,message:"storage not found",data:null})});var bL=t=>{let e=(t||"").toLowerCase().replace(/[^a-z0-9]/g,"");if(!e)return"";let i=Object.keys(Vl).find(n=>n.toLowerCase()===e||n.toLowerCase().replace(/[^a-z0-9]/g,"")===e);return i||(e.startsWith("115")?"115Open":e.startsWith("123")?"123Pan":e.includes("aliyun")?"AliyundriveOpen":e.startsWith("baidu")?"BaiduNetdisk":e.startsWith("189")||e.includes("cloud189")||e.includes("ctyun")?"Cloud189":e==="onedriveapp"?"OnedriveAPP":e.startsWith("onedrive")?"Onedrive":e.startsWith("google")||e.includes("gdrive")?"GoogleDrive":(e.includes("thunder")||e.includes("xunlei"))&&e.includes("expert")?"ThunderExpert":e.includes("thunder")||e.includes("xunlei")?"Thunder":e==="webdav"||e==="webdavdriver"?"WebDav":e==="wopan"||e.includes("unicom")||e.includes("woyun")?"WoPan":e==="quark"||e==="quarkuc"||e==="uc"?"Quark":["s3","doge","dogecloud","minio","ceph","aws","r2","b2","cos","oss","kodo"].includes(e)?"S3":e.startsWith("github")?"Github":e==="local"?"Local":e.includes("pikpak")?"PikPak":e.includes("seafile")?"Seafile":e.includes("yandex")?"YandexDisk":e.includes("terabox")||e.includes("dubox")?"Terabox":e.includes("mediatrack")||e.includes("fenmiao")?"MediaTrack":e.includes("alias")?"Alias":t||"")},DL=(t,e)=>{let r="";if(typeof e=="object"&&e!==null)try{r=JSON.stringify(e)}catch{r="{}"}else r=String(e||"{}");let i=(t||"").toLowerCase();if(i.includes("thunder")||i.includes("xunlei"))try{let n=JSON.parse(r||"{}");if(!n.device_id||typeof n.device_id!="string"||n.device_id.trim().length!==32){let s=typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID().replace(/-/g,""):Math.random().toString(16).substring(2).padEnd(16,"0")+Math.random().toString(16).substring(2).padEnd(16,"0");return n.device_id=s.slice(0,32),JSON.stringify(n)}}catch{}return r};Fe.post("/storage/create",async t=>{let e=await t.req.json().catch(()=>({})),r=await se(t.env);if(!e.driver||typeof e.driver!="string"||e.driver.trim()===""||e.driver==="undefined"||e.driver==="null")return t.json({code:400,message:"Storage driver is required",data:null},400);let i=e.mount_path;if(!i||String(i).trim()===""){let c=Vl[e.driver]?.default_mount_path;c&&(i=c)}let n="/"+String(i||"").split("/").filter(Boolean).join("/");if(r.storages.some(c=>!c.disabled&&"/"+(c.mount_path||"").split("/").filter(Boolean).join("/")===n))return t.json({code:400,message:`mount path already exists: ${n}`,data:null});let s=bL(e.driver),a=DL(s,e.addition||"{}"),o={...e,driver:s,addition:a,mount_path:n,id:r.storages.length?Math.max(...r.storages.map(c=>c.id))+1:1,status:"work",modified:new Date().toISOString()};r.storages.push(o);try{await de(r,t.env)}catch(c){return r.storages.pop(),t.json({code:500,message:`Failed to save storage config: ${c.message||String(c)}`,data:null})}if(!o.disabled){try{await et(o.driver,o),o.status="work"}catch(c){o.status=c.message||String(c),String(c.message||c).includes("unsupported driver")&&(o.disabled=!0);try{await de(r,t.env)}catch(u){console.error("[admin/storage/create] Failed to update storage status:",u)}return t.json({code:500,message:c.message||String(c),data:o})}try{await de(r,t.env)}catch(c){console.error("[admin/storage/create] Failed to update storage status after connection:",c)}}return t.json({code:200,message:"success",data:o})});Fe.post("/storage/update",async t=>{let e=await t.req.json().catch(()=>({})),r=await se(t.env),i=e.mount_path;if(!i||String(i).trim()===""){let a=Vl[e.driver]?.default_mount_path;a&&(i=a)}let n=String(i||"").trim()!==""?"/"+String(i||"").split("/").filter(Boolean).join("/"):void 0;if(n&&r.storages.some(a=>a.id!==e.id&&!a.disabled&&"/"+(a.mount_path||"").split("/").filter(Boolean).join("/")===n))return t.json({code:400,message:`mount path already exists: ${n}`,data:null});let s=r.storages.findIndex(a=>a.id===e.id);if(s!==-1){let a=e.driver||r.storages[s].driver,o=bL(a),c=DL(o,e.addition!==void 0?e.addition:r.storages[s].addition||"{}"),u={...r.storages[s],...e,driver:o,addition:c,mount_path:n||r.storages[s].mount_path,modified:new Date().toISOString()};if(!u.disabled)try{await et(u.driver,u,{deferTokenPersistence:!0}),u.status="work"}catch(l){return u.status=l.message||String(l),String(l.message||l).includes("unsupported driver")&&(u.disabled=!0),r.storages[s]=u,await de(r,t.env),t.json({code:500,message:l.message||String(l),data:{id:u.id}})}r.storages[s]=u,await de(r,t.env)}return t.json({code:200,message:"success",data:null})});Fe.post("/storage/delete",async t=>{let e=parseInt(t.req.query("id")||"0",10),r=await se(t.env);return r.storages=r.storages.filter(i=>i.id!==e),await de(r,t.env),t.json({code:200,message:"success",data:null})});Fe.post("/storage/enable",async t=>{let e=parseInt(t.req.query("id")||"0",10),r=await se(t.env),i=r.storages.find(n=>n.id===e);return i&&(i.disabled=!1,i.modified=new Date().toISOString(),await de(r,t.env),(async()=>{try{await et(i.driver,i);let n=await se(t.env),s=n.storages.find(a=>a.id===e);s&&!s.disabled&&(s.status="work",s.modified=new Date().toISOString(),await de(n,t.env))}catch(n){let s=await se(t.env),a=s.storages.find(o=>o.id===e);a&&!a.disabled&&(a.status=n.message||String(n),await de(s,t.env))}})()),t.json({code:200,message:"success",data:null})});Fe.post("/storage/disable",async t=>{let e=parseInt(t.req.query("id")||"0",10),r=await se(t.env),i=r.storages.find(n=>n.id===e);return i&&(i.disabled=!0,await de(r,t.env)),t.json({code:200,message:"success",data:null})});Fe.get("/driver/names",t=>t.json({code:200,message:"success",data:["AliyundriveOpen","GoogleDrive","Onedrive","OnedriveAPP","Quark","123Pan","BaiduNetdisk","115Open","GitHub API","Thunder","ThunderExpert","189Cloud","WoPan","Lanzou","WebDav","S3","Doge","PikPak","Seafile","YandexDisk","Terabox","MediaTrack","Alias","Dropbox","WPS","139Yun","Mega_nz","115Share","123PanShare","AliyundriveShare","OnedriveSharelink","PikPakShare","SMB","Crypt","Virtual","AListV3","UrlTree","Strm","AzureBlob","USS","Alidoc","Emby","BunnyStorage","CloudflareImgbed","GuangYaPan","AutoIndex","ProtonDrive"]}));var Tt=[{name:"mount_path",type:"string",default:"",required:!0},{name:"order",type:"number",default:"0",required:!1},{name:"remark",type:"string",default:"",required:!1},{name:"cache_expiration",type:"number",default:"30",required:!1,help:"\u76EE\u5F55\u5185\u5BB9\u7F13\u5B58\u65F6\u957F\uFF08\u5206\u949F\uFF09"}],Pt={name:"custom_cache_policies",type:"text",default:"",required:!1,help:'\u6309\u8DEF\u5F84\u8986\u76D6\u7F13\u5B58\u65F6\u957F\uFF0CJSON \u683C\u5F0F\uFF0C\u5982 [{"path":"/photos/*","cache_expiration":1440}]'},Ft={name:"enable_sign",type:"bool",default:"false",required:!0,help:"Enable signature validation for this storage"},Nt={name:"disable_index",type:"bool",default:"false",required:!1,help:"Disable directory listing for this storage"};function Tae(){return{name:"proxy_range",type:"bool",default:"true",required:!1,help:"Need to enable proxy"}}var BL={name:"web_proxy",type:"bool",default:"false",required:!1},G4={name:"webdav_policy",type:"select",options:"302_redirect,use_proxy_url,native_proxy",default:"302_redirect",required:!1};function Rt(t=""){let e=$o(t),r=mx.has(e)?[Tae()]:[];if(Ix(e))return[...r,{...G4,options:"use_proxy_url,native_proxy",default:"native_proxy"}];let i=q2(e);return[...r,i?{...BL,default:"true"}:{...BL},i?{...G4,default:"native_proxy"}:{...G4}]}var Zt={name:"seed_policy",type:"select",options:"inherit,on,off",default:"inherit",required:!0,help:"Override automatic transfer-seed generation for this storage"},Vc={name:"down_proxy_url",type:"string",default:"",required:!1,help:"\u81EA\u5B9A\u4E49\u4E0B\u8F7D\u4EE3\u7406\u5730\u5740\uFF08\u652F\u6301 $path \u5360\u4F4D\u7B26\uFF1B\u7559\u7A7A\u5219\u7528\u672C\u670D\u52A1\u4EE3\u7406\uFF09"},Ut={name:"disable_proxy_sign",type:"bool",default:"false",required:!1,help:"Disable sign for Download proxy URL"},ft=[...Tt,Pt,Ft,Nt,...Rt(),Vc,Ut,Zt],Vl={AliyundriveOpen:{name:"AliyundriveOpen",default_mount_path:"/aliyundrive",common:ft,additional:[{name:"refresh_token",type:"text",default:"",required:!0,help:"true"},{name:"drive_type",type:"select",options:"resource,backup,default",default:"resource",required:!0},{name:"drive_id",type:"string",default:"",required:!1},{name:"root_folder_id",type:"string",default:"root",required:!0},{name:"order_by",type:"select",options:"updated_at,name,size,created_at",default:"updated_at",required:!1},{name:"order_direction",type:"select",options:"DESC,ASC",default:"DESC",required:!1},{name:"api_url_address",type:"string",default:"https://api.oplist.org/alicloud/renewapi",required:!1,help:"true"},{name:"alipan_type",type:"select",options:"alipanQR,alipanTV",default:"alipanQR",required:!1},{name:"client_id",type:"string",default:"",required:!1},{name:"client_secret",type:"string",default:"",required:!1},{name:"remove_way",type:"select",options:"trash,delete",default:"trash",required:!1}],config:{name:"AliyundriveOpen",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"root"}},Onedrive:{name:"Onedrive",default_mount_path:"/onedrive",common:[...Tt,Pt,Ft,Nt,...Rt("Onedrive"),Vc,Ut],additional:[{name:"root_folder_path",type:"string",default:"/",required:!0},{name:"region",type:"select",options:"global,cn,us,de",default:"global",required:!0},{name:"is_sharepoint",type:"bool",default:"false",required:!1},{name:"use_online_api",type:"bool",default:"true",required:!1},{name:"api_url_address",type:"string",default:"https://api.oplist.org/onedrive/renewapi",required:!1},{name:"client_id",type:"string",default:"",required:!1},{name:"client_secret",type:"string",default:"",required:!1},{name:"redirect_uri",type:"string",default:"https://api.oplist.org/onedrive/callback",required:!0},{name:"refresh_token",type:"string",default:"",required:!0},{name:"site_id",type:"string",default:"",required:!1},{name:"chunk_size",type:"number",default:"5",required:!1},{name:"custom_host",type:"string",default:"",required:!1,help:"true"},{name:"disable_disk_usage",type:"bool",default:"false",required:!1,help:"true"},{name:"enable_direct_upload",type:"bool",default:"false",required:!1,help:"true"},{name:"order_by",type:"select",options:"filename,modified_time,size",default:"filename",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"Onedrive",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},OnedriveAPP:{name:"OnedriveAPP",default_mount_path:"/onedrive_app",common:[...Tt,Pt,Ft,Nt,...Rt("OnedriveAPP"),Vc,Ut],additional:[{name:"root_folder_path",type:"string",default:"/",required:!0},{name:"region",type:"select",options:"global,cn,us,de",default:"global",required:!0},{name:"client_id",type:"string",default:"",required:!0},{name:"client_secret",type:"string",default:"",required:!0},{name:"tenant_id",type:"string",default:"",required:!0},{name:"email",type:"string",default:"",required:!0},{name:"chunk_size",type:"number",default:"5",required:!1},{name:"custom_host",type:"string",default:"",required:!1,help:"true"},{name:"disable_disk_usage",type:"bool",default:"false",required:!1,help:"true"},{name:"enable_direct_upload",type:"bool",default:"false",required:!1,help:"true"},{name:"order_by",type:"select",options:"filename,modified_time,size",default:"filename",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"OnedriveAPP",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},GoogleDrive:{name:"GoogleDrive",default_mount_path:"/google-drive",common:[...Tt,Pt,Ft,Nt,...Rt("GoogleDrive"),Ut,Zt],additional:[{name:"refresh_token",type:"text",default:"",required:!0,help:"true"},{name:"root_folder_id",type:"string",default:"root",required:!1},{name:"order_by",type:"select",options:"folder,name,modifiedTime desc",default:"folder,name,modifiedTime desc",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1},{name:"api_url_address",type:"string",default:"https://api.alist.nn.ci/googledrive/token",required:!1,help:"true"},{name:"use_online_api",type:"bool",default:"true",required:!1},{name:"client_id",type:"string",default:"",required:!1},{name:"client_secret",type:"string",default:"",required:!1},{name:"chunk_size",type:"number",default:"5",required:!1}],config:{name:"GoogleDrive",local_sort:!0,only_local:!1,only_proxy:!0,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"root"}},Quark:{name:"Quark",default_mount_path:"/quark",common:ft,additional:[{name:"variant",type:"select",options:"Quark,UC",default:"Quark",required:!0},{name:"cookie",type:"text",default:"",required:!0,help:"true"},{name:"root_folder_id",type:"string",default:"0",required:!0},{name:"order_by",type:"select",options:"none,file_type,file_name,updated_at",default:"none",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1},{name:"use_transcoding_address",type:"bool",default:"false",required:!1},{name:"only_list_video_file",type:"bool",default:"false",required:!1}],config:{name:"Quark",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"0"}},"123Pan":{name:"123Pan",default_mount_path:"/123",common:[...Tt,Pt,Ft,Nt,...Rt("123Pan"),Ut,Zt],additional:[{name:"username",type:"string",default:"",required:!0},{name:"password",type:"string",default:"",required:!0},{name:"access_token",type:"string",default:"",required:!1,help:"\u767B\u5F55\u4EE4\u724C\uFF08\u53EF\u9009\uFF0C\u81EA\u52A8\u6301\u4E45\u5316\uFF0C\u65E0\u9700\u624B\u52A8\u586B\u5199\uFF09\u3002\u4EC5\u9700\u586B\u5199\u4E0A\u65B9 123 \u7F51\u76D8\u624B\u673A\u53F7\u548C\u5BC6\u7801\uFF0C\u767B\u5F55\u540E\u81EA\u52A8\u83B7\u53D6\u5E76\u4FDD\u5B58\uFF0C\u8DF3\u8FC7\u91CD\u590D\u767B\u5F55\u53EF\u907F\u514D\u5883\u5916 IP \u89E6\u53D1\u98CE\u63A7\u3002"},{name:"cookie",type:"text",default:"",required:!1,help:"\u6D4F\u89C8\u5668 Cookie\uFF08\u53EF\u9009\uFF09\u3002\u5728 123 \u7F51\u76D8\u7F51\u9875\u767B\u5F55\u540E\uFF0C\u4ECE\u5F00\u53D1\u8005\u5DE5\u5177\u590D\u5236\u8BF7\u6C42\u5934\u4E2D\u7684 Cookie \u6574\u4E32\u7C98\u8D34\u4E8E\u6B64\uFF08\u542B sso-token\uFF09\uFF0C\u6216\u4ECE Authorization: Bearer <token> \u4E2D\u590D\u5236 token/Bearer \u503C\u3002\u89E3\u6790\u51FA\u7684 JWT \u4F1A\u4F5C\u4E3A Bearer \u4EE4\u724C\u4F7F\u7528\uFF0C\u6548\u679C\u7B49\u540C\u8BBF\u95EE\u4EE4\u724C\uFF0C\u9002\u5408\u8D26\u53F7\u5BC6\u7801\u767B\u5F55\u88AB\u98CE\u63A7\u62E6\u622A\u7684\u73AF\u5883\u3002"},{name:"root_id",type:"string",default:"0",required:!1},{name:"upload_thread",type:"number",default:"3",required:!1,help:"the threads of upload"},{name:"platform",type:"string",default:"web",required:!1,help:"the platform header value, sent with API requests"},{name:"order_by",type:"select",options:"file_id,file_name,size,created_at,updated_at",default:"file_id",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"desc",required:!1}],config:{name:"123Pan",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"0"}},BaiduNetdisk:{name:"BaiduNetdisk",default_mount_path:"/baidu",common:[...Tt,Pt,Ft,Nt,...Rt("BaiduNetdisk"),Ut,Zt],additional:[{name:"refresh_token",type:"text",default:"",required:!0,help:"true"},{name:"access_token",type:"string",default:"",required:!0,help:"\u8BBF\u95EE\u4EE4\u724C\uFF08\u5FC5\u586B\uFF09\u3002\u901A\u8FC7 https://api.oplist.org/ \u83B7\u53D6\u3002\u82E5\u4EE4\u724C\u5931\u6548\uFF0C\u6302\u8F7D\u65F6\u4F1A\u81EA\u52A8\u6839\u636E refresh_token \u901A\u8FC7\u5728\u7EBF API \u6362\u65B0\u5E76\u6301\u4E45\u5316\u3002"},{name:"use_online_api",type:"bool",default:"true",required:!1,help:"\u4F7F\u7528\u5728\u7EBF API \u5237\u65B0 token\uFF08\u65E0\u9700 ClientID/ClientSecret\uFF09"},{name:"api_url_address",type:"string",default:"https://api.oplist.org/baiduyun/renewapi",required:!1},{name:"client_id",type:"string",default:"",required:!1},{name:"client_secret",type:"string",default:"",required:!1},{name:"download_api",type:"select",options:"official,crack,crack_video",default:"official",required:!1},{name:"custom_crack_ua",type:"string",default:"netdisk",required:!0},{name:"order_by",type:"select",options:"name,time,size",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1},{name:"only_list_video_file",type:"bool",default:"false",required:!1},{name:"upload_thread",type:"string",default:"3",required:!1,help:"1<=thread<=32"},{name:"upload_timeout",type:"number",default:"60",required:!1,help:"per-slice upload timeout in seconds"},{name:"custom_upload_part_size",type:"number",default:"0",required:!1,help:"0 for auto"},{name:"use_dynamic_upload_api",type:"bool",default:"true",required:!1,help:"dynamically get upload api domain, when enabled, the 'Upload API' setting will be used as a fallback if failed to get"},{name:"upload_api",type:"string",default:"https://d.pcs.baidu.com",required:!1},{name:"low_bandwith_upload_mode",type:"bool",default:"false",required:!1}],config:{name:"BaiduNetdisk",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},"115Open":{name:"115Open",default_mount_path:"/115",common:[...Tt,Pt,Ft,Nt,...Rt("115Open"),Ut,Zt],additional:[{name:"access_token",type:"string",default:"",required:!0,help:"\u8BBF\u95EE\u4EE4\u724C\uFF08\u5FC5\u586B\uFF09\u3002\u901A\u8FC7 115 \u5F00\u653E\u5E73\u53F0\u83B7\u53D6\uFF1B\u5931\u6548\u65F6\u81EA\u52A8\u7528 refresh_token \u5237\u65B0\u5E76\u6301\u4E45\u5316\u3002"},{name:"refresh_token",type:"string",default:"",required:!0,help:"\u5237\u65B0\u4EE4\u724C\uFF08\u5FC5\u586B\uFF09\u3002\u901A\u8FC7 115 \u5F00\u653E\u5E73\u53F0\u83B7\u53D6\uFF1Baccess_token \u5931\u6548\u65F6\u81EA\u52A8\u5237\u65B0\u3002"},{name:"root_id",type:"string",default:"0",required:!1,help:"\u6839\u6587\u4EF6\u5939 ID\uFF0C\u9ED8\u8BA4 0\uFF08\u6839\u76EE\u5F55\uFF09"},{name:"order_by",type:"select",options:"file_name,file_size,user_utime,file_type",default:"file_name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1},{name:"page_size",type:"number",default:"200",required:!1,help:"list api per page size (1~1150)"},{name:"limit_rate",type:"float",default:"1",required:!1,help:"limit all api request rate ([limit]r/1s)\uFF0C0 \u8868\u793A\u4E0D\u9650\u901F"}],config:{name:"115Open",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"0"}},"GitHub API":{name:"GitHub API",default_mount_path:"/github",common:ft,additional:[{name:"root_folder_path",type:"string",default:"/",required:!0},{name:"token",type:"string",default:"",required:!0},{name:"owner",type:"string",default:"",required:!0},{name:"repo",type:"string",default:"",required:!0},{name:"ref",type:"string",default:"",required:!1,help:"A branch, a tag or a commit SHA, default branch by default."},{name:"gh_proxy",type:"string",default:"",required:!1,help:"GitHub proxy, e.g. https://ghproxy.net/raw.githubusercontent.com"},{name:"committer_name",type:"string",default:"",required:!1},{name:"committer_email",type:"string",default:"",required:!1},{name:"author_name",type:"string",default:"",required:!1},{name:"author_email",type:"string",default:"",required:!1},{name:"mkdir_commit_message",type:"text",default:"{{.UserName}} mkdir {{.ObjPath}}",required:!1},{name:"delete_commit_message",type:"text",default:"{{.UserName}} remove {{.ObjPath}}",required:!1},{name:"put_commit_message",type:"text",default:"{{.UserName}} upload {{.ObjPath}}",required:!1},{name:"rename_commit_message",type:"text",default:"{{.UserName}} rename {{.ObjPath}} to {{.TargetName}}",required:!1},{name:"copy_commit_message",type:"text",default:"{{.UserName}} copy {{.ObjPath}} to {{.TargetPath}}",required:!1},{name:"move_commit_message",type:"text",default:"{{.UserName}} move {{.ObjPath}} to {{.TargetPath}}",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"GitHub API",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},Thunder:{name:"Thunder",default_mount_path:"/thunder",common:ft,additional:[{name:"root_folder_id",type:"string",default:"",required:!1},{name:"username",type:"string",default:"",required:!0},{name:"password",type:"string",default:"",required:!0},{name:"captcha_token",type:"string",default:"",required:!1},{name:"credit_key",type:"string",default:"",required:!1,help:"credit key, used for login"},{name:"device_id",type:"string",default:"",required:!1,help:"32 hex characters"},{name:"space",type:"string",default:"",required:!1,help:"device id for remote device"},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"Thunder",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:""}},ThunderExpert:{name:"ThunderExpert",default_mount_path:"/thunderexpert",common:ft,additional:[{name:"root_folder_id",type:"string",default:"",required:!1},{name:"login_type",type:"select",options:"user,refresh_token",default:"user",required:!0},{name:"sign_type",type:"select",options:"algorithms,captcha_sign",default:"algorithms",required:!0},{name:"username",type:"string",default:"",required:!1,help:"login type is user, this is required"},{name:"password",type:"string",default:"",required:!1,help:"login type is user, this is required"},{name:"refresh_token",type:"string",default:"",required:!1,help:"login type is refresh_token, this is required"},{name:"algorithms",type:"string",default:"9uJNVj/wLmdwKrJaVj/omlQ,Oz64Lp0GigmChHMf/6TNfxx7O9PyopcczMsnf,Eb+L7Ce+Ej48u,jKY0,ASr0zCl6v8W4aidjPK5KHd1Lq3t+vBFf41dqv5+fnOd,wQlozdg6r1qxh0eRmt3QgNXOvSZO6q/GXK,gmirk+ciAvIgA/cxUUCema47jr/YToixTT+Q6O,5IiCoM9B1/788ntB,P07JH0h6qoM6TSUAK2aL9T5s2QBVeY9JWvalf,+oK0AN",required:!1},{name:"captcha_sign",type:"string",default:"",required:!1},{name:"timestamp",type:"string",default:"",required:!1},{name:"captcha_token",type:"string",default:"",required:!1},{name:"credit_key",type:"string",default:"",required:!1,help:"credit key, used for login"},{name:"device_id",type:"string",default:"",required:!1},{name:"client_id",type:"string",default:"",required:!0,help:"\u8FC5\u96F7\u5F00\u653E\u5E73\u53F0 OAuth client_id\uFF08\u5FC5\u586B\uFF09\u3002"},{name:"client_secret",type:"string",default:"",required:!0,help:"\u8FC5\u96F7\u5F00\u653E\u5E73\u53F0 OAuth client_secret\uFF08\u5FC5\u586B\uFF09\u3002"},{name:"client_version",type:"string",default:"8.31.0.9726",required:!0},{name:"package_name",type:"string",default:"com.xunlei.downloadprovider",required:!0},{name:"user_agent",type:"string",default:"ANDROID-com.xunlei.downloadprovider/8.31.0.9726 netWorkType/5G appid/40 deviceName/Xiaomi_M2004j7ac deviceModel/M2004J7AC OSVersion/12 protocolVersion/301 platformVersion/10 sdkVersion/512000 Oauth2Client/0.9 (Linux 4_14_186-perf-gddfs8vbb238b) (JAVA 0)",required:!0},{name:"download_user_agent",type:"string",default:"Dalvik/2.1.0 (Linux; U; Android 12; M2004J7AC Build/SP1A.210812.016)",required:!0},{name:"use_video_url",type:"bool",default:"false",required:!1},{name:"space",type:"string",default:"",required:!1,help:"device id for remote device"},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"ThunderExpert",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:""}},"189Cloud":{name:"189Cloud",default_mount_path:"/189",common:[...Tt,Pt,Ft,Nt,...Rt("189Cloud"),Ut,Zt],additional:[{name:"username",type:"string",default:"",required:!0,help:"the phone number used to log in"},{name:"password",type:"string",default:"",required:!0,help:"password for login"},{name:"cookie",type:"text",default:"",required:!1,help:"Fill in the cookie if need captcha (\u82E5\u9047\u6ED1\u5757\u9A8C\u8BC1\u7801\u6216\u8BBE\u5907\u9501\uFF0C\u53EF\u5728\u6D4F\u89C8\u5668\u767B\u5F55\u540E\u590D\u5236 Cookie \u586B\u5165)"},{name:"root_folder_id",type:"string",default:"-11",required:!1,help:"\u6839\u6587\u4EF6\u5939ID\uFF0C\u9ED8\u8BA4\u4E3A -11\uFF08\u4E2A\u4EBA\u4E91\u6839\u76EE\u5F55\uFF09"},{name:"order_by",type:"select",options:"lastOpTime,filename,fileSize",default:"lastOpTime",required:!1},{name:"order_direction",type:"select",options:"desc,asc",default:"desc",required:!1}],config:{name:"189Cloud",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"-11"}},Lanzou:{name:"Lanzou",default_mount_path:"/lanzou",common:ft,additional:[{name:"type",type:"select",options:"cookie,account,url",default:"cookie",required:!0},{name:"account",type:"string",default:"",required:!1,help:"\u8D26\u53F7\uFF08\u624B\u673A\u53F7/UID\uFF09\uFF0C\u4EC5 account \u6A21\u5F0F\u9700\u586B\u5199"},{name:"password",type:"string",default:"",required:!1,help:"\u5BC6\u7801\uFF0C\u4EC5 account \u6A21\u5F0F\u9700\u586B\u5199"},{name:"cookie",type:"text",default:"",required:!1,help:"\u767B\u5F55 Cookie\uFF08\u542B ylogin, phpdisk_info \u7B49\uFF09\uFF0Ccookie \u6A21\u5F0F\u9700\u586B\u5199\uFF1B\u6709\u6548\u671F\u7EA6 15 \u5929"},{name:"root_folder_id",type:"string",default:"-1",required:!1,help:"\u6839\u6587\u4EF6\u5939 ID / \u5206\u4EAB ID\uFF08\u4E2A\u4EBA\u76D8\u9ED8\u8BA4 -1\uFF0C\u5206\u4EAB\u94FE\u63A5\u586B\u5206\u4EAB ID \u5982 b00xxxx\uFF09"},{name:"share_password",type:"string",default:"",required:!1,help:"\u63D0\u53D6\u7801 / \u8BBF\u95EE\u5BC6\u7801\uFF08\u65E0\u5BC6\u7801\u7559\u7A7A\uFF09"},{name:"baseUrl",type:"string",default:"https://pc.woozooo.com",required:!1,help:"\u57FA\u672C API \u57DF\u540D"},{name:"shareUrl",type:"string",default:"https://pan.lanzoui.com",required:!1,help:"\u5206\u4EAB\u9875\u9762\u89E3\u6790\u57DF\u540D"},{name:"user_agent",type:"string",default:"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Safari/537.36 Chrome/142.0.0.0 OpenList/42",required:!0,help:"\u53D1\u9001\u7ED9\u84DD\u594F\u4E91 API \u4E0E\u76F4\u94FE\u89E3\u6790\u65F6\u643A\u5E26\u7684\u5BA2\u6237\u7AEF User-Agent"},{name:"repair_file_info",type:"bool",default:"false",required:!1,help:"\u901A\u8FC7 HEAD \u8BF7\u6C42\u4FEE\u6B63\u6587\u4EF6\u7CBE\u786E\u5927\u5C0F\u4E0E\u4FEE\u6539\u65F6\u95F4\uFF08WebDAV \u63A8\u8350\u5F00\u542F\uFF09"},{name:"order_by",type:"select",options:"name,size,time",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"Lanzou",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"-1"}},WebDav:{name:"WebDav",default_mount_path:"/webdav",common:[...Tt,Pt,Ft,Nt,...Rt("WebDav"),Vc,Ut,Zt],additional:[{name:"vendor",type:"select",options:"other,sharepoint",default:"other",required:!0},{name:"address",type:"string",default:"",required:!0},{name:"username",type:"string",default:"",required:!0},{name:"password",type:"string",default:"",required:!0},{name:"root_folder_path",type:"string",default:"/",required:!1},{name:"tls_insecure_skip_verify",type:"bool",default:"false",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"WebDav",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},WoPan:{name:"WoPan",default_mount_path:"/wopan",common:ft,additional:[{name:"root_folder_id",type:"string",default:"0",required:!1},{name:"refresh_token",type:"text",default:"",required:!0},{name:"family_id",type:"string",default:"",required:!1,help:"true"},{name:"sort_rule",type:"select",options:"name_asc,name_desc,time_asc,time_desc,size_asc,size_desc",default:"name_asc",required:!1},{name:"access_token",type:"string",default:"",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"WoPan",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"0",no_overwrite_upload:!0}},S3:{name:"S3",default_mount_path:"/s3",common:ft,additional:[{name:"root_folder_path",type:"string",default:"/",required:!1},{name:"bucket",type:"string",default:"",required:!0},{name:"endpoint",type:"string",default:"",required:!0},{name:"region",type:"string",default:"",required:!1},{name:"access_key_id",type:"string",default:"",required:!0},{name:"secret_access_key",type:"string",default:"",required:!0},{name:"session_token",type:"string",default:"",required:!1},{name:"custom_host",type:"string",default:"",required:!1},{name:"enable_custom_host_presign",type:"bool",default:"false",required:!1},{name:"sign_url_expire",type:"number",default:"4",required:!1},{name:"placeholder",type:"string",default:"",required:!1},{name:"force_path_style",type:"bool",default:"false",required:!1},{name:"list_object_version",type:"select",options:"v1,v2",default:"v1",required:!1},{name:"remove_bucket",type:"bool",default:"false",required:!1,help:"true"},{name:"add_filename_to_disposition",type:"bool",default:"false",required:!1,help:"true"},{name:"enable_direct_upload",type:"bool",default:"false",required:!1},{name:"direct_upload_host",type:"string",default:"",required:!1},{name:"user_agent",type:"string",default:"",required:!1,help:"true"},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"S3",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/",check_status:!0}},Doge:{name:"Doge",default_mount_path:"/doge",common:ft,additional:[{name:"root_folder_path",type:"string",default:"/",required:!1},{name:"bucket",type:"string",default:"",required:!0},{name:"endpoint",type:"string",default:"",required:!0},{name:"region",type:"string",default:"",required:!1},{name:"access_key_id",type:"string",default:"",required:!0},{name:"secret_access_key",type:"string",default:"",required:!0},{name:"session_token",type:"string",default:"",required:!1},{name:"custom_host",type:"string",default:"",required:!1},{name:"enable_custom_host_presign",type:"bool",default:"false",required:!1},{name:"sign_url_expire",type:"number",default:"4",required:!1},{name:"placeholder",type:"string",default:"",required:!1},{name:"force_path_style",type:"bool",default:"false",required:!1},{name:"list_object_version",type:"select",options:"v1,v2",default:"v1",required:!1},{name:"remove_bucket",type:"bool",default:"false",required:!1,help:"true"},{name:"add_filename_to_disposition",type:"bool",default:"false",required:!1,help:"true"},{name:"enable_direct_upload",type:"bool",default:"false",required:!1},{name:"direct_upload_host",type:"string",default:"",required:!1},{name:"user_agent",type:"string",default:"",required:!1,help:"true"},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"Doge",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/",check_status:!0}},WeiYun:{name:"WeiYun",default_mount_path:"/weiyun",common:[...Tt,Pt,Ft,Nt,...Rt("WeiYun"),Ut,Zt],additional:[{name:"root_folder_id",type:"string",default:"",required:!1},{name:"cookies",type:"text",default:"",required:!0},{name:"order_by",type:"select",options:"name,size,updated_at",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1},{name:"upload_thread",type:"string",default:"4",required:!1,help:"4<=thread<=32"}],config:{name:"WeiYun",local_sort:!1,only_local:!1,only_proxy:!0,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"",check_status:!0}},SFTP:{name:"SFTP",default_mount_path:"/sftp",common:[...Tt,Pt,Ft,Nt,...Rt("SFTP"),Ut,Zt],additional:[{name:"address",type:"string",default:"",required:!0,help:"SSH host:port (e.g. 127.0.0.1:22)"},{name:"username",type:"string",default:"",required:!0},{name:"password",type:"string",default:"",required:!1},{name:"private_key",type:"text",default:"",required:!1},{name:"passphrase",type:"string",default:"",required:!1},{name:"root_folder_path",type:"string",default:"/",required:!1},{name:"ignore_symlink_error",type:"bool",default:"false",required:!1,help:"Ignore symlink error"}],config:{name:"SFTP",local_sort:!0,only_local:!1,only_proxy:!0,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/",check_status:!0,no_link_url:!0}},FTP:{name:"FTP",default_mount_path:"/ftp",common:[...Tt,Pt,Ft,Nt,...Rt("FTP"),Ut,Zt],additional:[{name:"address",type:"string",default:"",required:!0,help:"FTP host:port (e.g. 127.0.0.1:21)"},{name:"username",type:"string",default:"",required:!0},{name:"password",type:"string",default:"",required:!0},{name:"encoding",type:"string",default:"utf-8",required:!0,help:"Character encoding, e.g. utf-8, gbk, gb2312"},{name:"cwd_list",type:"bool",default:"false",required:!1,help:"Enter directory before listing"},{name:"root_folder_path",type:"string",default:"/",required:!1}],config:{name:"FTP",local_sort:!0,only_local:!1,only_proxy:!0,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/",check_status:!0,no_link_url:!0}},PikPak:{name:"PikPak",default_mount_path:"/pikpak",common:ft,additional:[{name:"root_folder_id",type:"string",default:"",required:!1},{name:"username",type:"string",default:"",required:!0},{name:"password",type:"string",default:"",required:!0},{name:"platform",type:"select",options:"web,android,pc",default:"web",required:!0},{name:"refresh_token",type:"text",default:"",required:!1},{name:"captcha_token",type:"text",default:"",required:!1},{name:"device_id",type:"string",default:"",required:!1},{name:"disable_media_link",type:"bool",default:"true",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"PikPak",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:""}},Seafile:{name:"Seafile",default_mount_path:"/seafile",common:ft,additional:[{name:"address",type:"string",default:"",required:!0},{name:"username",type:"string",default:"",required:!1},{name:"password",type:"string",default:"",required:!1},{name:"token",type:"string",default:"",required:!1},{name:"repo_id",type:"string",default:"",required:!1},{name:"repo_pwd",type:"string",default:"",required:!1},{name:"root_folder_path",type:"string",default:"/",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"Seafile",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},YandexDisk:{name:"YandexDisk",default_mount_path:"/yandex",common:ft,additional:[{name:"refresh_token",type:"text",default:"",required:!0},{name:"root_folder_path",type:"string",default:"/",required:!1},{name:"use_online_api",type:"bool",default:"true",required:!1},{name:"api_url_address",type:"string",default:"https://api.oplist.org/yandexui/renewapi",required:!1},{name:"client_id",type:"string",default:"",required:!1},{name:"client_secret",type:"string",default:"",required:!1},{name:"order_by",type:"select",options:"name,path,created,modified,size",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"YandexDisk",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},Terabox:{name:"Terabox",default_mount_path:"/terabox",common:[...Tt,Pt,Ft,Nt,...Rt("Terabox"),Ut,Zt],additional:[{name:"cookie",type:"text",default:"",required:!0},{name:"download_api",type:"select",options:"official,crack",default:"official",required:!1},{name:"root_folder_path",type:"string",default:"/",required:!1},{name:"order_by",type:"select",options:"name,time,size",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"Terabox",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},MediaTrack:{name:"MediaTrack",default_mount_path:"/mediatrack",common:ft,additional:[{name:"access_token",type:"text",default:"",required:!0},{name:"project_id",type:"string",default:"",required:!1},{name:"root_folder_id",type:"string",default:"",required:!1},{name:"order_by",type:"select",options:"updated_at,title,size",default:"title",required:!1},{name:"order_desc",type:"bool",default:"false",required:!1}],config:{name:"MediaTrack",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:""}},Alias:{name:"Alias",default_mount_path:"/alias",common:[...Tt,Pt,Ft,Nt,...Rt("Alias"),Vc,Ut,Zt],additional:[{name:"paths",type:"text",default:"",required:!0,help:"Newline-separated list of paths, e.g. /local or sub:/target"},{name:"read_conflict_policy",type:"select",options:"first,random,all",default:"first",required:!1},{name:"write_conflict_policy",type:"select",options:"disabled,first,deterministic,deterministic_or_all,all,all_strict",default:"disabled",required:!1},{name:"put_conflict_policy",type:"select",options:"disabled,first,deterministic,deterministic_or_all,all,all_strict,random,quota,quota_strict",default:"disabled",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"Alias",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!0,no_upload:!1,need_ms:!1,default_root:"/"}},Dropbox:{name:"Dropbox",default_mount_path:"/dropbox",common:ft,additional:[{name:"root_folder_path",type:"string",default:"/",required:!1},{name:"use_online_api",type:"bool",default:"false",required:!1},{name:"api_url_address",type:"string",default:"https://api.oplist.org/dropboxs/renewapi",required:!1},{name:"client_id",type:"string",default:"",required:!1},{name:"client_secret",type:"string",default:"",required:!1},{name:"refresh_token",type:"text",default:"",required:!0},{name:"root_namespace_id",type:"string",default:"",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"Dropbox",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},WPS:{name:"WPS",default_mount_path:"/wps",common:ft,additional:[{name:"root_folder_path",type:"string",default:"/",required:!1},{name:"cookie",type:"text",default:"",required:!0},{name:"mode",type:"select",options:"Personal,Business",default:"Personal",required:!1},{name:"custom_ua",type:"string",default:"",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"WPS",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},"139Yun":{name:"139Yun",default_mount_path:"/139",common:[...Tt,Pt,Ft,Nt,...Rt("139Yun"),Vc,Ut,Zt],additional:[{name:"authorization",type:"text",default:"",required:!0},{name:"root_folder_id",type:"string",default:"",required:!1},{name:"type",type:"select",options:"personal_new,family,group,personal,share",default:"personal_new",required:!1},{name:"link_id",type:"text",default:"",required:!1},{name:"cloud_id",type:"string",default:"",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"139Yun",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:""}},Mega_nz:{name:"Mega_nz",default_mount_path:"/mega",common:[...Tt,Pt,Ft,Nt,...Rt("Mega_nz"),Ut,Zt],additional:[{name:"email",type:"string",default:"",required:!0},{name:"password",type:"string",default:"",required:!0},{name:"two_fa_code",type:"string",default:"",required:!1},{name:"two_fa_secret",type:"string",default:"",required:!1},{name:"move_to_trash",type:"bool",default:"true",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"Mega_nz",local_sort:!0,only_local:!1,only_proxy:!0,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},"115Share":{name:"115Share",default_mount_path:"/115_share",common:ft,additional:[{name:"share_code",type:"text",default:"",required:!0},{name:"receive_code",type:"text",default:"",required:!0},{name:"cookie",type:"text",default:"",required:!1},{name:"root_folder_id",type:"string",default:"0",required:!1},{name:"page_size",type:"number",default:"1000",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"115Share",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!0,need_ms:!1,default_root:"0"}},"123PanShare":{name:"123PanShare",default_mount_path:"/123_share",common:[...Tt,Pt,Ft,Nt,...Rt("123PanShare"),Ut,Zt],additional:[{name:"sharekey",type:"string",default:"",required:!0},{name:"sharepassword",type:"string",default:"",required:!1},{name:"accesstoken",type:"text",default:"",required:!1},{name:"root_folder_id",type:"string",default:"0",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"123PanShare",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!0,need_ms:!1,default_root:"0"}},AliyundriveShare:{name:"AliyundriveShare",default_mount_path:"/aliyun_share",common:ft,additional:[{name:"share_id",type:"string",default:"",required:!0},{name:"share_pwd",type:"string",default:"",required:!1},{name:"root_folder_id",type:"string",default:"root",required:!1},{name:"order_by",type:"select",options:"name,size,updated_at,created_at",default:"name",required:!1},{name:"order_direction",type:"select",options:"ASC,DESC",default:"ASC",required:!1}],config:{name:"AliyundriveShare",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!0,need_ms:!1,default_root:"root"}},OnedriveSharelink:{name:"OnedriveSharelink",default_mount_path:"/onedrive_share",common:ft,additional:[{name:"url",type:"string",default:"",required:!0},{name:"password",type:"string",default:"",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"OnedriveSharelink",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!0,need_ms:!1,default_root:"/"}},PikPakShare:{name:"PikPakShare",default_mount_path:"/pikpak_share",common:ft,additional:[{name:"share_id",type:"string",default:"",required:!0},{name:"share_pwd",type:"string",default:"",required:!1},{name:"platform",type:"select",options:"android,web,pc",default:"web",required:!1},{name:"root_folder_id",type:"string",default:"",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"PikPakShare",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!0,need_ms:!1,default_root:""}},SMB:{name:"SMB",default_mount_path:"/smb",common:[...Tt,Pt,Ft,Nt,...Rt("SMB"),Ut,Zt],additional:[{name:"address",type:"string",default:"",required:!0},{name:"share_name",type:"string",default:"",required:!0},{name:"username",type:"string",default:"",required:!0},{name:"password",type:"string",default:"",required:!1},{name:"port",type:"number",default:"445",required:!1},{name:"root_folder_path",type:"string",default:"/",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"SMB",local_sort:!0,only_local:!1,only_proxy:!0,no_cache:!0,no_upload:!1,need_ms:!1,default_root:"/"}},Crypt:{name:"Crypt",default_mount_path:"/crypt",common:[...Tt,Pt,Ft,Nt,...Rt("Crypt"),Ut,Zt],additional:[{name:"remote_path",type:"string",default:"",required:!0,help:"\u52A0\u5BC6\u6570\u636E\u5B9E\u9645\u5B58\u50A8\u7684\u4F4D\u7F6E\uFF08\u53E6\u4E00\u4E2A\u5DF2\u6302\u8F7D\u5B58\u50A8\u7684\u8DEF\u5F84\uFF0C\u5982 /aliyundrive/enc\uFF09"},{name:"password",type:"string",default:"",required:!0,help:"\u4E3B\u5BC6\u7801\uFF08\u7528\u4E8E\u6D3E\u751F\u52A0\u5BC6\u5BC6\u94A5\uFF09"},{name:"salt",type:"string",default:"",required:!1,help:"\u76D0\uFF08\u7B2C\u4E8C\u5BC6\u7801\uFF09\u3002\u53EF\u9009\u4F46\u63A8\u8350\uFF0C\u63D0\u9AD8\u5BC6\u94A5\u5F3A\u5EA6"},{name:"filename_encryption",type:"select",options:"off,standard,obfuscate",default:"off",required:!0,help:"\u6587\u4EF6\u540D\u52A0\u5BC6\u65B9\u5F0F\u3002\u5F53\u524D\u4EC5\u652F\u6301 off\uFF08\u6587\u4EF6\u540D\u4E0D\u52A0\u5BC6\uFF0C\u4EC5\u5185\u5BB9\u52A0\u5BC6\uFF09"},{name:"directory_name_encryption",type:"select",options:"false,true",default:"false",required:!0},{name:"encrypted_suffix",type:"string",default:".bin",required:!0,help:"\u52A0\u5BC6\u6587\u4EF6\u7684\u540E\u7F00\uFF08\u9AD8\u7EA7\u9009\u9879\uFF09"},{name:"filename_encoding",type:"select",options:"base64,base32,base32768",default:"base64",required:!0},{name:"thumbnail",type:"bool",default:"false",required:!1},{name:"show_hidden",type:"bool",default:"true",required:!1}],config:{name:"Crypt",local_sort:!0,only_local:!1,only_proxy:!0,no_cache:!0,no_upload:!1,need_ms:!1,default_root:"/",no_link_url:!0,check_status:!0}},Virtual:{name:"Virtual",default_mount_path:"/virtual",common:[...Tt,Pt,Ft,Nt,...Rt("Virtual"),Ut,Zt],additional:[{name:"num_file",type:"number",default:"30",required:!0,help:"\u6BCF\u4E2A\u76EE\u5F55\u4E0B\u751F\u6210\u7684\u5360\u4F4D\u6587\u4EF6\u6570\u91CF"},{name:"num_folder",type:"number",default:"30",required:!0,help:"\u6BCF\u4E2A\u76EE\u5F55\u4E0B\u751F\u6210\u7684\u5360\u4F4D\u76EE\u5F55\u6570\u91CF"},{name:"max_file_size",type:"number",default:"1073741824",required:!0,help:"\u5360\u4F4D\u6587\u4EF6\u6700\u5927\u5B57\u8282\u6570"},{name:"min_file_size",type:"number",default:"1048576",required:!0,help:"\u5360\u4F4D\u6587\u4EF6\u6700\u5C0F\u5B57\u8282\u6570"}],config:{name:"Virtual",local_sort:!0,only_local:!1,only_proxy:!0,no_cache:!1,no_upload:!1,need_ms:!0,default_root:"/",no_link_url:!0}},AListV3:{name:"AListV3",default_mount_path:"/alist",common:[...Tt,Pt,Ft,Nt,...Rt("AListV3"),Vc,Ut,Zt],additional:[{name:"url",type:"string",default:"",required:!0,help:"\u53E6\u4E00\u4E2A OpenList / AList \u5B9E\u4F8B\u7684\u5730\u5740\uFF0C\u5982 https://example.com"},{name:"meta_password",type:"string",default:"",required:!1},{name:"username",type:"string",default:"",required:!1},{name:"password",type:"string",default:"",required:!1},{name:"token",type:"string",default:"",required:!1,help:"\u8BBF\u95EE\u4EE4\u724C\uFF08\u53EF\u9009\uFF0C\u81EA\u52A8\u6301\u4E45\u5316\uFF0C\u65E0\u9700\u624B\u52A8\u586B\u5199\uFF09"},{name:"pass_ip_to_upsteam",type:"bool",default:"true",required:!1},{name:"pass_ua_to_upsteam",type:"bool",default:"true",required:!1},{name:"forward_archive_requests",type:"bool",default:"true",required:!1}],config:{name:"AListV3",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},UrlTree:{name:"UrlTree",default_mount_path:"/url_tree",common:ft,additional:[{name:"url_structure",type:"text",default:"",required:!0,help:"URL \u6811\u7ED3\u6784\u6587\u672C\uFF0C\u6BCF\u884C\u7F29\u8FDB 2 \u7A7A\u683C\u8868\u793A\u4E00\u7EA7\u3002\u76EE\u5F55\u884C\u4EE5 : \u7ED3\u5C3E\uFF0C\u6587\u4EF6\u884C\u683C\u5F0F [FileName:][FileSize:][Modified:]Url"},{name:"head_size",type:"bool",default:"false",required:!1,help:"\u7528 HEAD \u8BF7\u6C42\u83B7\u53D6\u6587\u4EF6\u5927\u5C0F\uFF08\u53EF\u80FD\u5931\u8D25\uFF09"},{name:"writable",type:"bool",default:"false",required:!1,help:"\u5141\u8BB8\u589E\u5220\u6539\u6587\u4EF6\u6811\uFF08\u4F1A\u6301\u4E45\u5316\u56DE url_structure\uFF09"}],config:{name:"UrlTree",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!0,no_upload:!1,need_ms:!1,default_root:"/",check_status:!0}},Strm:{name:"Strm",default_mount_path:"/strm",common:[...Tt,Pt,Ft,Nt,...Rt("Strm"),Ut,Zt],additional:[{name:"paths",type:"text",default:"",required:!0,help:"\u8DEF\u5F84\u6620\u5C04\uFF0C\u6BCF\u884C\u4E00\u4E2A\uFF1A\u865A\u62DF\u540D:\u5E95\u5C42\u8DEF\u5F84\uFF08\u5982 movies:/aliyundrive/movies\uFF09\uFF0C\u6216\u76F4\u63A5\u5E95\u5C42\u8DEF\u5F84"},{name:"siteUrl",type:"text",default:"",required:!1,help:"strm \u6587\u4EF6\u5185\u5BB9\u7684 URL \u524D\u7F00\uFF08\u7559\u7A7A\u5219\u7528\u76F8\u5BF9\u8DEF\u5F84\uFF09"},{name:"PathPrefix",type:"text",default:"/d",required:!1,help:"\u4E0B\u8F7D\u8DEF\u5F84\u524D\u7F00"},{name:"downloadFileTypes",type:"text",default:"ass,srt,vtt,sub,strm",required:!1,help:"\u9700\u539F\u6837\u4E0B\u8F7D\u7684\u6587\u4EF6\u6269\u5C55\u540D\uFF08\u901A\u5E38\u4E3A\u5B57\u5E55\uFF09"},{name:"filterFileTypes",type:"text",default:"mp4,mkv,flv,avi,wmv,ts,rmvb,webm,mp3,flac,aac,wav,ogg,m4a,wma,alac",required:!1,help:"\u652F\u6301\u751F\u6210 strm \u7684\u6587\u4EF6\u6269\u5C55\u540D\uFF08\u89C6\u9891/\u97F3\u9891\uFF09"},{name:"encodePath",type:"bool",default:"true",required:!1},{name:"withoutUrl",type:"bool",default:"false",required:!1},{name:"withSign",type:"bool",default:"false",required:!1}],config:{name:"Strm",local_sort:!0,only_local:!1,only_proxy:!0,no_cache:!0,no_upload:!0,need_ms:!1,default_root:"/",no_link_url:!0}},AzureBlob:{name:"AzureBlob",default_mount_path:"/azure",common:ft,additional:[{name:"endpoint",type:"string",default:"",required:!0,help:"Azure \u5B58\u50A8\u7AEF\u70B9\uFF0C\u5982 https://accountname.blob.core.windows.net/"},{name:"access_key",type:"string",default:"",required:!0,help:"Azure \u5B58\u50A8\u8BBF\u95EE\u5BC6\u94A5\uFF08Base64\uFF09"},{name:"container_name",type:"string",default:"",required:!0,help:"\u5BB9\u5668\u540D\u79F0"},{name:"sign_url_expire",type:"number",default:"4",required:!1,help:"SAS URL \u6709\u6548\u671F\uFF08\u5C0F\u65F6\uFF09"}],config:{name:"AzureBlob",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/",check_status:!0}},USS:{name:"USS",default_mount_path:"/uss",common:ft,additional:[{name:"bucket",type:"string",default:"",required:!0},{name:"endpoint",type:"string",default:"",required:!0,help:"\u4E0B\u8F7D\u57DF\u540D\uFF08\u53EF\u542B\u534F\u8BAE\u5934\uFF09"},{name:"operator_name",type:"string",default:"",required:!0},{name:"operator_password",type:"string",default:"",required:!0},{name:"anti_theft_chain_token",type:"string",default:"",required:!1,help:"\u9632\u76D7\u94FE Token\uFF08\u7559\u7A7A\u5219\u7528\u64CD\u4F5C\u5458\u5BC6\u7801\uFF09"},{name:"sign_url_expire",type:"number",default:"4",required:!1,help:"\u94FE\u63A5\u6709\u6548\u671F\uFF08\u5C0F\u65F6\uFF09"}],config:{name:"USS",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},Alidoc:{name:"Alidoc",default_mount_path:"/alidoc",common:ft,additional:[{name:"cookie",type:"text",default:"",required:!0,help:"\u9489\u9489\u6587\u6863\u7F51\u9875 Cookie"},{name:"root_folder_id",type:"string",default:"",required:!0,help:"\u6839\u76EE\u5F55 dentryUuid"}],config:{name:"Alidoc",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!0,need_ms:!1,default_root:""}},Emby:{name:"Emby",default_mount_path:"/emby",common:ft,additional:[{name:"url",type:"string",default:"",required:!0,help:"Emby \u670D\u52A1\u5668\u5730\u5740\uFF0C\u5982 http://localhost:8096"},{name:"api_key",type:"string",default:"",required:!1},{name:"user_id",type:"string",default:"",required:!1},{name:"username",type:"string",default:"",required:!1},{name:"password",type:"string",default:"",required:!1},{name:"link_method",type:"select",options:"stream,download",default:"stream",required:!1},{name:"root_folder_id",type:"string",default:"1",required:!1,help:"\u6839\u76EE\u5F55 ID\uFF0C\u9ED8\u8BA4 1"}],config:{name:"Emby",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!0,need_ms:!1,default_root:"1"}},BunnyStorage:{name:"BunnyStorage",default_mount_path:"/bunny",common:ft,additional:[{name:"storage_zone_name",type:"string",default:"",required:!0},{name:"access_key",type:"string",default:"",required:!0},{name:"endpoint",type:"string",default:"storage.bunnycdn.com",required:!1},{name:"cdn_base_url",type:"string",default:"",required:!1},{name:"cdn_token_key",type:"string",default:"",required:!1},{name:"cdn_token_method",type:"select",options:"sha256,hmac_sha256",default:"sha256",required:!1},{name:"cdn_token_include_ip",type:"bool",default:"false",required:!1},{name:"sign_url_expire",type:"number",default:"4",required:!1,help:"\u94FE\u63A5\u6709\u6548\u671F\uFF08\u5C0F\u65F6\uFF09"},{name:"placeholder",type:"string",default:".openlist",required:!1},{name:"root_folder_path",type:"string",default:"/",required:!0}],config:{name:"BunnyStorage",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},CloudflareImgbed:{name:"CloudflareImgbed",default_mount_path:"/cfimgbed",common:ft,additional:[{name:"address",type:"string",default:"",required:!0,help:"\u56FE\u5E8A\u670D\u52A1\u5730\u5740"},{name:"token",type:"string",default:"",required:!0},{name:"small_channel_name",type:"string",default:"",required:!1},{name:"large_channel_name",type:"string",default:"",required:!1},{name:"large_channel_type",type:"string",default:"",required:!1},{name:"upload_thread",type:"number",default:"3",required:!1},{name:"root_folder_path",type:"string",default:"/",required:!0}],config:{name:"CloudflareImgbed",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},GuangYaPan:{name:"GuangYaPan",default_mount_path:"/guangyapan",common:ft,additional:[{name:"client_id",type:"string",default:"",required:!0},{name:"device_id",type:"string",default:"",required:!1},{name:"device_sign",type:"string",default:"",required:!1},{name:"access_token",type:"text",default:"",required:!1},{name:"refresh_token",type:"text",default:"",required:!1},{name:"phone_number",type:"string",default:"",required:!1,help:"\u624B\u673A\u53F7\uFF08\u767B\u5F55\u7528\uFF0C+86 \u683C\u5F0F\uFF09"},{name:"verify_code",type:"string",default:"",required:!1},{name:"page_size",type:"number",default:"100",required:!1},{name:"order_by",type:"number",default:"3",required:!1},{name:"sort_type",type:"number",default:"1",required:!1},{name:"root_folder_path",type:"string",default:"/",required:!0}],config:{name:"GuangYaPan",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},AutoIndex:{name:"AutoIndex",default_mount_path:"/autoindex",common:ft,additional:[{name:"url",type:"string",default:"",required:!0,help:"AutoIndex \u76EE\u5F55\u9875 URL"},{name:"item_xpath",type:"string",default:"//pre/a",required:!0},{name:"name_xpath",type:"string",default:"@href",required:!0},{name:"modified_xpath",type:"string",default:"string(following-sibling::text()[2])",required:!1},{name:"size_xpath",type:"string",default:"string(following-sibling::text()[1])",required:!1},{name:"ignore_file_names",type:"text",default:`.
|
|
272
|
+
`).map(B=>B.trim()).filter(Boolean),m=["md5","sha1","sha256"],E=f.map(B=>{let k=m.filter(Q=>!!B.hashes[Q]),F=k.length<m.length;return{path:B.virtualPath,name:B.relativePath,size:B.size,available_hashes:k,requires_download:F,requires_fetch:F,estimated_traffic:F?B.size:0,streamable:!0,share_available:!0,direct_source_available:!0}}),b=new Set;for(let B of f)for(let k of m)B.hashes[k]&&b.add(k);let C=m.filter(B=>b.has(B));return t.json({code:200,message:"success",data:{formats:{oss:!0,torrent:!0,cas:!0},files:E,existing_hashes:C,estimated_traffic:E.reduce((B,k)=>B+k.estimated_traffic,0),default_matrix:await Vne(),trackers:y}})}let i=await Nh(t,e,r),n=Ve(e,aa(r.path)),s=await rt(n);if(s.isVirtual||!s.storage)throw new Error("Target storage was not found");let o=await et(s.storage.driver,s.storage),c=typeof o.rapidUpload=="function"||typeof o.putRapid=="function"||typeof o.createUploadSession=="function",u=Array.isArray(o.rapidHashAlgos)?o.rapidHashAlgos.map(f=>String(f).toLowerCase()).filter(f=>["md5","sha1","sha256"].includes(f)):["md5","sha1"],l=typeof o.rapidHashNeedsPieces=="boolean"?o.rapidHashNeedsPieces:!1,d=typeof o.putStream=="function"||typeof o.createUploadSession=="function"&&typeof o.uploadPart=="function"&&typeof o.completeUploadSession=="function",A=sn(t,"SEED_BUFFERED_TRANSFER_MAX",rO),g=i.seed.files.map(f=>{let p=u.some(b=>!!f.hashes[b])||!1,y=l?p&&(f.hashes.pieces.md5.length>0||f.hashes.pieces.sha1.length>0):p,m=!!Mb(t,f),E="download_required";return c&&y?E="rapid_upload":m&&d?E="stream_upload":m&&f.size<=A&&(E="bounded_upload"),{path:f.path,method:E,requires_download:E==="download_required"}});return t.json({code:200,message:"success",data:{driver:s.storage.driver,policy:String(r.policy||"inherit"),driver_supports:{cas_rapid:c,rapid_hash_algos:u,rapid_uses_pieces:l},files:g}})}catch(r){return Qr(t,400,Pe(r))}});ds.post("/generate",async t=>{let e=await Ne(t);if(!e||e.disabled)return Qr(t,401,"Unauthorized");try{let r=await Fl(t);if((r.save_path||r.output_path)&&!ut(e))return Qr(t,403,"Permission denied");let n=(Array.isArray(r.formats)?r.formats:[r.format||"oss"]).map(b1);if(n.some(l=>!l))throw new Error("A valid output format is required");let s=n,{seed:a,torrentPieces:o}=await Wne(t,e,r,s),c=r.output_path||(Array.isArray(r.formats)?r.save_path:void 0),u=[];for(let l of s){let d=Pl(a,l);if(d.length){u.push({format:l,convertible:!1,diagnostics:d});continue}let A=l==="torrent"?await kb(a,o):await Th(a,l),g=c?Nb(aa(c),nO(a,l)):r.save_path;await Ob(t,e,g,A),u.push(Rb(a,l,A,{convertible:!0,...g?{path:g}:{}}))}return t.json({code:200,message:"success",data:Array.isArray(r.formats)?{seed:a,outputs:u,artifacts:u}:u[0]})}catch(r){let i=Pe(r);return Qr(t,i.includes("limit")||i.includes("exceeds")?413:400,i)}});ds.post("/parse",async t=>{let e=await Ne(t);if(!e||e.disabled)return Qr(t,401,"Unauthorized");try{let r=await Fl(t),i=await Nh(t,e,r),n=i.seed.files.reduce((o,c)=>o+c.size,0),s=i.seed.files.some(o=>!!Mb(t,o)),a=i.seed.files.some(o=>!!o.hashes.md5||!!o.hashes.sha1||!!o.hashes.sha256);return t.json({code:200,message:"success",data:{format:i.format,seed:i.seed,files:i.seed.files,total_size:n,diagnostics:Jne(i.seed),conversions:jne(i.seed),capabilities:{rapid_upload:a,offline_download:s,transfer:s,convert:!0,edit:!0,recalculate:!0},direct_preview:!1,...i.info_hash?{info_hash:i.info_hash}:{}}})}catch(r){return Qr(t,400,Pe(r))}});ds.post("/convert",async t=>{let e=await Ne(t);if(!e||e.disabled)return Qr(t,401,"Unauthorized");try{let r=await Fl(t);if(r.save_path&&!ut(e))return Qr(t,403,"Permission denied");let i=b1(r.to_format||r.target_format||r.output_format);if(!i)throw new Error("A valid target format is required");let n=await Nh(t,e,r),s=Pl(n.seed,i);if(s.length)return t.json({code:200,message:"success",data:{convertible:!1,diagnostics:s}});let a=await Th(n.seed,i);return await Ob(t,e,r.save_path,a),t.json({code:200,message:"success",data:Rb(n.seed,i,a,{convertible:!0})})}catch(r){return Qr(t,400,Pe(r))}});function Zne(t,e,r,i){if(!e)return;let n=!1;for(let s of i.values())if(s){n=!0;break}n&&!t.channels.some(s=>s.driver===e)&&t.channels.push({driver:e,mount_path:r});for(let s of t.files){if(!i.has(s.path))continue;i.get(s.path)?s.missing_channels=s.missing_channels.filter(o=>o!==e):s.missing_channels.includes(e)||s.missing_channels.push(e)}}async function oO(t,e){let r=await Ne(t);if(!ut(r))return Qr(t,403,"Permission denied");if(!e&&!bo(r,Bo.OFFLINE_DOWNLOAD))return Qr(t,403,"Offline download permission is required");try{let i=await Fl(t),n=await Nh(t,r,i),s=aa(i.target_path||i.destination||i.path||"/"),a=new Set(Array.isArray(i.files)?i.files.map(p=>String(p)):[]),o=new Set(Array.isArray(i.selected_files)?i.selected_files.map(p=>Number(p)):[]);if([...o].some(p=>!Number.isSafeInteger(p)||p<0||p>=n.seed.files.length))throw new Error("selected_files contains an invalid index");let c="",u="";try{let p=await rt(Ve(r,s));!p.isVirtual&&p.storage&&(c=p.storage.driver||"",u=p.storage.mount_path||"")}catch{}let l=n.seed.files.filter((p,y)=>a.size?a.has(p.path):o.size?o.has(y):!0),d=[],A=new Map,g=0;for(let p of l){let y=Nb(s,p.path),m=Mb(t,p);try{if(!e&&!m)throw new Error("capability unavailable: offline download requires an approved source URL");let E=await Xne(t,r,p,y,m,e);g++,A.set(p.path,!0),d.push({path:p.path,target:y,...E})}catch(E){A.set(p.path,!1),d.push({path:p.path,target:y,status:"unavailable",error:Pe(E)})}}if(g===0)return t.json({code:501,message:e?"capability unavailable: target driver cannot reuse hashes and no transferable source is available":"capability unavailable: no approved source and streaming upload combination is available",data:{results:d}},501);let f={total:d.length,saved:g,results:d};if(i.update_channel===!0&&c){Zne(n.seed,c,u,A);let p=await Th(n.seed,n.format);f.seed_data=Buffer.from(p).toString("base64"),f.seed=n.seed}return t.json({code:200,message:"success",data:f})}catch(i){return Qr(t,400,Pe(i))}}ds.post("/rapid_upload",t=>oO(t,!0));ds.post("/offline_download",t=>oO(t,!1));ds.post("/update",async t=>{let e=await Ne(t);if(!e||e.disabled)return Qr(t,401,"Unauthorized");try{let r=await Fl(t);if(r.save_path&&!ut(e))return Qr(t,403,"Permission denied");let i=await Nh(t,e,r),n=r.patch&&typeof r.patch=="object"?r.patch:r,s=r.options&&typeof r.options=="object"?r.options:{},a=n.comment??s.comment,o=!!(n.recalculate??s.recalculate),c=Oi({...i.seed,name:n.name??i.seed.name,comment:a??i.seed.comment,trackers:n.trackers??i.seed.trackers,channels:n.channels??i.seed.channels,files:n.files??i.seed.files}),u=r.file_comments&&typeof r.file_comments=="object"?r.file_comments:{},l=r.file_sources&&typeof r.file_sources=="object"?r.file_sources:{};for(let g of c.files)if(u[g.path]!==void 0&&(g.comment=String(u[g.path])),Array.isArray(l[g.path])){for(let f of l[g.path])Pb(t,f);g.sources=l[g.path]}if(o){let g=Number(r.piece_size||i.seed.piece_size||10485760);if(!Number.isSafeInteger(g)||g<16*1024||g>64*1024*1024)throw new Error("Invalid piece_size");c.piece_size=g;let f=E1(r.hash_matrix,[i.format]),p=Array.isArray(r.recalc_files)?r.recalc_files:[];if(!p.length)throw new Error("recalculate requires at least one recalc_files entry");let y=new Map;for(let b of p)typeof b?.source_path=="string"&&b.source_path.trim()&&y.set(String(b.path),b.source_path);let m=await Ph.create(g),E=sn(t,"SEED_MAX_HASH_BYTES",Fb);for(let b of c.files){let C=y.get(b.path);if(!C)continue;let B=await Ub(t,e,[C]);if(B.length!==1)throw new Error(`Recalculate path must resolve to exactly one file: ${C}`);let k=B[0],F=await D1(t,new URL(k.rawUrl,t.req.url),{headers:k.headers});if(!F.ok||!F.body)throw new Error(`Recalculate download failed with HTTP ${F.status}`);let Q=await Qb(F.body,g,k.size,E,m);b.hashes=Db({...b,hashes:Q.hashes},f).hashes,b.size=Q.size,b.cas_slice_md5="",b.cas_create_time=""}}for(let g of c.files)for(let f of g.sources)Pb(t,f);let d=b1(r.output_format||r.to_format)||i.format,A=await Th(c,d);return await Ob(t,e,r.save_path,A),t.json({code:200,message:"success",data:Rb(c,d,A)})}catch(r){return Qr(t,400,Pe(r))}});var S1=new Map,ese=1*1024*1024,tse=64*1024*1024,rse=10*1024*1024;function cO(t){return!Number.isFinite(t)||t<=0?rse:Math.min(tse,Math.max(ese,Math.floor(t)))}function ise(t){let e=Array.from(t).sort((s,a)=>s-a);if(e.length===0)return[];let r=[],i=e[0],n=e[0];for(let s=1;s<e.length;s++)e[s]===n+1?n=e[s]:(r.push([i,n]),i=n=e[s]);return r.push([i,n]),r}function oa(t){let e=ise(t.received),r=t.received.size*t.chunk_size,i=0;for(let s=0;s<t.total_chunks&&t.received.has(s);s++)i=s+1;let n=t.total_chunks>0?Math.floor(t.received.size/t.total_chunks*100):0;return{upload_id:t.upload_id,state:t.state,attempt:t.attempt,path:t.path,size:t.size,chunk_size:t.chunk_size,total_chunks:t.total_chunks,received:e,received_bytes:r,frontier:i,storage_progress:n,error:t.error}}function uO(t){return S1.get(t)}function lO(t,e){for(let r of S1.values())if(r.path===t&&r.size===e&&(r.state==="receiving"||r.state==="failed_retriable"))return r}function Nl(t){S1.set(t.upload_id,t)}function dO(t){S1.delete(t)}async function nse(t){try{let e=await rt(t);return e?.storage?gx(e.storage):!1}catch{return!1}}var at=new je;at.route("/seed",ds);var kt=t=>{try{let e=t.executionCtx;return!e||typeof e.waitUntil!="function"?void 0:{waitUntil:r=>e.waitUntil(r),env:t.env}}catch{return}},Gt=t=>t.json({code:403,message:"Permission denied",data:null},403),sse=25*1024*1024,ase=16*1024*1024,AO=1*1024*1024*1024;function ose(t,e){let r=t.env||{},i=e?"MAX_UPPART":"MAX_UPLOAD",n=r[i]||(typeof process<"u"?process.env?.[i]:"");if(n){let s=parseInt(String(n),10);if(Number.isFinite(s)&&s>0)return s}return e?ase:sse}function v1(t,e=!1){let r=parseInt(t.req.header("Content-Length")||"0",10);if(!r)return null;let i=ose(t,e);return r>i?i:null}var Lb=(t,e)=>{let r=e==="wrong password",i=e||"share error";return t.json({code:r?403:400,message:i,data:null},r?403:400)};at.post("/dirs",async t=>{let e=await t.req.json().catch(()=>({})),r=await Ne(t),i=e.path||"/";if(!i.startsWith("/@s")&&(!r||r.disabled))return t.json({code:401,message:"Unauthorized",data:null},401);let s=kt(t),a=i;(!e.force_root||!ls(r))&&(a=Ve(r,a));try{if(a.startsWith("/@s")){let u=await Bl(a,e.password||"",t.env);if(!u.ok)return Lb(t,u.error);if(u.virtualList){let A=[];for(let g of u.share.files||[])try{let{item:f}=await Bi(g,s);if(f.is_dir){let p=String(g).split("/").filter(Boolean);A.push({name:p[p.length-1]||g,modified:f.modified||new Date().toISOString()})}}catch{}return t.json({code:200,message:"success",data:A})}let{content:l}=await Xt(u.realPath,s),d=l.filter(A=>A.is_dir).map(A=>({name:A.name,modified:A.modified||new Date().toISOString()}));return t.json({code:200,message:"success",data:d})}let{content:o}=await Xt(a,s),c=o.filter(u=>u.is_dir).map(u=>({name:u.name,modified:u.modified||new Date().toISOString()}));return t.json({code:200,message:"success",data:c})}catch(o){return t.json({code:500,message:Pe(o),data:null})}});at.post("/list",async t=>{let e=await t.req.json().catch(()=>({})),r=await Ne(t);if(!(e.path||"/").startsWith("/@s")&&(!r||r.disabled))return t.json({code:401,message:"Unauthorized",data:null},401);let n=kt(t),s=Ve(r,e.path||"/"),a=parseInt(e.page,10)||1,o=parseInt(e.per_page,10)||0,c=u=>{let l=u.length;if(o<=0)return{content:u,total:l};let A=(Math.max(1,a)-1)*o,g=A+o;return{content:u.slice(A,g),total:l}};try{if(s.startsWith("/@s")){let D=await Bl(s,e.password||"",t.env);if(!D.ok)return Lb(t,D.error);if(D.virtualList){let j=[];for(let z of D.share.files||[]){let K=String(z).split("/").filter(Boolean),J=K[K.length-1]||z;try{let{item:ee}=await Bi(z,n);j.push({name:J,size:ee.size||0,is_dir:!!ee.is_dir,modified:ee.modified||new Date().toISOString(),sign:"",thumb:ee.thumb||"",type:ee.type??0})}catch{try{await Xt(z,n),j.push({name:J,size:0,is_dir:!0,modified:new Date().toISOString(),sign:"",thumb:"",type:1})}catch{j.push({name:J,size:0,is_dir:!1,modified:new Date().toISOString(),sign:"",thumb:"",type:0})}}}let{content:Y,total:L}=c(j);return t.json({code:200,message:"success",data:{content:Y,total:L,readme:D.share.readme||"",header:D.share.header||"",write:!1,write_content_bypass:!1,provider:"Share"}})}let{content:v,provider:x}=await Xt(D.realPath,n),_=v.map(j=>({name:j.name,size:j.size,is_dir:j.is_dir,created:j.created||j.modified||new Date().toISOString(),modified:j.modified||new Date().toISOString(),sign:j.sign||"",thumb:j.thumb||"",type:j.type??0})),{content:U,total:R}=c(_);return t.json({code:200,message:"success",data:{content:U,total:R,readme:D.share.readme||"",header:D.share.header||"",write:!1,write_content_bypass:!1,provider:x}})}let u=await yb(s,t.env);if(!Ib(r,u,s,e.password||""))return t.json({code:403,message:"Access denied (wrong password or not in read_users)",data:null},403);if(await nse(s))return t.json({code:403,message:"Index is disabled for this storage",data:null},403);let{content:l,provider:d,storage:A}=await Xt(s,n),g=ut(r)&&wb(r,u,s),f=Eb(u,s),p=await m1(t),y=await y1(t,s),m=p.enabled||y,E=m?p.expiresIn||await xl(t):0,b=await Promise.all(l.filter(D=>!HU(u,s,D.name)).map(async D=>{let v=`${s}/${D.name}`.replace(/\/{2,}/g,"/"),x=!D.is_dir&&m?await kl(t,v,E):"",_=D.hashinfo||D.hash_info_str||"",U=D.hash_info||{};return{name:D.name,size:D.size,is_dir:D.is_dir,created:D.created||D.modified||new Date().toISOString(),modified:D.modified||new Date().toISOString(),sign:x,thumb:D.thumb||"",type:D.type??0,hashinfo:_,hash_info:U}})),C=0;if(A&&(C=parseInt(A.page_size,10)||0,!C&&A.addition))try{let D=typeof A.addition=="string"?JSON.parse(A.addition):A.addition;C=parseInt(D?.page_size,10)||0}catch{}let B=o>0?o:C>0?C:0,k=D=>{let v=D.length;if(B<=0)return{content:D,total:v};let _=(Math.max(1,a)-1)*B,U=_+B;return{content:D.slice(_,U),total:v}},F=(()=>{if(!A)return[];let D=[],v=A;if(/^(s3|minio|cos|oss|r2|b2|cloudflare_r2)/i.test(v.driver||"")&&D.push("s3_presigned"),Array.isArray(v.direct_upload_tools))for(let x of v.direct_upload_tools)D.includes(x)||D.push(x);return D})(),{content:Q,total:P}=k(b),T=A?fx(A,s):void 0;return t.json({code:200,message:"success",data:{content:Q,total:P,readme:Cb(u,s),header:Bb(u,s),write:g,write_content_bypass:f,provider:d,direct_upload_tools:F,page_size:B>0?B:void 0,cache_expiration:T}})}catch(u){return t.json({code:500,message:Pe(u),data:null})}});at.post("/get",async t=>{let e=await t.req.json().catch(()=>({})),r=await Ne(t);if(!(e.path||"/").startsWith("/@s")&&(!r||r.disabled))return t.json({code:401,message:"Unauthorized",data:null},401);let n=kt(t),s=Ve(r,e.path||"/");try{if(s.startsWith("/@s")){let m=await Bl(s,e.password||"",t.env);if(!m.ok)return Lb(t,m.error);if(m.virtualList){let k=s.split("/").filter(Boolean)[1]||"share";return t.json({code:200,message:"success",data:{name:k,size:0,is_dir:!0,modified:new Date().toISOString(),sign:"",thumb:"",type:1,raw_url:"",readme:m.share.readme||"",header:m.share.header||"",provider:"Share",related:[],write:!1,write_content_bypass:!1}})}let E=s.split("/").filter(Boolean)[1]||"",{item:b,provider:C}=await Bi(m.realPath,n),B=s.replace(/^\/@s\/[^/]+/,"");return t.json({code:200,message:"success",data:{name:b.name,size:b.size,is_dir:b.is_dir,created:b.created||b.modified||new Date().toISOString(),modified:b.modified,sign:b.sign||"",thumb:b.thumb||"",type:b.type??0,raw_url:`/api/sd/${E}${B}`,readme:m.share.readme||"",header:m.share.header||"",provider:C,related:[],write:!1,write_content_bypass:!1}})}let a=await yb(s,t.env);if(!Ib(r,a,s,e.password||""))return t.json({code:403,message:"Access denied (wrong password or not in read_users)",data:null},403);let{item:o,provider:c,rawUrl:u}=await Bi(s,n),l=await m1(t),d=l.enabled||await y1(t,s),A=!o.is_dir&&d?await kl(t,s,l.expiresIn||await xl(t)):"",g=A&&u&&!/[?&]sign=/.test(u)?`${u}${u.includes("?")?"&":"?"}sign=${A}`:u,f=ut(r)&&wb(r,a,s),p=Eb(a,s),y=[];if(!o.is_dir)try{let m=s.includes("/")&&s.slice(0,s.lastIndexOf("/"))||"/",E=o.name.includes(".")?o.name.slice(0,o.name.lastIndexOf(".")):o.name,{content:b}=await Xt(m,n);y=b.filter(C=>C.name===o.name||C.is_dir?!1:(C.name.includes(".")?C.name.slice(0,C.name.lastIndexOf(".")):C.name)===E).map(C=>({name:C.name,size:C.size,is_dir:!1,modified:C.modified||new Date().toISOString(),sign:"",thumb:C.thumb||"",type:C.type??0}))}catch{y=[]}return t.json({code:200,message:"success",data:{name:o.name,size:o.size,is_dir:o.is_dir,created:o.created||o.modified||new Date().toISOString(),modified:o.modified,sign:A,thumb:o.thumb||"",type:o.type??0,raw_url:g,readme:Cb(a,s),header:Bb(a,s),provider:c,related:y,write:f,write_content_bypass:p}})}catch(a){return t.json({code:500,message:Pe(a),data:null})}});function Rl(t){if(typeof t!="string"||!t.trim())throw new Error("Invalid or empty file name");let e=t.trim();if(e==="."||e===".."||e.includes("/")||e.includes("\\")||e.includes("\0"))throw new Error(`Illegal file name '${e}'`);return e}function ca(t){if(typeof t!="string")throw new Error("Path must be a string");if(t.includes("\0"))throw new Error("Path contains illegal null byte");return t}at.post("/mkdir",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let i=(await t.req.json().catch(()=>({}))).path||"/";try{ca(i)}catch(a){return t.json({code:400,message:a.message,data:null},400)}let n=Ve(e,i),s=kt(t);try{return await bh(n,s),t.json({code:200,message:"success",data:null})}catch(a){return t.json({code:500,message:Pe(a),data:null})}});at.post("/rename",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let{path:r,name:i}=await t.req.json().catch(()=>({})),n="";try{ca(r||"/"),n=Rl(i)}catch(a){return t.json({code:400,message:a.message,data:null},400)}let s=kt(t);try{let a=Ve(e,r||"/");return await Dh(a,n,s),t.json({code:200,message:"success",data:null})}catch(a){return t.json({code:500,message:Pe(a),data:null})}});at.post("/remove",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let{dir:r,names:i}=await t.req.json().catch(()=>({}));if(!Array.isArray(i)||i.length===0)return t.json({code:400,message:"Parameter 'names' must be a non-empty array",data:null},400);let n=[];try{ca(r||"/"),n=i.map(a=>Rl(a))}catch(a){return t.json({code:400,message:a.message,data:null},400)}let s=kt(t);try{let a=Ve(e,r||"/");return await wo(a,n,s),t.json({code:200,message:"success",data:null})}catch(a){return t.json({code:500,message:Pe(a),data:null})}});at.post("/move",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let{src_dir:r,dst_dir:i,names:n}=await t.req.json().catch(()=>({}));if(!Array.isArray(n)||n.length===0)return t.json({code:400,message:"Parameter 'names' must be a non-empty array",data:null},400);let s=[];try{ca(r||"/"),ca(i||"/"),s=n.map(o=>Rl(o))}catch(o){return t.json({code:400,message:o.message,data:null},400)}let a=kt(t);try{let o=Ve(e,r||"/"),c=Ve(e,i||"/");return await Cl(o,c,s,a),t.json({code:200,message:"success",data:null})}catch(o){return t.json({code:500,message:Pe(o),data:null})}});at.post("/copy",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let{src_dir:r,dst_dir:i,names:n}=await t.req.json().catch(()=>({}));if(!Array.isArray(n)||n.length===0)return t.json({code:400,message:"Parameter 'names' must be a non-empty array",data:null},400);let s=[];try{ca(r||"/"),ca(i||"/"),s=n.map(o=>Rl(o))}catch(o){return t.json({code:400,message:o.message,data:null},400)}let a=kt(t);try{let o=Ve(e,r||"/"),c=Ve(e,i||"/");return await Sh(o,c,s,a),t.json({code:200,message:"success",data:null})}catch(o){return t.json({code:500,message:Pe(o),data:null})}});at.put("/put",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let r=decodeURIComponent(t.req.header("File-Path")||"");if(!r.trim())return t.json({code:400,message:"Missing File-Path header",data:null},400);try{ca(r)}catch(a){return t.json({code:400,message:a.message,data:null},400)}let i=Ve(e,r),n=kt(t),s=v1(t);if(s!==null)return t.json({code:413,message:`File too large (max ${s} bytes)`,data:null},413);try{let a=await t.req.arrayBuffer();return await kn(i,Buffer.from(a),n),t.json({code:200,message:"success",data:null})}catch(a){return t.json({code:500,message:Pe(a),data:null})}});at.put("/form",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let r=decodeURIComponent(t.req.header("File-Path")||"");if(!r.trim())return t.json({code:400,message:"Missing File-Path header",data:null},400);try{ca(r)}catch(a){return t.json({code:400,message:a.message,data:null},400)}let i=Ve(e,r),n=kt(t),s=v1(t);if(s!==null)return t.json({code:413,message:`File too large (max ${s} bytes)`,data:null},413);try{let o=(await t.req.formData()).get("file");if(!o||typeof o=="string")return t.json({code:400,message:"missing file in form data",data:null});let c=Buffer.from(await o.arrayBuffer());return await kn(i,c,n),t.json({code:200,message:"success",data:null})}catch(a){return t.json({code:500,message:Pe(a),data:null})}});at.post("/upload/create",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let{path:r,file_name:i,size:n,md5:s}=await t.req.json().catch(()=>({})),a=Ve(e,r||"/"),o=kt(t);if(!i)return t.json({code:400,message:"path and file_name are required",data:null});try{let c=await rt(a);if(c.isVirtual)throw new Error("failed get storage: storage not found");let u=await et(c.storage.driver,c.storage);if(typeof u.createUploadSession!="function")return t.json({code:200,message:"success",data:null});let l;try{l=await u.createUploadSession(a,c.physical,i,Number(n)||0,s||"")}finally{await Qt(c.storage.driver,c.storage,u,o)}return t.json({code:200,message:"success",data:l})}catch(c){return t.json({code:500,message:Pe(c),data:null})}});at.put("/upload/part",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let r=t.req.header("X-Upload-Session")||"",i=parseInt(t.req.header("X-Part-Number")||"0",10),n=decodeURIComponent(t.req.header("Upload-Path")||""),s=Ve(e,n),a=kt(t);if(!r||!(i>=1)||!s)return t.json({code:400,message:"missing X-Upload-Session / X-Part-Number / Upload-Path",data:null});let o=v1(t,!0);if(o!==null)return t.json({code:413,message:`Part too large (max ${o} bytes)`,data:null},413);try{let c=await rt(s);if(c.isVirtual)throw new Error("failed get storage: storage not found");let u=await et(c.storage.driver,c.storage);if(typeof u.uploadPart!="function")throw new Error("storage does not support chunked upload");let l=Buffer.from(await t.req.arrayBuffer()),d;try{d=await u.uploadPart(r,i,l)}finally{await Qt(c.storage.driver,c.storage,u,a)}return t.json({code:200,message:"success",data:d??null})}catch(c){return t.json({code:500,message:Pe(c),data:null})}});at.post("/upload/complete",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let{path:r,session:i,partMd5s:n}=await t.req.json().catch(()=>({})),s=Ve(e,r||"/"),a=kt(t);if(!i)return t.json({code:400,message:"path and session are required",data:null});try{let o=await rt(s);if(o.isVirtual)throw new Error("failed get storage: storage not found");let c=await et(o.storage.driver,o.storage);if(typeof c.completeUploadSession!="function")throw new Error("storage does not support chunked upload");try{await c.completeUploadSession(i,n)}finally{await Qt(o.storage.driver,o.storage,c,a)}return t.json({code:200,message:"success",data:null})}catch(o){return t.json({code:500,message:Pe(o),data:null})}});at.post("/add_offline_download",async t=>{let e=await Ne(t);if(!e||e.disabled)return t.json({code:401,message:"Unauthorized",data:null},401);let{path:r,urls:i}=await t.req.json().catch(()=>({})),n=Ve(e,r||"/");return!i||i.length===0?t.json({code:400,message:"No URLs provided"}):t.json({code:501,message:"capability unavailable: this runtime has no durable offline-download adapter; use /fs/seed/offline_download with an approved source and a streaming-capable target driver",data:{path:n,accepted:0}},501)});at.post("/search",async t=>{let e=await Ne(t);if(!e||e.disabled)return t.json({code:401,message:"Unauthorized",data:null},401);let r=await t.req.json().catch(()=>({})),i=Ve(e,r.parent||"/");try{let n=await _l({parent:i,keywords:r.keywords||"",scope:r.scope!==void 0?parseInt(r.scope,10):0,page:r.page?parseInt(r.page,10):1,per_page:r.per_page?parseInt(r.per_page,10):30},t.env);return t.json({code:200,message:"success",data:n})}catch(n){return t.json({code:500,message:Pe(n),data:null},500)}});at.post("/other",async t=>{let e=await Ne(t);if(!e||e.disabled)return t.json({code:401,message:"Unauthorized",data:null},401);let r=await t.req.json().catch(()=>({})),i=Ve(e,r.path||"/"),n=r.method;if(!n)return t.json({code:400,message:"Missing required parameter 'method'",data:null},400);if(!new Set(["video_preview"]).has(n)&&!ut(e))return Gt(t);try{let a=await rt(i);if(a.isVirtual||!a.storage)throw new Error("failed get storage: storage not found");let o=await et(a.storage.driver,a.storage);if(typeof o.other=="function"){let c=await o.other(n,a.relative,r);return t.json({code:200,message:"success",data:c})}return t.json({code:500,message:`Driver '${a.storage.driver}' does not support other method '${n}'`,data:null},500)}catch(a){return t.json({code:500,message:Pe(a),data:null},500)}});at.post("/batch_rename",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let{src_dir:r,rename_objects:i}=await t.req.json().catch(()=>({}));if(!Array.isArray(i)||i.length===0)return t.json({code:400,message:"rename_objects is required",data:null},400);let n=Ve(e,r||"/"),s=kt(t);try{for(let a of i){let o=a?.src_name,c=a?.new_name;if(!o||!c)continue;Rl(c);let u=`${n}/${o}`.replace(/\/{2,}/g,"/");await Dh(u,c,s)}return t.json({code:200,message:"success",data:null})}catch(a){return t.json({code:500,message:Pe(a),data:null},500)}});at.post("/regex_rename",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let{src_dir:r,src_name_regex:i,new_name_regex:n}=await t.req.json().catch(()=>({}));if(!i)return t.json({code:400,message:"src_name_regex is required",data:null},400);let s=Ve(e,r||"/"),a=kt(t);try{let o=new RegExp(i),{content:c}=await Xt(s,a);for(let u of c)if(!u.is_dir&&o.test(u.name)){let l=u.name.replace(o,n||"");Rl(l);let d=`${s}/${u.name}`.replace(/\/{2,}/g,"/");await Dh(d,l,a)}return t.json({code:200,message:"success",data:null})}catch(o){return t.json({code:500,message:Pe(o),data:null},500)}});at.post("/recursive_move",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let{src_dir:r,dst_dir:i,conflict_policy:n}=await t.req.json().catch(()=>({})),s=Ve(e,r||"/"),a=Ve(e,i||"/"),o=n||"overwrite",c=kt(t);try{let u=new Set;if(o!=="overwrite"){let A=await Xt(a,c);u=new Set(A.content.map(g=>g.name))}let l=[s],d=0;for(;l.length>0;){let A=l.shift(),{content:g}=await Xt(A,c);for(let f of g)if(f.is_dir)l.push(`${A}/${f.name}`.replace(/\/{2,}/g,"/"));else{if(u.has(f.name)){if(o==="cancel")return t.json({code:403,message:`file [${f.name}] exists`,data:null},403);if(o==="skip")continue}o!=="overwrite"&&u.add(f.name),await Cl(A,a,[f.name],c),d++}}return t.json({code:200,message:`Successfully moved ${d} files`,data:null})}catch(u){return t.json({code:500,message:Pe(u),data:null},500)}});at.post("/remove_empty_directory",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let{src_dir:r}=await t.req.json().catch(()=>({})),i=Ve(e,r||"/"),n=kt(t);try{let s=async a=>{let{content:o}=await Xt(a,n);for(let u of o)u.is_dir&&await s(`${a}/${u.name}`.replace(/\/{2,}/g,"/"));if(a===i)return;if((await Xt(a,n)).content.length===0){let u=a.split("/").slice(0,-1).join("/")||"/",l=a.split("/").pop();await wo(u,[l],n)}};return await s(i),t.json({code:200,message:"success",data:null})}catch(s){return t.json({code:500,message:Pe(s),data:null},500)}});at.post("/link",async t=>{let e=await Ne(t);if(!ls(e))return Gt(t);let{path:r}=await t.req.json().catch(()=>({})),i=Ve(e,r||"/"),n=kt(t);try{let s=await rt(i);if(s.isVirtual||!s.storage)return t.json({code:500,message:"storage not found",data:null},500);let a=await et(s.storage.driver,s.storage);try{let c=await a.get(i,s.physical??"/");if(c&&c.raw_url)return t.json({code:200,message:"success",data:{url:c.raw_url}})}finally{await Qt(s.storage.driver,s.storage,a,n)}let o=await kl(t,i,await xl(t));return t.json({code:200,message:"success",data:{url:`/api/p${xs(i)}?sign=${encodeURIComponent(o)}`}})}catch(s){return t.json({code:500,message:Pe(s),data:null},500)}});at.post("/get_direct_upload_info",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let{path:r,file_name:i,file_size:n}=await t.req.json().catch(()=>({})),s=Ve(e,r||"/");try{let a=await rt(s);if(a.isVirtual||!a.storage)return t.json({code:200,message:"success",data:null});let c=await et(a.storage.driver,a.storage);if(typeof c.getDirectUploadInfo=="function"){let u=await c.getDirectUploadInfo(a.relative,i,n);return t.json({code:200,message:"success",data:u})}if(typeof c.other=="function")for(let u of["direct_upload","get_direct_upload_info"])try{let l=await c.other(u,a.relative,{file_name:i,file_size:n});if(l)return t.json({code:200,message:"success",data:l})}catch{}return t.json({code:200,message:"success",data:null})}catch(a){return t.json({code:500,message:Pe(a),data:null},500)}});function x1(t){let r=(t.startsWith("/")?t:"/"+t).split("/").filter(Boolean),i=r.pop()||"";return{dir:"/"+r.join("/"),name:i}}function cse(t){let e={v:1,...t},r=JSON.stringify(e);return"mpt_"+(typeof btoa=="function"?btoa(String.fromCharCode(...new TextEncoder().encode(r))):Buffer.from(r,"utf8").toString("base64")).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function use(t){if(!t||t.indexOf("mpt_")!==0)return null;try{let e=t.slice(4).replace(/-/g,"+").replace(/_/g,"/"),r=e.length%4?"=".repeat(4-e.length%4):"",i=typeof atob=="function"?new TextDecoder().decode(Uint8Array.from(atob(e+r),s=>s.charCodeAt(0))):Buffer.from(e+r,"base64").toString("utf8"),n=JSON.parse(i);return!n||typeof n.path!="string"||!n.ds||!n.dss?null:n}catch{return null}}function lse(t){return{upload_id:"",state:"receiving",attempt:0,path:t.path,size:t.size,chunk_size:t.cs,total_chunks:t.tc,received:new Set,driver_session:t.dss,partMd5s:new Array(t.tc).fill(void 0),storage_driver:t.ds,created_at:Date.now()}}at.post("/multipart/init",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let r=decodeURIComponent(t.req.header("File-Path")||""),i=parseInt(t.req.header("X-File-Size")||"0",10),n=parseInt(t.req.header("X-Chunk-Size")||"0",10),s=t.req.header("X-File-Md5")||"";if(!r.trim()||i<=0)return t.json({code:400,message:"Missing File-Path / X-File-Size header",data:null},400);if(i>AO)return t.json({code:413,message:`File too large (max ${AO} bytes / 1GB)`,data:null},413);let{dir:a,name:o}=x1(r),c=Ve(e,a),u=kt(t);try{let l=await rt(c);if(l.isVirtual)throw new Error("failed get storage: storage not found");let d=await et(l.storage.driver,l.storage);if(typeof d.createUploadSession!="function")return t.json({code:200,message:"success",data:null});let A=cO(n),g=Math.max(1,Math.ceil(i/A)),f=lO(r,i),p=!1,y="";if(f)p=!0,y=f.upload_id;else{let E=await d.createUploadSession(c,l.physical,o,i,s);if(E?.reuse){let b={upload_id:"",state:"completed",attempt:0,path:r,size:i,chunk_size:A,total_chunks:g,received:new Set(Array.from({length:g},(B,k)=>k)),driver_session:"",partMd5s:new Array(g).fill(void 0),storage_driver:l.storage.driver,created_at:Date.now()},C=oa(b);return C.storage_progress=100,t.json({code:200,message:"success",data:C})}y=cse({path:r,size:i,cs:A,tc:g,ds:l.storage.driver,dss:E?.session||""}),f={upload_id:y,state:"receiving",attempt:0,path:r,size:i,chunk_size:A,total_chunks:g,received:new Set,driver_session:E?.session||"",partMd5s:new Array(g).fill(void 0),storage_driver:l.storage.driver,created_at:Date.now()},Nl(f)}await Qt(l.storage.driver,l.storage,d,u);let m=oa(f);return m.upload_id=y,t.json({code:200,message:"success",data:{...m,resumed:p}})}catch(l){return t.json({code:500,message:Pe(l),data:null},500)}});function Rh(t){let e=uO(t);if(e)return e;let r=use(t);if(!r)return null;let i=lse(r);return i.upload_id=t,i}at.put("/multipart/chunk",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let r=t.req.header("X-Upload-Id")||"",i=parseInt(t.req.header("X-Chunk-Index")||"-1",10),n=r?Rh(r):null;if(!n)return t.json({code:404,message:"upload session not found",data:null},404);if(i<0||i>=n.total_chunks)return t.json({code:400,message:"invalid X-Chunk-Index",data:null},400);if(n.received.has(i))return t.json({code:200,message:"success",data:oa(n)});let s=v1(t,!0);if(s!==null)return t.json({code:413,message:`Part too large (max ${s} bytes)`,data:null},413);let a=kt(t);try{let o=await rt(Ve(e,x1(n.path).dir));if(o.isVirtual)throw new Error("failed get storage: storage not found");let c=await et(o.storage.driver,o.storage);if(typeof c.uploadPart!="function")throw new Error("storage does not support chunked upload");let u=Buffer.from(await t.req.arrayBuffer()),l;try{l=await c.uploadPart(n.driver_session,i+1,u)}finally{await Qt(o.storage.driver,o.storage,c,a)}n.received.add(i),l?.partMd5&&(n.partMd5s[i]=l.partMd5),n.upload_id||(n.upload_id=r),Nl(n);let d=oa(n);return d.upload_id=r,t.json({code:200,message:"success",data:d})}catch(o){return t.json({code:500,message:Pe(o),data:null},500)}});at.get("/multipart/presign",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let r=t.req.query("upload_id")||"",i=parseInt(t.req.query("index")||"-1",10),n=r?Rh(r):null;if(!n)return t.json({code:404,message:"upload session not found",data:null},404);if(i<0||i>=n.total_chunks)return t.json({code:400,message:"invalid index",data:null},400);let s=kt(t);try{let a=await rt(Ve(e,x1(n.path).dir));if(a.isVirtual)throw new Error("failed get storage: storage not found");let o=await et(a.storage.driver,a.storage),c=o.getPartUploadUrl;if(typeof c!="function")return t.json({code:200,message:"success",data:null});let u=await c.call(o,n.driver_session,i+1);return await Qt(a.storage.driver,a.storage,o,s),t.json({code:200,message:"success",data:{index:i,part_number:i+1,url:u,total_chunks:n.total_chunks,chunk_size:n.chunk_size,path:n.path}})}catch(a){return t.json({code:500,message:Pe(a),data:null},500)}});at.get("/multipart/confirm",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let r=t.req.query("upload_id")||"",i=parseInt(t.req.query("index")||"-1",10),n=r?Rh(r):null;if(!n)return t.json({code:404,message:"upload session not found",data:null},404);if(i<0||i>=n.total_chunks)return t.json({code:400,message:"invalid index",data:null},400);n.received.add(i),n.upload_id||(n.upload_id=r),Nl(n);let s=oa(n);return s.upload_id=r,t.json({code:200,message:"success",data:s})});at.post("/multipart/complete",async t=>{let e=await Ne(t);if(!ut(e))return Gt(t);let r=t.req.header("X-Upload-Id")||"",i=r?Rh(r):null;if(!i)return t.json({code:404,message:"upload session not found",data:null},404);if(i.state==="completed")return t.json({code:200,message:"success",data:oa(i)});let n=kt(t);try{let s=await rt(Ve(e,x1(i.path).dir));if(s.isVirtual)throw new Error("failed get storage: storage not found");let a=await et(s.storage.driver,s.storage);if(typeof a.completeUploadSession!="function")throw new Error("storage does not support chunked upload");try{await a.completeUploadSession(i.driver_session,i.partMd5s.filter(c=>c!==void 0))}finally{await Qt(s.storage.driver,s.storage,a,n)}i.state="completed",i.upload_id||(i.upload_id=r),Nl(i),dO(r);let o=oa(i);return o.upload_id=r,o.storage_progress=100,t.json({code:200,message:"success",data:o})}catch(s){return i.state="failed_permanent",i.error=Pe(s),Nl(i),t.json({code:500,message:Pe(s),data:null},500)}});at.get("/multipart/status",async t=>{let e=t.req.query("upload_id")||"",r=e?Rh(e):null;if(!r)return t.json({code:404,message:"upload session not found",data:null},404);let i=oa(r);return i.upload_id=e,t.json({code:200,message:"success",data:i})});function qb(t){let e=t.toLowerCase();return e.endsWith(".zip")?"zip":e.endsWith(".tar.gz")||e.endsWith(".tgz")?"tar.gz":e.endsWith(".tar.bz2")||e.endsWith(".tbz2")?"tar.bz2":e.endsWith(".tar.xz")||e.endsWith(".txz")?"tar.xz":e.endsWith(".tar")?"tar":e.endsWith(".7z")?"7z":e.endsWith(".rar")?"rar":null}function Hb(t){return t==="zip"}async function Kb(t,e,r){let i=Ve(e,r),n=await rt(i);if(n.isVirtual)throw new Error("failed get storage: storage not found");let s=await et(n.storage.driver,n.storage),a;try{a=await s.get(r,n.physical)}finally{await Qt(n.storage.driver,n.storage,s,kt(t))}if(!a||!a.raw_url)throw new Error("archive driver did not return download link");let o=zf(n.storage?.addition,t.env);Rr(a.raw_url,"Archive download",o);let c=await fetch(a.raw_url,{headers:a.raw_url_headers||{}});if(!c.ok)throw new Error(`archive download failed: HTTP ${c.status}`);return await c.arrayBuffer()}function dse(t){let e=[],r=new Map;for(let i of t.entries){let n=i.name.split("/").filter(Boolean);if(n.length===0)continue;let s=e,a="";for(let o=0;o<n.length;o++){let c=n[o],u=o===n.length-1;if(a=a?`${a}/${c}`:`/${c}`,u)s.push({name:c,size:i.size,is_dir:!1,modified:i.modified||new Date().toISOString(),type:hO(c,!1),children:[]});else{let l=r.get(a);l||(l={name:c,size:0,is_dir:!0,modified:i.modified||new Date().toISOString(),type:1,children:[]},r.set(a,l),s.push(l)),s=l.children}}}return e}function hO(t,e){let r=t.split(".").pop()?.toLowerCase()||"";if(e)return 1;let i=["mp4","mkv","webm","avi","mov","flv","m3u8"],n=["mp3","flac","wav","aac","ogg","m4a"],s=["jpg","jpeg","png","gif","webp","svg","bmp","ico"],a=["txt","md","json","js","ts","css","html","xml","yml","log"];return i.includes(r)?2:n.includes(r)?3:s.includes(r)?4:a.includes(r)?5:6}at.post("/archive/meta",async t=>{let e=await Ne(t);if(!e||e.disabled)return t.json({code:401,message:"Unauthorized",data:null},401);let r=await t.req.json().catch(()=>({})),i=String(r.path||t.req.query("path")||"").trim();if(!i)return t.json({code:400,message:"path is required",data:null},400);let n=qb(i);if(!n)return t.json({code:400,message:"unrecognized archive format",data:null},400);if(!Hb(n))return t.json({code:501,message:`archive format '${n}' is recognized but not supported in this runtime (Worker supports ZIP only); use the Go backend for ${n} archives`,data:null},501);try{let s=await Kb(t,e,i),a=I1(s),o=dse(a);return t.json({code:200,message:"success",data:{comment:"",encrypted:!1,content:o,raw_url:"",sign:""}})}catch(s){return t.json({code:500,message:Pe(s),data:null},500)}});at.post("/archive/list",async t=>{let e=await Ne(t);if(!e||e.disabled)return t.json({code:401,message:"Unauthorized",data:null},401);let r=await t.req.json().catch(()=>({})),i=String(r.path||t.req.query("path")||"").trim(),n=String(r.inner_path||"").trim().replace(/\/+/g,"/");if(!i)return t.json({code:400,message:"path is required",data:null},400);let s=qb(i);if(!s)return t.json({code:400,message:"unrecognized archive format",data:null},400);if(!Hb(s))return t.json({code:501,message:`archive format '${s}' is recognized but not supported in this runtime; use the Go backend for ${s} archives`,data:null},501);try{let a=await Kb(t,e,i),o=I1(a),c=n?n.replace(/^\/+|\/+$/g,"")+"/":"",u=o.entries.filter(A=>c?A.name.startsWith(c)&&A.name!==c.slice(0,-1):!A.name.includes("/")).map(A=>{let g=c?A.name.slice(c.length):A.name;return{name:g.split("/")[0],size:A.size,is_dir:!1,modified:A.modified||new Date().toISOString(),type:hO(g.split("/")[0],!1)}}),l=new Set,d=u.filter(A=>l.has(A.name)?!1:(l.add(A.name),!0));return t.json({code:200,message:"success",data:{content:d,total:d.length}})}catch(a){return t.json({code:500,message:Pe(a),data:null},500)}});at.post("/archive/decompress",async t=>{let e=await Ne(t);if(!ut(e))return t.json({code:403,message:"Permission denied",data:null},403);let r=await t.req.json().catch(()=>({})),i=String(r.src_dir||"").trim(),n=String(r.dst_dir||"").trim(),s=Array.isArray(r.name)?r.name:r.name?[String(r.name)]:[],a=String(r.inner_path||"").trim().replace(/\/+/g,"/");if(!s.length||!n)return t.json({code:400,message:"src_dir/dst_dir/name are required",data:null},400);try{let o=0;for(let c of s){let u=i?`${i}/${c}`:`/${c}`,l=qb(c);if(!l||!Hb(l))return t.json({code:400,message:`unsupported archive format: ${c} (only ZIP is supported)`,data:null},400);let d=await Kb(t,e,u),A=I1(d),g=a?a.replace(/^\/+|\/+$/g,"")+"/":"";for(let f of A.entries){if(g&&!f.name.startsWith(g))continue;let p=g?f.name.slice(g.length):f.name;if(!p||p.endsWith("/"))continue;let y=`${n.replace(/\/+$/,"")}/${p}`,m=await zU(d,f);await kn(y,Buffer.from(m),kt(t)),o++}}return t.json({code:200,message:"success",data:{task:null,count:o}})}catch(o){return t.json({code:500,message:Pe(o),data:null},500)}});jc();nr();Ye();Yt();g1();Co();async function H4(t,e,r,i=5){let n=t.req?.method;if(n!=="GET"&&n!=="HEAD")return r();let s=new URL(t.req.url);if(s.searchParams.has("token")||s.searchParams.has("access_token"))return r();let a=wL();if(!a)return r();let o;try{o=new Request(`${s.origin}${s.pathname}`,{method:"GET"})}catch{return r()}try{let u=await a.match(o);if(u)return u}catch{}let c=await r();if(c.status===200){let u=IL(c.clone(),i);try{await(t.executionCtx?.waitUntil?t.executionCtx.waitUntil(a.put(o,u.clone())):a.put(o,u.clone()))}catch{}return IL(c,i)}return c}function IL(t,e){let r=new Headers(t.headers);return r.set("Cache-Control",`public, max-age=0, must-revalidate, s-maxage=${e}`),new Response(t.body,{status:t.status,statusText:t.statusText,headers:r})}function wL(){try{if(typeof caches<"u"){let t=caches.default;if(t)return t}}catch{}return null}async function K4(t){let e=wL();if(!e)return;let r="";try{r=new URL(t.req.url).origin}catch{return}let i=["/api/public/settings","/api/public/init_status"];await Promise.all(i.map(async n=>{try{await e.delete(new Request(`${r}${n}`,{method:"GET"}))}catch{}}))}xd();nr();Ye();jc();jh();na();bi();P4();var Tn=new je;Tn.get("/list",async t=>{let r=((await se(t.env)).users||[]).map(i=>({id:i.id,username:i.username,role:i.role,permission:i.permission??0,base_path:i.base_path||"/",disabled:!!i.disabled,sso_id:i.sso_id||"",allow_ldap:!!i.allow_ldap,pwd_update_at:i.pwd_update_at||"",otp:!!i.otp_secret}));return t.json({code:200,message:"success",data:{content:r,total:r.length}})});Tn.get("/get",async t=>{let e=t.req.query("id");if(!e)return t.json({code:400,message:"Missing id parameter",data:null},400);let r=parseInt(e,10),n=((await se(t.env)).users||[]).find(s=>s.id===r);return n?t.json({code:200,message:"success",data:{id:n.id,username:n.username,password:"",role:n.role,permission:n.permission??0,base_path:n.base_path||"/",disabled:!!n.disabled,sso_id:n.sso_id||"",allow_ldap:!!n.allow_ldap,otp:!!n.otp_secret}}):t.json({code:404,message:"User not found",data:null},404)});Tn.post("/create",async t=>{let e=await t.req.json().catch(()=>({}));if(!e.username)return t.json({code:400,message:"Username is required",data:null},400);let r=await se(t.env);if(r.users||(r.users=[]),r.users.some(u=>u.username===e.username))return t.json({code:400,message:"Username already exists",data:null},400);let s=r.users.reduce((u,l)=>Math.max(u,l.id||0),0)+1,a=e.password||"",o=null;a||(o=Jl(),a=o);let c={id:s,username:e.username,role:e.role!==void 0?parseInt(e.role,10):0,permission:e.permission!==void 0?parseInt(e.permission,10):0,base_path:e.base_path||"/",disabled:!!e.disabled,sso_id:e.sso_id||"",allow_ldap:!!e.allow_ldap,pwd_update_at:new Date().toISOString()};return await Si(c,a),r.users.push(c),await de(r,t.env),t.json({code:200,message:o?"success (a random password was generated \u2014 pass one explicitly to choose your own)":"success",data:o?{password:o}:null})});Tn.post("/update",async t=>{let e=await t.req.json().catch(()=>({}));if(!e.id)return t.json({code:400,message:"User ID is required",data:null},400);let r=parseInt(e.id,10),i=await se(t.env);i.users||(i.users=[]);let n=i.users.findIndex(a=>a.id===r);if(n===-1)return t.json({code:404,message:"User not found",data:null},404);let s=i.users[n];if(e.username&&e.username!==s.username){if(i.users.some(o=>o.id!==r&&o.username===e.username))return t.json({code:400,message:"Username already in use",data:null},400);s.username=e.username}return e.password&&e.password.trim()!==""&&await Si(s,e.password.trim()),e.role!==void 0&&(s.role=parseInt(e.role,10)),e.permission!==void 0&&(s.permission=parseInt(e.permission,10)),e.base_path!==void 0&&(s.base_path=e.base_path),e.disabled!==void 0&&(s.disabled=!!e.disabled),e.sso_id!==void 0&&(s.sso_id=e.sso_id),e.allow_ldap!==void 0&&(s.allow_ldap=!!e.allow_ldap),i.users[n]=s,await de(i,t.env),t.json({code:200,message:"success",data:null})});var EL=async t=>{let e=t.req.query("id");if(!e)return t.json({code:400,message:"Missing id parameter",data:null},400);let r=parseInt(e,10);if(r===1)return t.json({code:400,message:"Cannot delete primary admin user",data:null},400);let i=await se(t.env);return i.users||(i.users=[]),i.users=i.users.filter(n=>n.id!==r),await de(i,t.env),t.json({code:200,message:"success",data:null})};Tn.post("/delete",EL);Tn.post("/cancel",EL);Tn.get("/sshkey/list",async t=>{let e=parseInt(t.req.query("uid")||"0",10),r=await Hl(e,t.env);return t.json({code:200,message:"success",data:{content:r,total:r.length}})});Tn.post("/sshkey/delete",async t=>{let e=parseInt(t.req.query("uid")||"0",10),r=t.req.query("id");if(!e||!r)return t.json({code:400,message:"Missing uid or id parameter",data:null},400);if(!await Z1(e,r,t.env))return t.json({code:404,message:"SSH key not found",data:null},404);let n=await Hl(e,t.env);return t.json({code:200,message:"success",data:n})});Tn.post("/cancel_2fa",async t=>{let e=parseInt(t.req.query("id")||"0",10);if(!e)return t.json({code:400,message:"Missing id parameter",data:null},400);let r=await se(t.env),i=(r.users||[]).find(n=>n.id===e);return i?(delete i.otp_secret,await de(r,t.env),t.json({code:200,message:"success",data:null})):t.json({code:404,message:"User not found",data:null},404)});var CL=async t=>{let e=t.req.header("Authorization");if(!e)return t.json({code:401,message:"Unauthorized",data:null},401);let r=e.startsWith("Bearer ")?e.substring(7):e;try{let i=await Er(t),n=await ra(r,i,"HS256"),s=await t.req.json().catch(()=>({})),a=s.old_password||"",o=s.new_password||"";if(!o)return t.json({code:400,message:"New password is required",data:null},400);let c=await se(t.env);c.users||(c.users=[]);let u=c.users.findIndex(d=>d.id===n.id||d.username===n.username);if(u===-1)return t.json({code:404,message:"User not found",data:null},404);let l=c.users[u];return!l.password||!await zl(l,a)?t.json({code:400,message:"Incorrect old password",data:null},400):(await Si(l,o),c.users[u]=l,await de(c,t.env),t.json({code:200,message:"success",data:null}))}catch(i){return t.json({code:401,message:`Unauthorized: ${i.message||"Invalid token"}`,data:null},401)}};var Fe=new je;Fe.use("*",async(t,e)=>{if(!await Sl(t))return t.json({code:401,message:"Unauthorized",data:null});await e()});function Qae(t=32){let e="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",r=new Uint8Array(t);if(typeof crypto<"u"&&typeof crypto.getRandomValues=="function")crypto.getRandomValues(r);else for(let n=0;n<t;n++)r[n]=(Math.random()*256|0)^Date.now()&255;let i="";for(let n=0;n<t;n++)i+=e.charAt(r[n]%e.length);return i}Fe.get("/storage/list",async t=>{let r=[...(await se(t.env)).storages||[]].sort((i,n)=>{let s=Number(i.order)||0,a=Number(n.order)||0;return s!==a?s-a:(Number(i.id)||0)-(Number(n.id)||0)});return t.json({code:200,message:"success",data:{content:r,total:r.length}})});Fe.post("/storage/load_all",async t=>{let e=await se(t.env),r=[],i=0,n=0;for(let s of e.storages||[])if(!s.disabled)try{await et(s.driver,s),i++,r.push({id:s.id,mount_path:s.mount_path,driver:s.driver,status:"ok"})}catch(a){n++,r.push({id:s.id,mount_path:s.mount_path,driver:s.driver,status:"failed",error:a?.message||String(a)})}return t.json({code:200,message:"success",data:{loaded:i,failed:n,results:r}})});Fe.get("/storage/get",async t=>{let e=parseInt(t.req.query("id")||"0",10),i=(await se(t.env)).storages.find(n=>n.id===e);return i?t.json({code:200,message:"success",data:i}):t.json({code:404,message:"storage not found",data:null})});var bL=t=>{let e=(t||"").toLowerCase().replace(/[^a-z0-9]/g,"");if(!e)return"";let i=Object.keys(Vl).find(n=>n.toLowerCase()===e||n.toLowerCase().replace(/[^a-z0-9]/g,"")===e);return i||(e.startsWith("115")?"115Open":e.startsWith("123")?"123Pan":e.includes("aliyun")?"AliyundriveOpen":e.startsWith("baidu")?"BaiduNetdisk":e.startsWith("189")||e.includes("cloud189")||e.includes("ctyun")?"Cloud189":e==="onedriveapp"?"OnedriveAPP":e.startsWith("onedrive")?"Onedrive":e.startsWith("google")||e.includes("gdrive")?"GoogleDrive":(e.includes("thunder")||e.includes("xunlei"))&&e.includes("expert")?"ThunderExpert":e.includes("thunder")||e.includes("xunlei")?"Thunder":e==="webdav"||e==="webdavdriver"?"WebDav":e==="wopan"||e.includes("unicom")||e.includes("woyun")?"WoPan":e==="quark"||e==="quarkuc"||e==="uc"?"Quark":["s3","doge","dogecloud","minio","ceph","aws","r2","b2","cos","oss","kodo"].includes(e)?"S3":e.startsWith("github")?"Github":e==="local"?"Local":e.includes("pikpak")?"PikPak":e.includes("seafile")?"Seafile":e.includes("yandex")?"YandexDisk":e.includes("terabox")||e.includes("dubox")?"Terabox":e.includes("mediatrack")||e.includes("fenmiao")?"MediaTrack":e.includes("alias")?"Alias":t||"")},DL=(t,e)=>{let r="";if(typeof e=="object"&&e!==null)try{r=JSON.stringify(e)}catch{r="{}"}else r=String(e||"{}");let i=(t||"").toLowerCase();if(i.includes("thunder")||i.includes("xunlei"))try{let n=JSON.parse(r||"{}");if(!n.device_id||typeof n.device_id!="string"||n.device_id.trim().length!==32){let s=typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID().replace(/-/g,""):Math.random().toString(16).substring(2).padEnd(16,"0")+Math.random().toString(16).substring(2).padEnd(16,"0");return n.device_id=s.slice(0,32),JSON.stringify(n)}}catch{}return r};Fe.post("/storage/create",async t=>{let e=await t.req.json().catch(()=>({})),r=await se(t.env);if(!e.driver||typeof e.driver!="string"||e.driver.trim()===""||e.driver==="undefined"||e.driver==="null")return t.json({code:400,message:"Storage driver is required",data:null},400);let i=e.mount_path;if(!i||String(i).trim()===""){let c=Vl[e.driver]?.default_mount_path;c&&(i=c)}let n="/"+String(i||"").split("/").filter(Boolean).join("/");if(r.storages.some(c=>!c.disabled&&"/"+(c.mount_path||"").split("/").filter(Boolean).join("/")===n))return t.json({code:400,message:`mount path already exists: ${n}`,data:null});let s=bL(e.driver),a=DL(s,e.addition||"{}"),o={...e,driver:s,addition:a,mount_path:n,id:r.storages.length?Math.max(...r.storages.map(c=>c.id))+1:1,status:"work",modified:new Date().toISOString()};r.storages.push(o);try{await de(r,t.env)}catch(c){return r.storages.pop(),t.json({code:500,message:`Failed to save storage config: ${c.message||String(c)}`,data:null})}if(!o.disabled){try{await et(o.driver,o),o.status="work"}catch(c){o.status=c.message||String(c),String(c.message||c).includes("unsupported driver")&&(o.disabled=!0);try{await de(r,t.env)}catch(u){console.error("[admin/storage/create] Failed to update storage status:",u)}return t.json({code:500,message:c.message||String(c),data:o})}try{await de(r,t.env)}catch(c){console.error("[admin/storage/create] Failed to update storage status after connection:",c)}}return t.json({code:200,message:"success",data:o})});Fe.post("/storage/update",async t=>{let e=await t.req.json().catch(()=>({})),r=await se(t.env),i=e.mount_path;if(!i||String(i).trim()===""){let a=Vl[e.driver]?.default_mount_path;a&&(i=a)}let n=String(i||"").trim()!==""?"/"+String(i||"").split("/").filter(Boolean).join("/"):void 0;if(n&&r.storages.some(a=>a.id!==e.id&&!a.disabled&&"/"+(a.mount_path||"").split("/").filter(Boolean).join("/")===n))return t.json({code:400,message:`mount path already exists: ${n}`,data:null});let s=r.storages.findIndex(a=>a.id===e.id);if(s!==-1){let a=e.driver||r.storages[s].driver,o=bL(a),c=DL(o,e.addition!==void 0?e.addition:r.storages[s].addition||"{}"),u={...r.storages[s],...e,driver:o,addition:c,mount_path:n||r.storages[s].mount_path,modified:new Date().toISOString()};if(!u.disabled)try{await et(u.driver,u,{deferTokenPersistence:!0}),u.status="work"}catch(l){return u.status=l.message||String(l),String(l.message||l).includes("unsupported driver")&&(u.disabled=!0),r.storages[s]=u,await de(r,t.env),t.json({code:500,message:l.message||String(l),data:{id:u.id}})}r.storages[s]=u,await de(r,t.env)}return t.json({code:200,message:"success",data:null})});Fe.post("/storage/delete",async t=>{let e=parseInt(t.req.query("id")||"0",10),r=await se(t.env);return r.storages=r.storages.filter(i=>i.id!==e),await de(r,t.env),t.json({code:200,message:"success",data:null})});Fe.post("/storage/enable",async t=>{let e=parseInt(t.req.query("id")||"0",10),r=await se(t.env),i=r.storages.find(n=>n.id===e);return i&&(i.disabled=!1,i.modified=new Date().toISOString(),await de(r,t.env),(async()=>{try{await et(i.driver,i);let n=await se(t.env),s=n.storages.find(a=>a.id===e);s&&!s.disabled&&(s.status="work",s.modified=new Date().toISOString(),await de(n,t.env))}catch(n){let s=await se(t.env),a=s.storages.find(o=>o.id===e);a&&!a.disabled&&(a.status=n.message||String(n),await de(s,t.env))}})()),t.json({code:200,message:"success",data:null})});Fe.post("/storage/disable",async t=>{let e=parseInt(t.req.query("id")||"0",10),r=await se(t.env),i=r.storages.find(n=>n.id===e);return i&&(i.disabled=!0,await de(r,t.env)),t.json({code:200,message:"success",data:null})});Fe.get("/driver/names",t=>t.json({code:200,message:"success",data:["AliyundriveOpen","GoogleDrive","Onedrive","OnedriveAPP","Quark","123Pan","BaiduNetdisk","115Open","GitHub API","Thunder","ThunderExpert","189Cloud","WoPan","Lanzou","WebDav","S3","Doge","PikPak","Seafile","YandexDisk","Terabox","MediaTrack","Alias","Dropbox","WPS","139Yun","Mega_nz","115Share","123PanShare","AliyundriveShare","OnedriveSharelink","PikPakShare","SMB","Crypt","Virtual","AListV3","UrlTree","Strm","AzureBlob","USS","Alidoc","Emby","BunnyStorage","CloudflareImgbed","GuangYaPan","AutoIndex","ProtonDrive"]}));var Tt=[{name:"mount_path",type:"string",default:"",required:!0},{name:"order",type:"number",default:"0",required:!1},{name:"remark",type:"string",default:"",required:!1},{name:"cache_expiration",type:"number",default:"30",required:!1,help:"\u76EE\u5F55\u5185\u5BB9\u7F13\u5B58\u65F6\u957F\uFF08\u5206\u949F\uFF09"}],Pt={name:"custom_cache_policies",type:"text",default:"",required:!1,help:'\u6309\u8DEF\u5F84\u8986\u76D6\u7F13\u5B58\u65F6\u957F\uFF0CJSON \u683C\u5F0F\uFF0C\u5982 [{"path":"/photos/*","cache_expiration":1440}]'},Ft={name:"enable_sign",type:"bool",default:"false",required:!0,help:"Enable signature validation for this storage"},Nt={name:"disable_index",type:"bool",default:"false",required:!1,help:"Disable directory listing for this storage"};function Tae(){return{name:"proxy_range",type:"bool",default:"true",required:!1,help:"Need to enable proxy"}}var BL={name:"web_proxy",type:"bool",default:"false",required:!1},G4={name:"webdav_policy",type:"select",options:"302_redirect,use_proxy_url,native_proxy",default:"302_redirect",required:!1};function Rt(t=""){let e=$o(t),r=mx.has(e)?[Tae()]:[];if(Ix(e))return[...r,{...G4,options:"use_proxy_url,native_proxy",default:"native_proxy"}];let i=q2(e);return[...r,i?{...BL,default:"true"}:{...BL},i?{...G4,default:"native_proxy"}:{...G4}]}var Zt={name:"seed_policy",type:"select",options:"inherit,on,off",default:"inherit",required:!0,help:"Override automatic transfer-seed generation for this storage"},Vc={name:"down_proxy_url",type:"string",default:"",required:!1,help:"\u81EA\u5B9A\u4E49\u4E0B\u8F7D\u4EE3\u7406\u5730\u5740\uFF08\u652F\u6301 $path \u5360\u4F4D\u7B26\uFF1B\u7559\u7A7A\u5219\u7528\u672C\u670D\u52A1\u4EE3\u7406\uFF09"},Ut={name:"disable_proxy_sign",type:"bool",default:"false",required:!1,help:"Disable sign for Download proxy URL"},ft=[...Tt,Pt,Ft,Nt,...Rt(),Vc,Ut,Zt],Vl={AliyundriveOpen:{name:"AliyundriveOpen",default_mount_path:"/aliyundrive",common:ft,additional:[{name:"refresh_token",type:"text",default:"",required:!0,help:"true"},{name:"drive_type",type:"select",options:"resource,backup,default",default:"resource",required:!0},{name:"drive_id",type:"string",default:"",required:!1},{name:"root_folder_id",type:"string",default:"root",required:!0},{name:"order_by",type:"select",options:"updated_at,name,size,created_at",default:"updated_at",required:!1},{name:"order_direction",type:"select",options:"DESC,ASC",default:"DESC",required:!1},{name:"api_url_address",type:"string",default:"https://api.oplist.org/alicloud/renewapi",required:!1,help:"true"},{name:"alipan_type",type:"select",options:"alipanQR,alipanTV",default:"alipanQR",required:!1},{name:"client_id",type:"string",default:"",required:!1},{name:"client_secret",type:"string",default:"",required:!1},{name:"remove_way",type:"select",options:"trash,delete",default:"trash",required:!1}],config:{name:"AliyundriveOpen",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"root"}},Onedrive:{name:"Onedrive",default_mount_path:"/onedrive",common:[...Tt,Pt,Ft,Nt,...Rt("Onedrive"),Vc,Ut],additional:[{name:"root_folder_path",type:"string",default:"/",required:!0},{name:"region",type:"select",options:"global,cn,us,de",default:"global",required:!0},{name:"is_sharepoint",type:"bool",default:"false",required:!1},{name:"use_online_api",type:"bool",default:"true",required:!1},{name:"api_url_address",type:"string",default:"https://api.oplist.org/onedrive/renewapi",required:!1},{name:"client_id",type:"string",default:"",required:!1},{name:"client_secret",type:"string",default:"",required:!1},{name:"redirect_uri",type:"string",default:"https://api.oplist.org/onedrive/callback",required:!0},{name:"refresh_token",type:"string",default:"",required:!0},{name:"site_id",type:"string",default:"",required:!1},{name:"chunk_size",type:"number",default:"5",required:!1},{name:"custom_host",type:"string",default:"",required:!1,help:"true"},{name:"disable_disk_usage",type:"bool",default:"false",required:!1,help:"true"},{name:"enable_direct_upload",type:"bool",default:"false",required:!1,help:"true"},{name:"order_by",type:"select",options:"filename,modified_time,size",default:"filename",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"Onedrive",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},OnedriveAPP:{name:"OnedriveAPP",default_mount_path:"/onedrive_app",common:[...Tt,Pt,Ft,Nt,...Rt("OnedriveAPP"),Vc,Ut],additional:[{name:"root_folder_path",type:"string",default:"/",required:!0},{name:"region",type:"select",options:"global,cn,us,de",default:"global",required:!0},{name:"client_id",type:"string",default:"",required:!0},{name:"client_secret",type:"string",default:"",required:!0},{name:"tenant_id",type:"string",default:"",required:!0},{name:"email",type:"string",default:"",required:!0},{name:"chunk_size",type:"number",default:"5",required:!1},{name:"custom_host",type:"string",default:"",required:!1,help:"true"},{name:"disable_disk_usage",type:"bool",default:"false",required:!1,help:"true"},{name:"enable_direct_upload",type:"bool",default:"false",required:!1,help:"true"},{name:"order_by",type:"select",options:"filename,modified_time,size",default:"filename",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"OnedriveAPP",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},GoogleDrive:{name:"GoogleDrive",default_mount_path:"/google-drive",common:[...Tt,Pt,Ft,Nt,...Rt("GoogleDrive"),Ut,Zt],additional:[{name:"refresh_token",type:"text",default:"",required:!0,help:"true"},{name:"root_folder_id",type:"string",default:"root",required:!1},{name:"order_by",type:"select",options:"folder,name,modifiedTime desc",default:"folder,name,modifiedTime desc",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1},{name:"api_url_address",type:"string",default:"https://api.alist.nn.ci/googledrive/token",required:!1,help:"true"},{name:"use_online_api",type:"bool",default:"true",required:!1},{name:"client_id",type:"string",default:"",required:!1},{name:"client_secret",type:"string",default:"",required:!1},{name:"chunk_size",type:"number",default:"5",required:!1}],config:{name:"GoogleDrive",local_sort:!0,only_local:!1,only_proxy:!0,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"root"}},Quark:{name:"Quark",default_mount_path:"/quark",common:ft,additional:[{name:"variant",type:"select",options:"Quark,UC",default:"Quark",required:!0},{name:"cookie",type:"text",default:"",required:!0,help:"true"},{name:"root_folder_id",type:"string",default:"0",required:!0},{name:"order_by",type:"select",options:"none,file_type,file_name,updated_at",default:"none",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1},{name:"use_transcoding_address",type:"bool",default:"false",required:!1},{name:"only_list_video_file",type:"bool",default:"false",required:!1}],config:{name:"Quark",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"0"}},"123Pan":{name:"123Pan",default_mount_path:"/123",common:[...Tt,Pt,Ft,Nt,...Rt("123Pan"),Ut,Zt],additional:[{name:"username",type:"string",default:"",required:!0},{name:"password",type:"string",default:"",required:!0},{name:"access_token",type:"string",default:"",required:!1,help:"\u767B\u5F55\u4EE4\u724C\uFF08\u53EF\u9009\uFF0C\u81EA\u52A8\u6301\u4E45\u5316\uFF0C\u65E0\u9700\u624B\u52A8\u586B\u5199\uFF09\u3002\u4EC5\u9700\u586B\u5199\u4E0A\u65B9 123 \u7F51\u76D8\u624B\u673A\u53F7\u548C\u5BC6\u7801\uFF0C\u767B\u5F55\u540E\u81EA\u52A8\u83B7\u53D6\u5E76\u4FDD\u5B58\uFF0C\u8DF3\u8FC7\u91CD\u590D\u767B\u5F55\u53EF\u907F\u514D\u5883\u5916 IP \u89E6\u53D1\u98CE\u63A7\u3002"},{name:"cookie",type:"text",default:"",required:!1,help:"\u6D4F\u89C8\u5668 Cookie\uFF08\u53EF\u9009\uFF09\u3002\u5728 123 \u7F51\u76D8\u7F51\u9875\u767B\u5F55\u540E\uFF0C\u4ECE\u5F00\u53D1\u8005\u5DE5\u5177\u590D\u5236\u8BF7\u6C42\u5934\u4E2D\u7684 Cookie \u6574\u4E32\u7C98\u8D34\u4E8E\u6B64\uFF08\u542B sso-token\uFF09\uFF0C\u6216\u4ECE Authorization: Bearer <token> \u4E2D\u590D\u5236 token/Bearer \u503C\u3002\u89E3\u6790\u51FA\u7684 JWT \u4F1A\u4F5C\u4E3A Bearer \u4EE4\u724C\u4F7F\u7528\uFF0C\u6548\u679C\u7B49\u540C\u8BBF\u95EE\u4EE4\u724C\uFF0C\u9002\u5408\u8D26\u53F7\u5BC6\u7801\u767B\u5F55\u88AB\u98CE\u63A7\u62E6\u622A\u7684\u73AF\u5883\u3002"},{name:"root_id",type:"string",default:"0",required:!1},{name:"upload_thread",type:"number",default:"3",required:!1,help:"the threads of upload"},{name:"platform",type:"string",default:"web",required:!1,help:"the platform header value, sent with API requests"},{name:"order_by",type:"select",options:"file_id,file_name,size,created_at,updated_at",default:"file_id",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"desc",required:!1}],config:{name:"123Pan",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"0"}},BaiduNetdisk:{name:"BaiduNetdisk",default_mount_path:"/baidu",common:[...Tt,Pt,Ft,Nt,...Rt("BaiduNetdisk"),Ut,Zt],additional:[{name:"refresh_token",type:"text",default:"",required:!0,help:"true"},{name:"access_token",type:"string",default:"",required:!0,help:"\u8BBF\u95EE\u4EE4\u724C\uFF08\u5FC5\u586B\uFF09\u3002\u901A\u8FC7 https://api.oplist.org/ \u83B7\u53D6\u3002\u82E5\u4EE4\u724C\u5931\u6548\uFF0C\u6302\u8F7D\u65F6\u4F1A\u81EA\u52A8\u6839\u636E refresh_token \u901A\u8FC7\u5728\u7EBF API \u6362\u65B0\u5E76\u6301\u4E45\u5316\u3002"},{name:"use_online_api",type:"bool",default:"true",required:!1,help:"\u4F7F\u7528\u5728\u7EBF API \u5237\u65B0 token\uFF08\u65E0\u9700 ClientID/ClientSecret\uFF09"},{name:"api_url_address",type:"string",default:"https://api.oplist.org/baiduyun/renewapi",required:!1},{name:"client_id",type:"string",default:"",required:!1},{name:"client_secret",type:"string",default:"",required:!1},{name:"download_api",type:"select",options:"official,crack,crack_video",default:"official",required:!1},{name:"custom_crack_ua",type:"string",default:"netdisk",required:!0},{name:"order_by",type:"select",options:"name,time,size",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1},{name:"only_list_video_file",type:"bool",default:"false",required:!1},{name:"upload_thread",type:"string",default:"3",required:!1,help:"1<=thread<=32"},{name:"upload_timeout",type:"number",default:"60",required:!1,help:"per-slice upload timeout in seconds"},{name:"custom_upload_part_size",type:"number",default:"0",required:!1,help:"0 for auto"},{name:"use_dynamic_upload_api",type:"bool",default:"true",required:!1,help:"dynamically get upload api domain, when enabled, the 'Upload API' setting will be used as a fallback if failed to get"},{name:"upload_api",type:"string",default:"https://d.pcs.baidu.com",required:!1},{name:"low_bandwith_upload_mode",type:"bool",default:"false",required:!1}],config:{name:"BaiduNetdisk",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},"115Open":{name:"115Open",default_mount_path:"/115",common:[...Tt,Pt,Ft,Nt,...Rt("115Open"),Ut,Zt],additional:[{name:"access_token",type:"string",default:"",required:!0,help:"\u8BBF\u95EE\u4EE4\u724C\uFF08\u5FC5\u586B\uFF09\u3002\u901A\u8FC7 115 \u5F00\u653E\u5E73\u53F0\u83B7\u53D6\uFF1B\u5931\u6548\u65F6\u81EA\u52A8\u7528 refresh_token \u5237\u65B0\u5E76\u6301\u4E45\u5316\u3002"},{name:"refresh_token",type:"string",default:"",required:!0,help:"\u5237\u65B0\u4EE4\u724C\uFF08\u5FC5\u586B\uFF09\u3002\u901A\u8FC7 115 \u5F00\u653E\u5E73\u53F0\u83B7\u53D6\uFF1Baccess_token \u5931\u6548\u65F6\u81EA\u52A8\u5237\u65B0\u3002"},{name:"root_id",type:"string",default:"0",required:!1,help:"\u6839\u6587\u4EF6\u5939 ID\uFF0C\u9ED8\u8BA4 0\uFF08\u6839\u76EE\u5F55\uFF09"},{name:"order_by",type:"select",options:"file_name,file_size,user_utime,file_type",default:"file_name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1},{name:"page_size",type:"number",default:"200",required:!1,help:"list api per page size (1~1150)"},{name:"limit_rate",type:"float",default:"1",required:!1,help:"limit all api request rate ([limit]r/1s)\uFF0C0 \u8868\u793A\u4E0D\u9650\u901F"}],config:{name:"115Open",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"0"}},"GitHub API":{name:"GitHub API",default_mount_path:"/github",common:ft,additional:[{name:"root_folder_path",type:"string",default:"/",required:!0},{name:"token",type:"string",default:"",required:!0},{name:"owner",type:"string",default:"",required:!0},{name:"repo",type:"string",default:"",required:!0},{name:"ref",type:"string",default:"",required:!1,help:"A branch, a tag or a commit SHA, default branch by default."},{name:"gh_proxy",type:"string",default:"",required:!1,help:"GitHub proxy, e.g. https://ghproxy.net/raw.githubusercontent.com"},{name:"committer_name",type:"string",default:"",required:!1},{name:"committer_email",type:"string",default:"",required:!1},{name:"author_name",type:"string",default:"",required:!1},{name:"author_email",type:"string",default:"",required:!1},{name:"mkdir_commit_message",type:"text",default:"{{.UserName}} mkdir {{.ObjPath}}",required:!1},{name:"delete_commit_message",type:"text",default:"{{.UserName}} remove {{.ObjPath}}",required:!1},{name:"put_commit_message",type:"text",default:"{{.UserName}} upload {{.ObjPath}}",required:!1},{name:"rename_commit_message",type:"text",default:"{{.UserName}} rename {{.ObjPath}} to {{.TargetName}}",required:!1},{name:"copy_commit_message",type:"text",default:"{{.UserName}} copy {{.ObjPath}} to {{.TargetPath}}",required:!1},{name:"move_commit_message",type:"text",default:"{{.UserName}} move {{.ObjPath}} to {{.TargetPath}}",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"GitHub API",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},Thunder:{name:"Thunder",default_mount_path:"/thunder",common:ft,additional:[{name:"root_folder_id",type:"string",default:"",required:!1},{name:"username",type:"string",default:"",required:!0},{name:"password",type:"string",default:"",required:!0},{name:"captcha_token",type:"string",default:"",required:!1},{name:"credit_key",type:"string",default:"",required:!1,help:"credit key, used for login"},{name:"device_id",type:"string",default:"",required:!1,help:"32 hex characters"},{name:"space",type:"string",default:"",required:!1,help:"device id for remote device"},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"Thunder",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:""}},ThunderExpert:{name:"ThunderExpert",default_mount_path:"/thunderexpert",common:ft,additional:[{name:"root_folder_id",type:"string",default:"",required:!1},{name:"login_type",type:"select",options:"user,refresh_token",default:"user",required:!0},{name:"sign_type",type:"select",options:"algorithms,captcha_sign",default:"algorithms",required:!0},{name:"username",type:"string",default:"",required:!1,help:"login type is user, this is required"},{name:"password",type:"string",default:"",required:!1,help:"login type is user, this is required"},{name:"refresh_token",type:"string",default:"",required:!1,help:"login type is refresh_token, this is required"},{name:"algorithms",type:"string",default:"9uJNVj/wLmdwKrJaVj/omlQ,Oz64Lp0GigmChHMf/6TNfxx7O9PyopcczMsnf,Eb+L7Ce+Ej48u,jKY0,ASr0zCl6v8W4aidjPK5KHd1Lq3t+vBFf41dqv5+fnOd,wQlozdg6r1qxh0eRmt3QgNXOvSZO6q/GXK,gmirk+ciAvIgA/cxUUCema47jr/YToixTT+Q6O,5IiCoM9B1/788ntB,P07JH0h6qoM6TSUAK2aL9T5s2QBVeY9JWvalf,+oK0AN",required:!1},{name:"captcha_sign",type:"string",default:"",required:!1},{name:"timestamp",type:"string",default:"",required:!1},{name:"captcha_token",type:"string",default:"",required:!1},{name:"credit_key",type:"string",default:"",required:!1,help:"credit key, used for login"},{name:"device_id",type:"string",default:"",required:!1},{name:"client_id",type:"string",default:"",required:!0,help:"\u8FC5\u96F7\u5F00\u653E\u5E73\u53F0 OAuth client_id\uFF08\u5FC5\u586B\uFF09\u3002"},{name:"client_secret",type:"string",default:"",required:!0,help:"\u8FC5\u96F7\u5F00\u653E\u5E73\u53F0 OAuth client_secret\uFF08\u5FC5\u586B\uFF09\u3002"},{name:"client_version",type:"string",default:"8.31.0.9726",required:!0},{name:"package_name",type:"string",default:"com.xunlei.downloadprovider",required:!0},{name:"user_agent",type:"string",default:"ANDROID-com.xunlei.downloadprovider/8.31.0.9726 netWorkType/5G appid/40 deviceName/Xiaomi_M2004j7ac deviceModel/M2004J7AC OSVersion/12 protocolVersion/301 platformVersion/10 sdkVersion/512000 Oauth2Client/0.9 (Linux 4_14_186-perf-gddfs8vbb238b) (JAVA 0)",required:!0},{name:"download_user_agent",type:"string",default:"Dalvik/2.1.0 (Linux; U; Android 12; M2004J7AC Build/SP1A.210812.016)",required:!0},{name:"use_video_url",type:"bool",default:"false",required:!1},{name:"space",type:"string",default:"",required:!1,help:"device id for remote device"},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"ThunderExpert",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:""}},"189Cloud":{name:"189Cloud",default_mount_path:"/189",common:[...Tt,Pt,Ft,Nt,...Rt("189Cloud"),Ut,Zt],additional:[{name:"username",type:"string",default:"",required:!0,help:"the phone number used to log in"},{name:"password",type:"string",default:"",required:!0,help:"password for login"},{name:"cookie",type:"text",default:"",required:!1,help:"Fill in the cookie if need captcha (\u82E5\u9047\u6ED1\u5757\u9A8C\u8BC1\u7801\u6216\u8BBE\u5907\u9501\uFF0C\u53EF\u5728\u6D4F\u89C8\u5668\u767B\u5F55\u540E\u590D\u5236 Cookie \u586B\u5165)"},{name:"root_folder_id",type:"string",default:"-11",required:!1,help:"\u6839\u6587\u4EF6\u5939ID\uFF0C\u9ED8\u8BA4\u4E3A -11\uFF08\u4E2A\u4EBA\u4E91\u6839\u76EE\u5F55\uFF09"},{name:"order_by",type:"select",options:"lastOpTime,filename,fileSize",default:"lastOpTime",required:!1},{name:"order_direction",type:"select",options:"desc,asc",default:"desc",required:!1}],config:{name:"189Cloud",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"-11"}},Lanzou:{name:"Lanzou",default_mount_path:"/lanzou",common:ft,additional:[{name:"type",type:"select",options:"cookie,account,url",default:"cookie",required:!0},{name:"account",type:"string",default:"",required:!1,help:"\u8D26\u53F7\uFF08\u624B\u673A\u53F7/UID\uFF09\uFF0C\u4EC5 account \u6A21\u5F0F\u9700\u586B\u5199"},{name:"password",type:"string",default:"",required:!1,help:"\u5BC6\u7801\uFF0C\u4EC5 account \u6A21\u5F0F\u9700\u586B\u5199"},{name:"cookie",type:"text",default:"",required:!1,help:"\u767B\u5F55 Cookie\uFF08\u542B ylogin, phpdisk_info \u7B49\uFF09\uFF0Ccookie \u6A21\u5F0F\u9700\u586B\u5199\uFF1B\u6709\u6548\u671F\u7EA6 15 \u5929"},{name:"root_folder_id",type:"string",default:"-1",required:!1,help:"\u6839\u6587\u4EF6\u5939 ID / \u5206\u4EAB ID\uFF08\u4E2A\u4EBA\u76D8\u9ED8\u8BA4 -1\uFF0C\u5206\u4EAB\u94FE\u63A5\u586B\u5206\u4EAB ID \u5982 b00xxxx\uFF09"},{name:"share_password",type:"string",default:"",required:!1,help:"\u63D0\u53D6\u7801 / \u8BBF\u95EE\u5BC6\u7801\uFF08\u65E0\u5BC6\u7801\u7559\u7A7A\uFF09"},{name:"baseUrl",type:"string",default:"https://pc.woozooo.com",required:!1,help:"\u57FA\u672C API \u57DF\u540D"},{name:"shareUrl",type:"string",default:"https://pan.lanzoui.com",required:!1,help:"\u5206\u4EAB\u9875\u9762\u89E3\u6790\u57DF\u540D"},{name:"user_agent",type:"string",default:"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Safari/537.36 Chrome/142.0.0.0 OpenList/42",required:!0,help:"\u53D1\u9001\u7ED9\u84DD\u594F\u4E91 API \u4E0E\u76F4\u94FE\u89E3\u6790\u65F6\u643A\u5E26\u7684\u5BA2\u6237\u7AEF User-Agent"},{name:"repair_file_info",type:"bool",default:"false",required:!1,help:"\u901A\u8FC7 HEAD \u8BF7\u6C42\u4FEE\u6B63\u6587\u4EF6\u7CBE\u786E\u5927\u5C0F\u4E0E\u4FEE\u6539\u65F6\u95F4\uFF08WebDAV \u63A8\u8350\u5F00\u542F\uFF09"},{name:"order_by",type:"select",options:"name,size,time",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"Lanzou",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"-1"}},WebDav:{name:"WebDav",default_mount_path:"/webdav",common:[...Tt,Pt,Ft,Nt,...Rt("WebDav"),Vc,Ut,Zt],additional:[{name:"vendor",type:"select",options:"other,sharepoint",default:"other",required:!0},{name:"address",type:"string",default:"",required:!0},{name:"username",type:"string",default:"",required:!0},{name:"password",type:"string",default:"",required:!0},{name:"root_folder_path",type:"string",default:"/",required:!1},{name:"tls_insecure_skip_verify",type:"bool",default:"false",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"WebDav",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},WoPan:{name:"WoPan",default_mount_path:"/wopan",common:ft,additional:[{name:"root_folder_id",type:"string",default:"0",required:!1},{name:"refresh_token",type:"text",default:"",required:!0},{name:"family_id",type:"string",default:"",required:!1,help:"true"},{name:"sort_rule",type:"select",options:"name_asc,name_desc,time_asc,time_desc,size_asc,size_desc",default:"name_asc",required:!1},{name:"access_token",type:"string",default:"",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"WoPan",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"0",no_overwrite_upload:!0}},S3:{name:"S3",default_mount_path:"/s3",common:ft,additional:[{name:"root_folder_path",type:"string",default:"/",required:!1},{name:"bucket",type:"string",default:"",required:!0},{name:"endpoint",type:"string",default:"",required:!0},{name:"region",type:"string",default:"",required:!1},{name:"access_key_id",type:"string",default:"",required:!0},{name:"secret_access_key",type:"string",default:"",required:!0},{name:"session_token",type:"string",default:"",required:!1},{name:"custom_host",type:"string",default:"",required:!1},{name:"enable_custom_host_presign",type:"bool",default:"false",required:!1},{name:"sign_url_expire",type:"number",default:"4",required:!1},{name:"placeholder",type:"string",default:"",required:!1},{name:"force_path_style",type:"bool",default:"false",required:!1},{name:"list_object_version",type:"select",options:"v1,v2",default:"v1",required:!1},{name:"remove_bucket",type:"bool",default:"false",required:!1,help:"true"},{name:"add_filename_to_disposition",type:"bool",default:"false",required:!1,help:"true"},{name:"enable_direct_upload",type:"bool",default:"false",required:!1},{name:"direct_upload_host",type:"string",default:"",required:!1},{name:"user_agent",type:"string",default:"",required:!1,help:"true"},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"S3",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/",check_status:!0}},Doge:{name:"Doge",default_mount_path:"/doge",common:ft,additional:[{name:"root_folder_path",type:"string",default:"/",required:!1},{name:"bucket",type:"string",default:"",required:!0},{name:"endpoint",type:"string",default:"",required:!0},{name:"region",type:"string",default:"",required:!1},{name:"access_key_id",type:"string",default:"",required:!0},{name:"secret_access_key",type:"string",default:"",required:!0},{name:"session_token",type:"string",default:"",required:!1},{name:"custom_host",type:"string",default:"",required:!1},{name:"enable_custom_host_presign",type:"bool",default:"false",required:!1},{name:"sign_url_expire",type:"number",default:"4",required:!1},{name:"placeholder",type:"string",default:"",required:!1},{name:"force_path_style",type:"bool",default:"false",required:!1},{name:"list_object_version",type:"select",options:"v1,v2",default:"v1",required:!1},{name:"remove_bucket",type:"bool",default:"false",required:!1,help:"true"},{name:"add_filename_to_disposition",type:"bool",default:"false",required:!1,help:"true"},{name:"enable_direct_upload",type:"bool",default:"false",required:!1},{name:"direct_upload_host",type:"string",default:"",required:!1},{name:"user_agent",type:"string",default:"",required:!1,help:"true"},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"Doge",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/",check_status:!0}},WeiYun:{name:"WeiYun",default_mount_path:"/weiyun",common:[...Tt,Pt,Ft,Nt,...Rt("WeiYun"),Ut,Zt],additional:[{name:"root_folder_id",type:"string",default:"",required:!1},{name:"cookies",type:"text",default:"",required:!0},{name:"order_by",type:"select",options:"name,size,updated_at",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1},{name:"upload_thread",type:"string",default:"4",required:!1,help:"4<=thread<=32"}],config:{name:"WeiYun",local_sort:!1,only_local:!1,only_proxy:!0,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"",check_status:!0}},SFTP:{name:"SFTP",default_mount_path:"/sftp",common:[...Tt,Pt,Ft,Nt,...Rt("SFTP"),Ut,Zt],additional:[{name:"address",type:"string",default:"",required:!0,help:"SSH host:port (e.g. 127.0.0.1:22)"},{name:"username",type:"string",default:"",required:!0},{name:"password",type:"string",default:"",required:!1},{name:"private_key",type:"text",default:"",required:!1},{name:"passphrase",type:"string",default:"",required:!1},{name:"root_folder_path",type:"string",default:"/",required:!1},{name:"ignore_symlink_error",type:"bool",default:"false",required:!1,help:"Ignore symlink error"}],config:{name:"SFTP",local_sort:!0,only_local:!1,only_proxy:!0,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/",check_status:!0,no_link_url:!0}},FTP:{name:"FTP",default_mount_path:"/ftp",common:[...Tt,Pt,Ft,Nt,...Rt("FTP"),Ut,Zt],additional:[{name:"address",type:"string",default:"",required:!0,help:"FTP host:port (e.g. 127.0.0.1:21)"},{name:"username",type:"string",default:"",required:!0},{name:"password",type:"string",default:"",required:!0},{name:"encoding",type:"string",default:"utf-8",required:!0,help:"Character encoding, e.g. utf-8, gbk, gb2312"},{name:"cwd_list",type:"bool",default:"false",required:!1,help:"Enter directory before listing"},{name:"root_folder_path",type:"string",default:"/",required:!1}],config:{name:"FTP",local_sort:!0,only_local:!1,only_proxy:!0,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/",check_status:!0,no_link_url:!0}},PikPak:{name:"PikPak",default_mount_path:"/pikpak",common:ft,additional:[{name:"root_folder_id",type:"string",default:"",required:!1},{name:"username",type:"string",default:"",required:!0},{name:"password",type:"string",default:"",required:!0},{name:"platform",type:"select",options:"web,android,pc",default:"web",required:!0},{name:"refresh_token",type:"text",default:"",required:!1},{name:"captcha_token",type:"text",default:"",required:!1},{name:"device_id",type:"string",default:"",required:!1},{name:"disable_media_link",type:"bool",default:"true",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"PikPak",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:""}},Seafile:{name:"Seafile",default_mount_path:"/seafile",common:ft,additional:[{name:"address",type:"string",default:"",required:!0},{name:"username",type:"string",default:"",required:!1},{name:"password",type:"string",default:"",required:!1},{name:"token",type:"string",default:"",required:!1},{name:"repo_id",type:"string",default:"",required:!1},{name:"repo_pwd",type:"string",default:"",required:!1},{name:"root_folder_path",type:"string",default:"/",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"Seafile",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},YandexDisk:{name:"YandexDisk",default_mount_path:"/yandex",common:ft,additional:[{name:"refresh_token",type:"text",default:"",required:!0},{name:"root_folder_path",type:"string",default:"/",required:!1},{name:"use_online_api",type:"bool",default:"true",required:!1},{name:"api_url_address",type:"string",default:"https://api.oplist.org/yandexui/renewapi",required:!1},{name:"client_id",type:"string",default:"",required:!1},{name:"client_secret",type:"string",default:"",required:!1},{name:"order_by",type:"select",options:"name,path,created,modified,size",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"YandexDisk",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},Terabox:{name:"Terabox",default_mount_path:"/terabox",common:[...Tt,Pt,Ft,Nt,...Rt("Terabox"),Ut,Zt],additional:[{name:"cookie",type:"text",default:"",required:!0},{name:"download_api",type:"select",options:"official,crack",default:"official",required:!1},{name:"root_folder_path",type:"string",default:"/",required:!1},{name:"order_by",type:"select",options:"name,time,size",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"Terabox",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},MediaTrack:{name:"MediaTrack",default_mount_path:"/mediatrack",common:ft,additional:[{name:"access_token",type:"text",default:"",required:!0},{name:"project_id",type:"string",default:"",required:!1},{name:"root_folder_id",type:"string",default:"",required:!1},{name:"order_by",type:"select",options:"updated_at,title,size",default:"title",required:!1},{name:"order_desc",type:"bool",default:"false",required:!1}],config:{name:"MediaTrack",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:""}},Alias:{name:"Alias",default_mount_path:"/alias",common:[...Tt,Pt,Ft,Nt,...Rt("Alias"),Vc,Ut,Zt],additional:[{name:"paths",type:"text",default:"",required:!0,help:"Newline-separated list of paths, e.g. /local or sub:/target"},{name:"read_conflict_policy",type:"select",options:"first,random,all",default:"first",required:!1},{name:"write_conflict_policy",type:"select",options:"disabled,first,deterministic,deterministic_or_all,all,all_strict",default:"disabled",required:!1},{name:"put_conflict_policy",type:"select",options:"disabled,first,deterministic,deterministic_or_all,all,all_strict,random,quota,quota_strict",default:"disabled",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"Alias",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!0,no_upload:!1,need_ms:!1,default_root:"/"}},Dropbox:{name:"Dropbox",default_mount_path:"/dropbox",common:ft,additional:[{name:"root_folder_path",type:"string",default:"/",required:!1},{name:"use_online_api",type:"bool",default:"false",required:!1},{name:"api_url_address",type:"string",default:"https://api.oplist.org/dropboxs/renewapi",required:!1},{name:"client_id",type:"string",default:"",required:!1},{name:"client_secret",type:"string",default:"",required:!1},{name:"refresh_token",type:"text",default:"",required:!0},{name:"root_namespace_id",type:"string",default:"",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"Dropbox",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},WPS:{name:"WPS",default_mount_path:"/wps",common:ft,additional:[{name:"root_folder_path",type:"string",default:"/",required:!1},{name:"cookie",type:"text",default:"",required:!0},{name:"mode",type:"select",options:"Personal,Business",default:"Personal",required:!1},{name:"custom_ua",type:"string",default:"",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"WPS",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},"139Yun":{name:"139Yun",default_mount_path:"/139",common:[...Tt,Pt,Ft,Nt,...Rt("139Yun"),Vc,Ut,Zt],additional:[{name:"authorization",type:"text",default:"",required:!0},{name:"root_folder_id",type:"string",default:"",required:!1},{name:"type",type:"select",options:"personal_new,family,group,personal,share",default:"personal_new",required:!1},{name:"link_id",type:"text",default:"",required:!1},{name:"cloud_id",type:"string",default:"",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"139Yun",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:""}},Mega_nz:{name:"Mega_nz",default_mount_path:"/mega",common:[...Tt,Pt,Ft,Nt,...Rt("Mega_nz"),Ut,Zt],additional:[{name:"email",type:"string",default:"",required:!0},{name:"password",type:"string",default:"",required:!0},{name:"two_fa_code",type:"string",default:"",required:!1},{name:"two_fa_secret",type:"string",default:"",required:!1},{name:"move_to_trash",type:"bool",default:"true",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"Mega_nz",local_sort:!0,only_local:!1,only_proxy:!0,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},"115Share":{name:"115Share",default_mount_path:"/115_share",common:ft,additional:[{name:"share_code",type:"text",default:"",required:!0},{name:"receive_code",type:"text",default:"",required:!0},{name:"cookie",type:"text",default:"",required:!1},{name:"root_folder_id",type:"string",default:"0",required:!1},{name:"page_size",type:"number",default:"1000",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"115Share",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!0,need_ms:!1,default_root:"0"}},"123PanShare":{name:"123PanShare",default_mount_path:"/123_share",common:[...Tt,Pt,Ft,Nt,...Rt("123PanShare"),Ut,Zt],additional:[{name:"sharekey",type:"string",default:"",required:!0},{name:"sharepassword",type:"string",default:"",required:!1},{name:"accesstoken",type:"text",default:"",required:!1},{name:"root_folder_id",type:"string",default:"0",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"123PanShare",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!0,need_ms:!1,default_root:"0"}},AliyundriveShare:{name:"AliyundriveShare",default_mount_path:"/aliyun_share",common:ft,additional:[{name:"share_id",type:"string",default:"",required:!0},{name:"share_pwd",type:"string",default:"",required:!1},{name:"root_folder_id",type:"string",default:"root",required:!1},{name:"order_by",type:"select",options:"name,size,updated_at,created_at",default:"name",required:!1},{name:"order_direction",type:"select",options:"ASC,DESC",default:"ASC",required:!1}],config:{name:"AliyundriveShare",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!0,need_ms:!1,default_root:"root"}},OnedriveSharelink:{name:"OnedriveSharelink",default_mount_path:"/onedrive_share",common:ft,additional:[{name:"url",type:"string",default:"",required:!0},{name:"password",type:"string",default:"",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"OnedriveSharelink",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!0,need_ms:!1,default_root:"/"}},PikPakShare:{name:"PikPakShare",default_mount_path:"/pikpak_share",common:ft,additional:[{name:"share_id",type:"string",default:"",required:!0},{name:"share_pwd",type:"string",default:"",required:!1},{name:"platform",type:"select",options:"android,web,pc",default:"web",required:!1},{name:"root_folder_id",type:"string",default:"",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"PikPakShare",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!0,need_ms:!1,default_root:""}},SMB:{name:"SMB",default_mount_path:"/smb",common:[...Tt,Pt,Ft,Nt,...Rt("SMB"),Ut,Zt],additional:[{name:"address",type:"string",default:"",required:!0},{name:"share_name",type:"string",default:"",required:!0},{name:"username",type:"string",default:"",required:!0},{name:"password",type:"string",default:"",required:!1},{name:"port",type:"number",default:"445",required:!1},{name:"root_folder_path",type:"string",default:"/",required:!1},{name:"order_by",type:"select",options:"name,size,modified",default:"name",required:!1},{name:"order_direction",type:"select",options:"asc,desc",default:"asc",required:!1}],config:{name:"SMB",local_sort:!0,only_local:!1,only_proxy:!0,no_cache:!0,no_upload:!1,need_ms:!1,default_root:"/"}},Crypt:{name:"Crypt",default_mount_path:"/crypt",common:[...Tt,Pt,Ft,Nt,...Rt("Crypt"),Ut,Zt],additional:[{name:"remote_path",type:"string",default:"",required:!0,help:"\u52A0\u5BC6\u6570\u636E\u5B9E\u9645\u5B58\u50A8\u7684\u4F4D\u7F6E\uFF08\u53E6\u4E00\u4E2A\u5DF2\u6302\u8F7D\u5B58\u50A8\u7684\u8DEF\u5F84\uFF0C\u5982 /aliyundrive/enc\uFF09"},{name:"password",type:"string",default:"",required:!0,help:"\u4E3B\u5BC6\u7801\uFF08\u7528\u4E8E\u6D3E\u751F\u52A0\u5BC6\u5BC6\u94A5\uFF09"},{name:"salt",type:"string",default:"",required:!1,help:"\u76D0\uFF08\u7B2C\u4E8C\u5BC6\u7801\uFF09\u3002\u53EF\u9009\u4F46\u63A8\u8350\uFF0C\u63D0\u9AD8\u5BC6\u94A5\u5F3A\u5EA6"},{name:"filename_encryption",type:"select",options:"off,standard,obfuscate",default:"off",required:!0,help:"\u6587\u4EF6\u540D\u52A0\u5BC6\u65B9\u5F0F\u3002\u5F53\u524D\u4EC5\u652F\u6301 off\uFF08\u6587\u4EF6\u540D\u4E0D\u52A0\u5BC6\uFF0C\u4EC5\u5185\u5BB9\u52A0\u5BC6\uFF09"},{name:"directory_name_encryption",type:"select",options:"false,true",default:"false",required:!0},{name:"encrypted_suffix",type:"string",default:".bin",required:!0,help:"\u52A0\u5BC6\u6587\u4EF6\u7684\u540E\u7F00\uFF08\u9AD8\u7EA7\u9009\u9879\uFF09"},{name:"filename_encoding",type:"select",options:"base64,base32,base32768",default:"base64",required:!0},{name:"thumbnail",type:"bool",default:"false",required:!1},{name:"show_hidden",type:"bool",default:"true",required:!1}],config:{name:"Crypt",local_sort:!0,only_local:!1,only_proxy:!0,no_cache:!0,no_upload:!1,need_ms:!1,default_root:"/",no_link_url:!0,check_status:!0}},Virtual:{name:"Virtual",default_mount_path:"/virtual",common:[...Tt,Pt,Ft,Nt,...Rt("Virtual"),Ut,Zt],additional:[{name:"num_file",type:"number",default:"30",required:!0,help:"\u6BCF\u4E2A\u76EE\u5F55\u4E0B\u751F\u6210\u7684\u5360\u4F4D\u6587\u4EF6\u6570\u91CF"},{name:"num_folder",type:"number",default:"30",required:!0,help:"\u6BCF\u4E2A\u76EE\u5F55\u4E0B\u751F\u6210\u7684\u5360\u4F4D\u76EE\u5F55\u6570\u91CF"},{name:"max_file_size",type:"number",default:"1073741824",required:!0,help:"\u5360\u4F4D\u6587\u4EF6\u6700\u5927\u5B57\u8282\u6570"},{name:"min_file_size",type:"number",default:"1048576",required:!0,help:"\u5360\u4F4D\u6587\u4EF6\u6700\u5C0F\u5B57\u8282\u6570"}],config:{name:"Virtual",local_sort:!0,only_local:!1,only_proxy:!0,no_cache:!1,no_upload:!1,need_ms:!0,default_root:"/",no_link_url:!0}},AListV3:{name:"AListV3",default_mount_path:"/alist",common:[...Tt,Pt,Ft,Nt,...Rt("AListV3"),Vc,Ut,Zt],additional:[{name:"url",type:"string",default:"",required:!0,help:"\u53E6\u4E00\u4E2A OpenList / AList \u5B9E\u4F8B\u7684\u5730\u5740\uFF0C\u5982 https://example.com"},{name:"meta_password",type:"string",default:"",required:!1},{name:"username",type:"string",default:"",required:!1},{name:"password",type:"string",default:"",required:!1},{name:"token",type:"string",default:"",required:!1,help:"\u8BBF\u95EE\u4EE4\u724C\uFF08\u53EF\u9009\uFF0C\u81EA\u52A8\u6301\u4E45\u5316\uFF0C\u65E0\u9700\u624B\u52A8\u586B\u5199\uFF09"},{name:"pass_ip_to_upsteam",type:"bool",default:"true",required:!1},{name:"pass_ua_to_upsteam",type:"bool",default:"true",required:!1},{name:"forward_archive_requests",type:"bool",default:"true",required:!1}],config:{name:"AListV3",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},UrlTree:{name:"UrlTree",default_mount_path:"/url_tree",common:ft,additional:[{name:"url_structure",type:"text",default:"",required:!0,help:"URL \u6811\u7ED3\u6784\u6587\u672C\uFF0C\u6BCF\u884C\u7F29\u8FDB 2 \u7A7A\u683C\u8868\u793A\u4E00\u7EA7\u3002\u76EE\u5F55\u884C\u4EE5 : \u7ED3\u5C3E\uFF0C\u6587\u4EF6\u884C\u683C\u5F0F [FileName:][FileSize:][Modified:]Url"},{name:"head_size",type:"bool",default:"false",required:!1,help:"\u7528 HEAD \u8BF7\u6C42\u83B7\u53D6\u6587\u4EF6\u5927\u5C0F\uFF08\u53EF\u80FD\u5931\u8D25\uFF09"},{name:"writable",type:"bool",default:"false",required:!1,help:"\u5141\u8BB8\u589E\u5220\u6539\u6587\u4EF6\u6811\uFF08\u4F1A\u6301\u4E45\u5316\u56DE url_structure\uFF09"}],config:{name:"UrlTree",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!0,no_upload:!1,need_ms:!1,default_root:"/",check_status:!0}},Strm:{name:"Strm",default_mount_path:"/strm",common:[...Tt,Pt,Ft,Nt,...Rt("Strm"),Ut,Zt],additional:[{name:"paths",type:"text",default:"",required:!0,help:"\u8DEF\u5F84\u6620\u5C04\uFF0C\u6BCF\u884C\u4E00\u4E2A\uFF1A\u865A\u62DF\u540D:\u5E95\u5C42\u8DEF\u5F84\uFF08\u5982 movies:/aliyundrive/movies\uFF09\uFF0C\u6216\u76F4\u63A5\u5E95\u5C42\u8DEF\u5F84"},{name:"siteUrl",type:"text",default:"",required:!1,help:"strm \u6587\u4EF6\u5185\u5BB9\u7684 URL \u524D\u7F00\uFF08\u7559\u7A7A\u5219\u7528\u76F8\u5BF9\u8DEF\u5F84\uFF09"},{name:"PathPrefix",type:"text",default:"/d",required:!1,help:"\u4E0B\u8F7D\u8DEF\u5F84\u524D\u7F00"},{name:"downloadFileTypes",type:"text",default:"ass,srt,vtt,sub,strm",required:!1,help:"\u9700\u539F\u6837\u4E0B\u8F7D\u7684\u6587\u4EF6\u6269\u5C55\u540D\uFF08\u901A\u5E38\u4E3A\u5B57\u5E55\uFF09"},{name:"filterFileTypes",type:"text",default:"mp4,mkv,flv,avi,wmv,ts,rmvb,webm,mp3,flac,aac,wav,ogg,m4a,wma,alac",required:!1,help:"\u652F\u6301\u751F\u6210 strm \u7684\u6587\u4EF6\u6269\u5C55\u540D\uFF08\u89C6\u9891/\u97F3\u9891\uFF09"},{name:"encodePath",type:"bool",default:"true",required:!1},{name:"withoutUrl",type:"bool",default:"false",required:!1},{name:"withSign",type:"bool",default:"false",required:!1}],config:{name:"Strm",local_sort:!0,only_local:!1,only_proxy:!0,no_cache:!0,no_upload:!0,need_ms:!1,default_root:"/",no_link_url:!0}},AzureBlob:{name:"AzureBlob",default_mount_path:"/azure",common:ft,additional:[{name:"endpoint",type:"string",default:"",required:!0,help:"Azure \u5B58\u50A8\u7AEF\u70B9\uFF0C\u5982 https://accountname.blob.core.windows.net/"},{name:"access_key",type:"string",default:"",required:!0,help:"Azure \u5B58\u50A8\u8BBF\u95EE\u5BC6\u94A5\uFF08Base64\uFF09"},{name:"container_name",type:"string",default:"",required:!0,help:"\u5BB9\u5668\u540D\u79F0"},{name:"sign_url_expire",type:"number",default:"4",required:!1,help:"SAS URL \u6709\u6548\u671F\uFF08\u5C0F\u65F6\uFF09"}],config:{name:"AzureBlob",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/",check_status:!0}},USS:{name:"USS",default_mount_path:"/uss",common:ft,additional:[{name:"bucket",type:"string",default:"",required:!0},{name:"endpoint",type:"string",default:"",required:!0,help:"\u4E0B\u8F7D\u57DF\u540D\uFF08\u53EF\u542B\u534F\u8BAE\u5934\uFF09"},{name:"operator_name",type:"string",default:"",required:!0},{name:"operator_password",type:"string",default:"",required:!0},{name:"anti_theft_chain_token",type:"string",default:"",required:!1,help:"\u9632\u76D7\u94FE Token\uFF08\u7559\u7A7A\u5219\u7528\u64CD\u4F5C\u5458\u5BC6\u7801\uFF09"},{name:"sign_url_expire",type:"number",default:"4",required:!1,help:"\u94FE\u63A5\u6709\u6548\u671F\uFF08\u5C0F\u65F6\uFF09"}],config:{name:"USS",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},Alidoc:{name:"Alidoc",default_mount_path:"/alidoc",common:ft,additional:[{name:"cookie",type:"text",default:"",required:!0,help:"\u9489\u9489\u6587\u6863\u7F51\u9875 Cookie"},{name:"root_folder_id",type:"string",default:"",required:!0,help:"\u6839\u76EE\u5F55 dentryUuid"}],config:{name:"Alidoc",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!0,need_ms:!1,default_root:""}},Emby:{name:"Emby",default_mount_path:"/emby",common:ft,additional:[{name:"url",type:"string",default:"",required:!0,help:"Emby \u670D\u52A1\u5668\u5730\u5740\uFF0C\u5982 http://localhost:8096"},{name:"api_key",type:"string",default:"",required:!1},{name:"user_id",type:"string",default:"",required:!1},{name:"username",type:"string",default:"",required:!1},{name:"password",type:"string",default:"",required:!1},{name:"link_method",type:"select",options:"stream,download",default:"stream",required:!1},{name:"root_folder_id",type:"string",default:"1",required:!1,help:"\u6839\u76EE\u5F55 ID\uFF0C\u9ED8\u8BA4 1"}],config:{name:"Emby",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!0,need_ms:!1,default_root:"1"}},BunnyStorage:{name:"BunnyStorage",default_mount_path:"/bunny",common:ft,additional:[{name:"storage_zone_name",type:"string",default:"",required:!0},{name:"access_key",type:"string",default:"",required:!0},{name:"endpoint",type:"string",default:"storage.bunnycdn.com",required:!1},{name:"cdn_base_url",type:"string",default:"",required:!1},{name:"cdn_token_key",type:"string",default:"",required:!1},{name:"cdn_token_method",type:"select",options:"sha256,hmac_sha256",default:"sha256",required:!1},{name:"cdn_token_include_ip",type:"bool",default:"false",required:!1},{name:"sign_url_expire",type:"number",default:"4",required:!1,help:"\u94FE\u63A5\u6709\u6548\u671F\uFF08\u5C0F\u65F6\uFF09"},{name:"placeholder",type:"string",default:".openlist",required:!1},{name:"root_folder_path",type:"string",default:"/",required:!0}],config:{name:"BunnyStorage",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},CloudflareImgbed:{name:"CloudflareImgbed",default_mount_path:"/cfimgbed",common:ft,additional:[{name:"address",type:"string",default:"",required:!0,help:"\u56FE\u5E8A\u670D\u52A1\u5730\u5740"},{name:"token",type:"string",default:"",required:!0},{name:"small_channel_name",type:"string",default:"",required:!1},{name:"large_channel_name",type:"string",default:"",required:!1},{name:"large_channel_type",type:"string",default:"",required:!1},{name:"upload_thread",type:"number",default:"3",required:!1},{name:"root_folder_path",type:"string",default:"/",required:!0}],config:{name:"CloudflareImgbed",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},GuangYaPan:{name:"GuangYaPan",default_mount_path:"/guangyapan",common:ft,additional:[{name:"client_id",type:"string",default:"",required:!0},{name:"device_id",type:"string",default:"",required:!1},{name:"device_sign",type:"string",default:"",required:!1},{name:"access_token",type:"text",default:"",required:!1},{name:"refresh_token",type:"text",default:"",required:!1},{name:"phone_number",type:"string",default:"",required:!1,help:"\u624B\u673A\u53F7\uFF08\u767B\u5F55\u7528\uFF0C+86 \u683C\u5F0F\uFF09"},{name:"verify_code",type:"string",default:"",required:!1},{name:"page_size",type:"number",default:"100",required:!1},{name:"order_by",type:"number",default:"3",required:!1},{name:"sort_type",type:"number",default:"1",required:!1},{name:"root_folder_path",type:"string",default:"/",required:!0}],config:{name:"GuangYaPan",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!1,need_ms:!1,default_root:"/"}},AutoIndex:{name:"AutoIndex",default_mount_path:"/autoindex",common:ft,additional:[{name:"url",type:"string",default:"",required:!0,help:"AutoIndex \u76EE\u5F55\u9875 URL"},{name:"item_xpath",type:"string",default:"//pre/a",required:!0},{name:"name_xpath",type:"string",default:"@href",required:!0},{name:"modified_xpath",type:"string",default:"string(following-sibling::text()[2])",required:!1},{name:"size_xpath",type:"string",default:"string(following-sibling::text()[1])",required:!1},{name:"ignore_file_names",type:"text",default:`.
|
|
273
273
|
..
|
|
274
274
|
Parent Directory
|
|
275
275
|
Up`,required:!1},{name:"modified_time_format",type:"string",default:"02-Jan-2006 15:04",required:!1}],config:{name:"AutoIndex",local_sort:!0,only_local:!1,only_proxy:!1,no_cache:!1,no_upload:!0,need_ms:!1,default_root:""}},ProtonDrive:{name:"ProtonDrive",default_mount_path:"/proton",common:[...Tt,Pt,Ft,Nt,...Rt("ProtonDrive"),Ut,Zt],additional:[{name:"email",type:"string",default:"",required:!0,help:"Proton \u8D26\u53F7\u90AE\u7BB1"},{name:"password",type:"string",default:"",required:!0,help:"Proton \u8D26\u53F7\u5BC6\u7801"},{name:"two_fa_code",type:"string",default:"",required:!1,help:"\u4E24\u6B65\u9A8C\u8BC1\u7801\uFF08\u5982\u5DF2\u542F\u7528 2FA\uFF09"},{name:"root_folder_id",type:"string",default:"root",required:!1,help:"\u6839\u6587\u4EF6\u5939 LinkID\uFF0C\u9ED8\u8BA4 root \u8868\u793A\u4E3B\u5171\u4EAB\u6839\u76EE\u5F55"},{name:"chunk_size",type:"number",default:"4",required:!1,help:"\u5206\u5757\u5927\u5C0F\uFF08MB\uFF09"},{name:"use_reusable_login",type:"bool",default:"true",required:!1}],config:{name:"ProtonDrive",local_sort:!0,only_local:!1,only_proxy:!0,no_cache:!1,no_upload:!0,need_ms:!1,default_root:"root"}}};Fe.get("/driver/list",t=>t.json({code:200,message:"success",data:Vl}));Fe.get("/driver/info",t=>{let e=t.req.query("driver")||"",r=Vl[e]||Vl.AliyundriveOpen;return t.json({code:200,message:"success",data:r})});Fe.get("/setting/list",async t=>{let e=await se(t.env),r=t.req.query("group"),i=t.req.query("groups"),n=e.settings||[];if(r!==void 0){let s=parseInt(r,10);n=n.filter(a=>a.group===s)}else if(i!==void 0){let s=i.split(",").map(a=>parseInt(a,10));n=n.filter(a=>s.includes(a.group))}return t.json({code:200,message:"success",data:n})});Fe.post("/setting/save",async t=>{let e=await t.req.json().catch(()=>[]);if(!Array.isArray(e))return t.json({code:400,message:"body must be an array",data:null});let r=await se(t.env);r.settings||(r.settings=[]);for(let n of e){if(!n||typeof n!="object"||Array.isArray(n))continue;let s=n.key;if(typeof s!="string"||s.length===0||s.length>128)continue;let a=n.value;a!==null&&typeof a=="object"&&(a=JSON.stringify(a));let o=r.settings.findIndex(c=>c.key===s);o!==-1?(r.settings[o].value=a,typeof n.group=="number"&&(r.settings[o].group=n.group)):r.settings.push({key:s,value:a,type:typeof n.type=="string"?n.type:"string",help:typeof n.help=="string"?n.help:"",group:typeof n.group=="number"?n.group:0,flag:typeof n.flag=="number"?n.flag:0})}let i=new Set;return r.settings=r.settings.filter(n=>!n.key||i.has(n.key)?!1:(i.add(n.key),!0)),await de(r,t.env),t.executionCtx?t.executionCtx.waitUntil(K4(t)):await K4(t).catch(()=>{}),t.json({code:200,message:"success",data:null})});Fe.post("/setting/default",async t=>{let e=t.req.query("group");if(e===void 0)return t.json({code:400,message:"group is required",data:null});let r=parseInt(e,10),i=await se(t.env);i.settings=(i.settings||[]).filter(a=>a.group!==r);let n=Vo.settings.filter(a=>a.group===r),s=new Set(n.map(a=>a.key));return i.settings=i.settings.filter(a=>!s.has(a.key)),i.settings.push(...JSON.parse(JSON.stringify(n))),await de(i,t.env),t.json({code:200,message:"success",data:n})});Fe.post("/setting/delete",async t=>{let e=t.req.query("key");if(!e)return t.json({code:400,message:"key is required",data:null});let r=await se(t.env);return r.settings=(r.settings||[]).filter(i=>i.key!==e),await de(r,t.env),t.json({code:200,message:"success",data:null})});var la=async(t,e,r=14)=>{let i=await se(t);i.settings||(i.settings=[]);for(let[n,s]of Object.entries(e)){if(s===void 0)continue;let a=i.settings.findIndex(o=>o.key===n);a!==-1?i.settings[a].value=s:i.settings.push({key:n,value:s,type:"string",help:n,group:r,flag:0})}await de(i,t)};Fe.post("/setting/set_115",async t=>{let e=await t.req.json().catch(()=>({}));return await la(t.env,{"115_temp_dir":e.temp_dir||""}),t.json({code:200,message:"success",data:"success"})});Fe.post("/setting/set_115_open",async t=>{let e=await t.req.json().catch(()=>({}));return await la(t.env,{"115_open_temp_dir":e.temp_dir||""}),t.json({code:200,message:"success",data:"success"})});Fe.post("/setting/set_123_pan",async t=>{let e=await t.req.json().catch(()=>({}));return await la(t.env,{"123_pan_temp_dir":e.temp_dir||"","123_temp_dir":e.temp_dir||""}),t.json({code:200,message:"success",data:"success"})});Fe.post("/setting/set_123_open",async t=>{let e=await t.req.json().catch(()=>({}));return await la(t.env,{"123_open_temp_dir":e.temp_dir||"","123_open_callback_url":e.callback_url||""}),t.json({code:200,message:"success",data:"success"})});Fe.post("/setting/set_pikpak",async t=>{let e=await t.req.json().catch(()=>({}));return await la(t.env,{pikpak_temp_dir:e.temp_dir||""}),t.json({code:200,message:"success",data:"success"})});Fe.post("/setting/set_thunder",async t=>{let e=await t.req.json().catch(()=>({}));return await la(t.env,{thunder_temp_dir:e.temp_dir||""}),t.json({code:200,message:"success",data:"success"})});Fe.post("/setting/set_thunder_browser",async t=>{let e=await t.req.json().catch(()=>({}));return await la(t.env,{thunder_browser_temp_dir:e.temp_dir||""}),t.json({code:200,message:"success",data:"success"})});Fe.post("/setting/set_thunderx",async t=>{let e=await t.req.json().catch(()=>({}));return await la(t.env,{thunderx_temp_dir:e.temp_dir||""}),t.json({code:200,message:"success",data:"success"})});Fe.post("/setting/reset_token",async t=>{let e=Qae(32);await la(t.env,{token:e});let{resetJwtSecretCache:r}=await Promise.resolve().then(()=>(bi(),f1));return r(),t.json({code:200,message:"success",data:e})});Fe.get("/meta/list",async t=>{let r=(await se(t.env)).metas||[];return t.json({code:200,message:"success",data:{content:r,total:r.length}})});Fe.get("/meta/get",async t=>{let e=parseInt(t.req.query("id")||"0",10),i=((await se(t.env)).metas||[]).find(n=>n.id===e);return i?t.json({code:200,message:"success",data:i}):t.json({code:404,message:"meta not found",data:null})});Fe.post("/meta/create",async t=>{let e=await t.req.json().catch(()=>({})),r=await se(t.env);r.metas||(r.metas=[]);let i="/"+String(e.path||"").split("/").filter(Boolean).join("/");if(!i||i==="/")return t.json({code:400,message:"path is required",data:null});if(r.metas.some(a=>a.path===i))return t.json({code:400,message:"meta already exists",data:null});let n=String(e.hide||"");if(n){let a=bb(n);if(a)return t.json({code:400,message:`invalid hide regex: ${a}`,data:null},400)}let s={id:r.metas.length?Math.max(...r.metas.map(a=>a.id))+1:1,path:i,password:e.password||"",read_users:e.read_users||[],read_users_sub:!!e.read_users_sub,write_users:e.write_users||[],write_users_sub:!!e.write_users_sub,p_sub:!!e.p_sub,write:!!e.write,w_sub:!!e.w_sub,hide:n,h_sub:!!e.h_sub,readme:e.readme||"",r_sub:!!e.r_sub,header:e.header||"",header_sub:!!e.header_sub};return r.metas.push(s),await de(r,t.env),t.json({code:200,message:"success",data:s})});Fe.post("/meta/update",async t=>{let e=await t.req.json().catch(()=>({})),r=await se(t.env);r.metas||(r.metas=[]);let i=r.metas.findIndex(a=>a.id===e.id);if(i===-1)return t.json({code:404,message:"meta not found",data:null});let n=e.path!==void 0?"/"+String(e.path).split("/").filter(Boolean).join("/"):r.metas[i].path;if(n&&r.metas.some(a=>a.path===n&&a.id!==e.id))return t.json({code:400,message:"meta already exists",data:null});let s=e.hide!==void 0?String(e.hide):r.metas[i].hide;if(s){let a=bb(s);if(a)return t.json({code:400,message:`invalid hide regex: ${a}`,data:null},400)}return r.metas[i]={...r.metas[i],...n?{path:n}:{},password:e.password!==void 0?e.password:r.metas[i].password,read_users:e.read_users!==void 0?e.read_users:r.metas[i].read_users,read_users_sub:e.read_users_sub!==void 0?!!e.read_users_sub:r.metas[i].read_users_sub,write_users:e.write_users!==void 0?e.write_users:r.metas[i].write_users,write_users_sub:e.write_users_sub!==void 0?!!e.write_users_sub:r.metas[i].write_users_sub,p_sub:e.p_sub!==void 0?!!e.p_sub:r.metas[i].p_sub,write:e.write!==void 0?!!e.write:r.metas[i].write,w_sub:e.w_sub!==void 0?!!e.w_sub:r.metas[i].w_sub,hide:e.hide!==void 0?e.hide:r.metas[i].hide,h_sub:e.h_sub!==void 0?!!e.h_sub:r.metas[i].h_sub,readme:e.readme!==void 0?e.readme:r.metas[i].readme,r_sub:e.r_sub!==void 0?!!e.r_sub:r.metas[i].r_sub,header:e.header!==void 0?e.header:r.metas[i].header,header_sub:e.header_sub!==void 0?!!e.header_sub:r.metas[i].header_sub},await de(r,t.env),t.json({code:200,message:"success",data:null})});Fe.post("/meta/delete",async t=>{let e=parseInt(t.req.query("id")||"0",10),r=await se(t.env);return r.metas||(r.metas=[]),r.metas=r.metas.filter(i=>i.id!==e),await de(r,t.env),t.json({code:200,message:"success",data:null})});Fe.route("/user",Tn);Fe.get("/kv/status",async t=>{let[e,r]=await Promise.all([lu(t.env),Mn(t.env)]);return t.json({code:200,message:"success",data:{...e,store:r}})});function Yh(t){let e=t.search_index||{};return{obj_count:e.total??0,is_done:e.is_done!==!1,last_done_time:e.updated_at||null,error:e.error||""}}Fe.post("/index/build",async t=>{try{let e=await se(t.env),r=await _l({parent:"/",keywords:"",max_depth:20,max_results:2e3},t.env);return e.search_index={items:r.content,total:r.total,is_done:!0,updated_at:new Date().toISOString(),error:""},await de(e,t.env),t.json({code:200,message:"success",data:Yh(e)})}catch(e){return t.json({code:500,message:Pe(e),data:null},500)}});Fe.post("/index/update",async t=>{try{let e=await t.req.json().catch(()=>({})),r=Array.isArray(e.paths)?e.paths:["/"],i=Math.min(20,Math.max(0,Number(e.max_depth)||20)),n=await se(t.env),a=(n.search_index?.items||[]).filter(c=>!r.some(u=>(c.parent||"/").startsWith(u))),o=await _l({parent:"/",keywords:"",max_depth:i,max_results:2e3},t.env);return n.search_index={items:[...a,...o.content],total:a.length+o.total,is_done:!0,updated_at:new Date().toISOString(),error:""},await de(n,t.env),t.json({code:200,message:"success",data:Yh(n)})}catch(e){return t.json({code:500,message:Pe(e),data:null},500)}});Fe.post("/index/stop",async t=>{let e=await se(t.env);return e.search_index&&(e.search_index.is_done=!0),await de(e,t.env),t.json({code:200,message:"success",data:Yh(e)})});Fe.post("/index/clear",async t=>{let e=await se(t.env);return e.search_index={items:[],total:0,is_done:!0,updated_at:new Date().toISOString(),error:""},await de(e,t.env),t.json({code:200,message:"success",data:Yh(e)})});Fe.get("/index/progress",async t=>{let e=await se(t.env);return t.json({code:200,message:"success",data:Yh(e)})});Fe.post("/scan/start",async t=>{try{let e=await se(t.env),r=await _l({parent:"/",keywords:"",max_depth:20,max_results:2e3},t.env);return e.scan_result={items:r.content,total:r.total,is_done:!0,updated_at:new Date().toISOString(),error:""},await de(e,t.env),t.json({code:200,message:"success",data:{obj_count:r.total,is_done:!0,last_done_time:e.scan_result.updated_at,error:""}})}catch(e){return t.json({code:500,message:Pe(e),data:null},500)}});Fe.post("/scan/stop",async t=>t.json({code:200,message:"success",data:{obj_count:0,is_done:!0,last_done_time:null,error:""}}));Fe.get("/scan/progress",async t=>{let r=(await se(t.env)).scan_result||{};return t.json({code:200,message:"success",data:{obj_count:r.total??0,is_done:r.is_done!==!1,last_done_time:r.updated_at||null,error:r.error||""}})});Fe.get("/plugin/list",async t=>{let e=await se(t.env);return e.plugins||(e.plugins=[]),t.json({code:200,message:"success",data:{content:e.plugins,total:e.plugins.length}})});Fe.get("/plugin/get",async t=>{let e=t.req.query("id");if(!e)return t.json({code:400,message:"id is required",data:null});let r=await se(t.env);r.plugins||(r.plugins=[]);let i=r.plugins.find(n=>n.id===e);return i?t.json({code:200,message:"success",data:i}):t.json({code:404,message:"Plugin not found",data:null})});Fe.post("/plugin/install",async t=>{try{let e=await t.req.json(),r=e;if(e.manifest_url&&typeof e.manifest_url=="string")try{let o=await fetch(e.manifest_url);if(!o.ok)return t.json({code:400,message:`Failed to fetch plugin manifest from URL: HTTP ${o.status}`,data:null});r={...await o.json(),...e}}catch(o){return t.json({code:400,message:`Network error fetching plugin manifest: ${Pe(o,"unexpected network error")}`,data:null})}if(!r.id||!r.name)return t.json({code:400,message:"Plugin id and name are required",data:null});let i=await se(t.env);i.plugins||(i.plugins=[]);let n=i.plugins.findIndex(o=>o.id===r.id),s=new Date().toISOString(),a={id:r.id,name:r.name,version:r.version||"1.0.0",description:r.description||"",author:r.author||"Unknown",homepage:r.homepage||"",repository:r.repository||"",icon:r.icon||"",type:r.type||"ui",enabled:r.enabled!==void 0?!!r.enabled:!0,high_privilege:!!r.high_privilege,permissions:Array.isArray(r.permissions)?r.permissions:[],entry_url:r.entry_url||"",script_content:r.script_content||"",style_content:r.style_content||"",config_schema:r.config_schema||[],config_values:r.config_values||r.default_config||{},target_hooks:r.target_hooks||["global"],is_builtin:!!r.is_builtin,tags:r.tags||[],created_at:n>=0?i.plugins[n].created_at:s,updated_at:s};return n>=0?i.plugins[n]=a:i.plugins.push(a),await de(i,t.env),t.json({code:200,message:"Plugin installed successfully",data:a})}catch(e){return t.json({code:500,message:e.message||"Failed to install plugin",data:null})}});Fe.post("/plugin/update",async t=>{try{let e=await t.req.json();if(!e.id)return t.json({code:400,message:"Plugin id is required",data:null});let r=await se(t.env);r.plugins||(r.plugins=[]);let i=r.plugins.findIndex(a=>a.id===e.id);if(i===-1)return t.json({code:404,message:"Plugin not found",data:null});let n=r.plugins[i],s={...n,...e,id:n.id,updated_at:new Date().toISOString()};return r.plugins[i]=s,await de(r,t.env),t.json({code:200,message:"Plugin updated successfully",data:s})}catch(e){return t.json({code:500,message:e.message||"Failed to update plugin",data:null})}});Fe.post("/plugin/toggle",async t=>{try{let e=await t.req.json();if(!e.id)return t.json({code:400,message:"Plugin id is required",data:null});let r=await se(t.env);r.plugins||(r.plugins=[]);let i=r.plugins.findIndex(s=>s.id===e.id);if(i===-1)return t.json({code:404,message:"Plugin not found",data:null});let n=e.enabled!==void 0?!!e.enabled:!r.plugins[i].enabled;return r.plugins[i].enabled=n,r.plugins[i].updated_at=new Date().toISOString(),await de(r,t.env),t.json({code:200,message:n?"Plugin enabled":"Plugin disabled",data:{id:e.id,enabled:n}})}catch(e){return t.json({code:500,message:e.message||"Failed to toggle plugin",data:null})}});Fe.post("/plugin/delete",async t=>{try{let r=t.req.query("id");if(!r)try{r=(await t.req.json()).id}catch{}if(!r)return t.json({code:400,message:"Plugin id is required",data:null});let i=await se(t.env);i.plugins||(i.plugins=[]);let n=i.plugins.length;return i.plugins=i.plugins.filter(s=>s.id!==r),i.plugins.length===n?t.json({code:404,message:"Plugin not found",data:null}):(await de(i,t.env),t.json({code:200,message:"Plugin deleted successfully",data:null}))}catch(e){return t.json({code:500,message:e.message||"Failed to delete plugin",data:null})}});Fe.post("/plugin/batch_save",async t=>{try{let e=await t.req.json(),r=Array.isArray(e)?e:e.plugins;if(!Array.isArray(r))return t.json({code:400,message:"plugins array is required",data:null});let i=await se(t.env);return i.plugins=r,await de(i,t.env),t.json({code:200,message:"Plugins saved successfully",data:{count:r.length}})}catch(e){return t.json({code:500,message:e.message||"Failed to batch save plugins",data:null})}});var SL=[];Fe.post("/message/send",async t=>{let r=(await t.req.json().catch(()=>({})))?.message;return r==null||r===""?t.json({code:400,message:"message is required",data:null},400):(SL.push(String(r)),t.json({code:200,message:"success",data:null}))});Fe.post("/message/get",t=>{let e=SL.shift();return e===void 0?t.json({code:404,message:"no message",data:null},404):t.json({code:200,message:"success",data:e})});Fe.get("/audit/logs",async t=>{try{let{queryAuditLogs:e}=await Promise.resolve().then(()=>(kh(),xh)),r=t.req.query("username"),i=t.req.query("action"),n=t.req.query("method"),s=t.req.query("status"),a=t.req.query("start_date"),o=t.req.query("end_date"),c=parseInt(t.req.query("limit")||"100",10),u=e({username:r,action:i,method:n,status:s,startDate:a,endDate:o,limit:Math.min(c,1e3)});return t.json({code:200,message:"success",data:{content:u,total:u.length}})}catch(e){return t.json({code:500,message:e.message||"Failed to query audit logs",data:null},500)}});Fe.get("/audit/stats",async t=>{try{let{getAuditStats:e}=await Promise.resolve().then(()=>(kh(),xh)),r=e();return t.json({code:200,message:"success",data:r})}catch(e){return t.json({code:500,message:e.message||"Failed to get audit stats",data:null},500)}});Fe.post("/audit/cleanup",async t=>{try{let e=await t.req.json().catch(()=>({})),r=parseInt(e.retention_days||"30",10),{cleanupExpiredLogs:i}=await Promise.resolve().then(()=>(kh(),xh));return i(r),t.json({code:200,message:`Cleaned up logs older than ${r} days`,data:null})}catch(e){return t.json({code:500,message:e.message||"Failed to cleanup logs",data:null},500)}});nr();Ye();Ye();function $h(t,e){let r=t.replace(/bytes=/,"").split("-"),i=parseInt(r[0],10),n=r[1]?parseInt(r[1],10):e-1,s=n-i+1;return{start:i,end:n,chunksize:s}}Yt();Co();Au();Zo();xd();vd();xd();var Pae="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36";function vL(t){let e=Fae(t.ignoreHeaders),r={...t.rawUrlHeaders||{}};return!r["User-Agent"]&&!e.has("user-agent")&&(r["User-Agent"]=Pae),t.proxyRange&&t.rangeHeader&&!e.has("range")&&(r.Range=t.rangeHeader),r}function Fae(t){let e=Array.isArray(t)?t.join(","):t;return new Set(String(e??"").split(",").map(r=>r.trim().toLowerCase()).filter(Boolean))}function xL(t,e){return t.Range?e.status===412||e.status===200&&!e.headers.get("content-range"):!1}var Nae={pdf:"application/pdf",mp4:"video/mp4",webm:"video/webm",mkv:"video/x-matroska",mp3:"audio/mpeg",flac:"audio/flac",m3u8:"application/vnd.apple.mpegurl",ts:"video/mp2t",png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml"};function kL(t){let e=t.split(".").pop()?.toLowerCase()||"";return Nae[e]||"application/octet-stream"}function _L(t){return t.replace(/[\r\n\u0000-\u001f]+/g,"")}var Rae=6*1024*1024,Uae=(t,e)=>{let i=(t?.env||{})[e];if(i!=null)return String(i);if(typeof process<"u"&&process.env){let n=process.env[e];if(n!=null)return String(n)}return""};function Oae(t){let e=typeof globalThis<"u"?globalThis:{},r=t?.env||{},i=typeof process<"u"?process.env||{}:{};return!!(r.EDGEONE||r.EO_REGION||r.EDGEONE_BLOB||e.EDGEONE_BLOB||typeof e.EdgeOne<"u"||r.TENCENTCLOUD_SCF_FUNCTIONNAME||i.TENCENTCLOUD_SCF_FUNCTIONNAME)}function hs(t){let e=Uae(t,"RAW_PROXY_MAX_BYTES").trim();if(e!==""){let r=parseInt(e,10);if(Number.isFinite(r)&&r>=0)return r}return Oae(t)?Rae:0}function sw(t,e,r){if(!Number.isFinite(r)||r<=0||!Number.isFinite(t)||t<=0)return!1;if(e)try{return $h(e,t).chunksize>r}catch{return!1}return t>r}var Mae=new Set(["authorization","cookie"]);function Lae(t){return t?Object.keys(t).some(e=>Mae.has(e.trim().toLowerCase())):!1}function QL(t,e,r){return qf(r,t)||Lae(e)}function TL(t){if(!t)return 0;let e=parseInt(t.get("content-length")||"",10);if(Number.isFinite(e)&&e>0)return e;let r=t.get("content-range")||"",i=/bytes\s+(\d+)-(\d+)\/(\d+|\*)/i.exec(r);if(i){let n=parseInt(i[1],10),s=parseInt(i[2],10);if(Number.isFinite(n)&&Number.isFinite(s)&&s>=n)return s-n+1}return 0}function z4(t){return sw(t.size,t.range,t.payloadLimit)?t.authBound?"too-large":"redirect":"proxy"}var ow=null,aw=null;async function qae(){if(typeof process<"u"&&process.release?.name==="node"&&!ow)try{ow=await import("fs/promises"),aw=(await Promise.resolve().then(()=>(dn(),ms))).createReadStream}catch{}}var gs=new je,Hae=t=>{try{let e=t.executionCtx;return!e||typeof e.waitUntil!="function"?void 0:{waitUntil:r=>e.waitUntil(r)}}catch{return}},Kae=new Set(["range","user-agent","accept","accept-language","referer"]);async function PL(t,e,r){let n=t,s=e;for(let a=0;a<5;a++){try{Rr(n,"Proxy download",r)}catch(u){throw new Error(u?.message||"SSRF blocked: restricted destination")}let o=await fetch(n,{headers:s,redirect:"manual"}),c=o.headers.get("location");if(o.status>=300&&o.status<400&&c){n=new URL(c,n).toString();let u={};for(let[l,d]of Object.entries(s))Kae.has(l.toLowerCase())&&d&&(u[l]=d);s=u;continue}return o}throw new Error("Proxy download blocked: too many redirects")}function cw(t,e,r){let i=hs(t);return`\u6587\u4EF6\u8FC7\u5927\uFF0C\u5F53\u524D\u90E8\u7F72\u5E73\u53F0\u65E0\u6CD5\u4EE3\u7406\u4E0B\u8F7D\uFF08${r} \u5B57\u8282 > \u4E0A\u9650 ${i} \u5B57\u8282 \u2248 ${(s=>Math.floor(s/1024/1024))(i)} MiB\uFF09\u3002\u5F53\u524D\u8FD0\u884C\u73AF\u5883\u5BF9\u51FD\u6570\u5355\u6B21\u8BF7\u6C42/\u54CD\u5E94 body \u6709\u786C\u4E0A\u9650\uFF08EdgeOne \u4E91\u51FD\u6570\u4E3A 6 MiB\uFF0C\u9519\u8BEF\u7801 CLOUD_FUNCTION_PAYLOAD_TOO_LARGE / HTTP 413\uFF09\uFF0C${e} \u65E0\u6CD5\u63D0\u4F9B\u53EF\u76F4\u8FDE\u7684\u4E0B\u8F7D\u94FE\u63A5\uFF08\u6216\u76F4\u94FE\u5FC5\u987B\u643A\u5E26\u79C1\u6709\u9274\u6743\u5934\uFF09\uFF0C\u53EA\u80FD\u7ECF\u670D\u52A1\u7AEF\u8F6C\u53D1\uFF0C\u56E0\u6B64\u65E0\u6CD5\u7ED5\u8FC7\u8BE5\u4E0A\u9650\u3002\u5EFA\u8BAE\uFF1A\u6539\u7528\u8FD4\u56DE\u516C\u5F00\u76F4\u94FE\u7684\u5B58\u50A8\u3001\u6216\u5728\u81EA\u6258\u7BA1\u73AF\u5883\uFF08Docker / Node\uFF09\u90E8\u7F72\uFF1B\u786E\u9700\u653E\u5F00\u9650\u5236\u53EF\u8BBE\u7F6E RAW_PROXY_MAX_BYTES=0\uFF08\u6216\u6309\u5E73\u53F0\u5B9E\u9645\u4E0A\u9650\u8C03\u6574\u8BE5\u503C\uFF09\u3002`}async function FL(t,e,r,i,n={}){let s=n.proxyRange??!1,a=n.driver??"",o=QL(a,e.raw_url_headers,n.storage),c=z4({size:Number(e.size)||0,range:s?t.req.header("Range"):void 0,payloadLimit:hs(t),authBound:o});if(c==="redirect"){try{Rr(e.raw_url,"Redirect download",i)}catch(b){return t.text(b.message||"SSRF blocked",403)}return console.warn(`[rawRouter] Falling back to 302 direct link for '${r}': ${e.size} bytes exceeds the ${hs(t)}-byte payload limit of this runtime \u2014 native proxy would hit CLOUD_FUNCTION_PAYLOAD_TOO_LARGE`),t.redirect(e.raw_url,302)}if(c==="too-large")return console.warn(`[rawRouter] Refusing to proxy '${r}': ${e.size} bytes exceeds the ${hs(t)}-byte payload limit of this runtime and no direct link can be handed to the browser (driver=${a}, authBound=${o})`),t.json({code:413,message:cw(t,a||"\u8BE5\u5B58\u50A8",Number(e.size)||0),data:null},413);let u=vL({rawUrlHeaders:e.raw_url_headers,rangeHeader:t.req.header("Range"),proxyRange:s,ignoreHeaders:n.ignoreHeaders}),l;try{l=await PL(e.raw_url,u,i)}catch(b){return t.text(b.message||"SSRF blocked",403)}xL(u,l)&&(console.warn(`[rawRouter] Upstream ignored/refused Range (status=${l.status}) for '${r}', retrying without Range header...`),delete u.Range,l=await PL(e.raw_url,u,i));let d=TL(l.headers),A=z4({size:d,payloadLimit:hs(t),authBound:o});if(A!=="proxy"){try{await l.body?.cancel()}catch{}if(console.warn(`[rawRouter] Upstream body is ${d} bytes after Range negotiation (status=${l.status}) for '${r}', which exceeds the ${hs(t)}-byte payload limit of this runtime \u2014 refusing to stream it (decision=${A}).`),A==="redirect"){try{Rr(e.raw_url,"Redirect download",i)}catch(b){return t.text(b.message||"SSRF blocked",403)}return t.redirect(e.raw_url,302)}return t.json({code:413,message:cw(t,a||"\u8BE5\u5B58\u50A8",d),data:null},413)}t.header("Access-Control-Allow-Origin","*"),t.header("Access-Control-Allow-Methods","GET, OPTIONS, HEAD"),t.header("Access-Control-Expose-Headers","Content-Range, Accept-Ranges, Content-Length, Content-Disposition"),t.header("Content-Type",l.headers.get("content-type")||kL(r));let g=l.headers.get("content-length");g&&t.header("Content-Length",g);let f=l.headers.get("content-range");f&&t.header("Content-Range",f),t.header("Accept-Ranges",l.headers.get("accept-ranges")||"bytes");let p=l.headers.get("etag");p&&t.header("ETag",p);let y=l.headers.get("last-modified");y&&t.header("Last-Modified",y);let m=l.headers.get("cache-control");m&&t.header("Cache-Control",m);let E=l.headers.get("content-disposition");return E&&t.header("Content-Disposition",_L(E)),t.body(l.body,l.status)}async function Gae(t,e,r,i){if(!e)return"";let n=xs(r),s=e.includes("$path")?e.replace(/\$path(?!\w)/g,n):e.replace(/\/+$/,"")+n;if(!Cx(i)&&!/[?&]sign=/.test(s))try{let a=await kl(t,r,await xl(t));a&&(s+=(s.includes("?")?"&":"?")+"sign="+a)}catch(a){console.warn(`[rawRouter] failed to sign down_proxy_url for '${r}': ${a?.message||a}`)}return s}gs.get("/*",async t=>{await qae();let e=t.req.query("proxy")==="true"||t.req.path.startsWith("/p")||t.req.path.startsWith("/api/p")||t.req.path.startsWith("/sd")||t.req.path.startsWith("/api/sd"),r=t.req.path.startsWith("/p")||t.req.path.startsWith("/api/p"),i=t.req.path.replace(/^\/(?:api\/)?(?:raw|sd|d|p)(?=\/|$)/,""),n;try{n=decodeURIComponent(i)}catch{return t.text("Bad Request: malformed path encoding",400)}try{let s=n;if(t.req.path.startsWith("/api/sd")||t.req.path.startsWith("/sd")){let d=(t.req.header("Cookie")||"").split(";").map(p=>p.trim()).find(p=>p.startsWith("browser-password="))?.split("=").slice(1).join("=")||"",A;try{A=d?decodeURIComponent(d):""}catch{A=d}let g=t.req.query("pwd")||A,f=await Bl(s,g,t.env);if(!f.ok)return t.text(f.error||"Share not found",404);if(f.virtualList||!f.realPath)return t.text("Cannot download share root",400);s=f.realPath}else if(await KU(t,s)){let l=t.req.query("sign")||"";if(!await GU(t,s,l))return t.text("sign verify failed",401)}let o=await rt(s);if(o.isVirtual||!o.physical)return t.text("Cannot download virtual directory path",400);if(o.storage){let l=(o.storage.driver||"").toLowerCase().replace(/[^a-z0-9]/g,""),d=await qi().catch(()=>({})),A=Wo(d.proxy_types),g=Wo(d.text_types),f={proxyRange:Ax(o.storage),driver:o.storage.driver,storage:o.storage,ignoreHeaders:d.proxy_ignore_headers};if(r&&!Hf({storage:o.storage,driver:l,filename:s,proxyTypes:A,textTypes:g}))return console.warn(`[rawRouter] proxy not allowed for '${s}' (storage=${o.storage.id}, driver=${o.storage.driver})`),t.text("proxy not allowed",403);if(l!=="local")try{let p=zf(o.storage.addition,t.env),y=await et(o.storage.driver,o.storage),m;try{m=await y.get(s,o.physical)}finally{await Qt(o.storage.driver,o.storage,y,Hae(t))}if(m&&m.raw_url){let E=bx(o.storage,l,e,{filename:s,proxyTypes:A});if(E.mode==="use_proxy_url"){let b=Ex(o.storage);if(b){let C=await Gae(t,b,s,o.storage);if(C){try{Rr(C,"Redirect download",p)}catch(B){return t.text(B.message||"SSRF blocked",403)}return console.log(`[rawRouter] Redirecting download for '${s}' to configured proxy url via ${o.storage.driver}`),t.redirect(C,302)}}return console.warn(`[rawRouter] webdav_policy=use_proxy_url but down_proxy_url is empty (storage=${o.storage.id}); falling back to native proxy`),FL(t,m,s,p,f)}if(E.needsProxy)return FL(t,m,s,p,f);try{Rr(m.raw_url,"Redirect download",p)}catch(b){return t.text(b.message||"SSRF blocked",403)}return console.log(`[rawRouter] Redirecting download for '${s}' via ${o.storage.driver}`),t.redirect(m.raw_url,302)}else if(typeof y.createReadStream=="function"&&m&&!m.is_dir){let E=Number(m.size)||0;if(sw(E,t.req.header("Range"),hs(t)))return console.warn(`[rawRouter] Refusing to stream '${s}': ${E} bytes exceeds the ${hs(t)}-byte payload limit of this runtime.`),t.json({code:413,message:cw(t,o.storage.driver,E),data:null},413);t.header("Access-Control-Allow-Origin","*");let b=m.size||0,C=t.req.header("Range");if(C&&b>0){let{start:B,end:k,chunksize:F}=$h(C,b),Q=await y.createReadStream(o.physical,{start:B,end:k});return t.header("Content-Range",`bytes ${B}-${k}/${b}`),t.header("Accept-Ranges","bytes"),t.header("Content-Length",F.toString()),t.header("Content-Type","application/octet-stream"),t.body(Q,206)}else{b>0&&t.header("Content-Length",b.toString()),t.header("Accept-Ranges","bytes"),t.header("Content-Type","application/octet-stream");let B=await y.createReadStream(o.physical);return t.body(B)}}else{let E=m?.raw_url_error||(m?.is_dir?"\u8BE5\u6761\u76EE\u662F\u6587\u4EF6\u5939\uFF0C\u4E0D\u53EF\u4F5C\u4E3A\u6587\u4EF6\u4E0B\u8F7D\u3002":"\u8BE5\u5B58\u50A8\u9A71\u52A8\u672A\u8FD4\u56DE\u4E0B\u8F7D\u94FE\u63A5\uFF08raw_url \u4E3A\u7A7A\uFF09\u3002");return t.text(`File not found or no download link available: ${s}
|