mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
1 line
1.3 KiB
JavaScript
1 line
1.3 KiB
JavaScript
(()=>{return(t,o)=>{function r(){const o=t.aria2RpcOption;const r=o.host.match(/^http[s]?:\/\//)?o.host:"http://"+o.host;const e="aria2.addUri";return{option:o,host:r,methodName:e}}async function e(t,o=false){try{let r=await t();if(typeof r==="string"){r=JSON.parse(r)}if(r.error!==undefined){if(r.error.code===1){logError(`请求遭到拒绝, 请检查您的密钥相关设置.`)}else{logError(`请求发生错误, code = ${r.error.code}, message = ${r.error.message}`)}return false}if(!o){Toast.success(`成功发送了请求, GID = ${r.result}`,"aria2 RPC",5e3)}return true}catch(t){logError(`无法连接到RPC主机.`);return false}}async function a(t,o=false){const{option:a,host:s,methodName:n}=r();return await e(async()=>{const o=window.btoa(unescape(encodeURIComponent(JSON.stringify(t.params))));const r=`${s}:${a.port}/jsonrpc?method=${n}&id=${t.id}¶ms=${o}`;console.log(`RPC request:`,r);return await Ajax.getJson(r)},o)}async function s(t,o=false){const{option:a,host:s,methodName:n}=r();return await e(async()=>{const o=`${s}:${a.port}/jsonrpc`;return await Ajax.postJson(o,{method:n,id:t.id,params:t.params})},o)}async function n(o,r=false){const e=t.aria2RpcOption;for(const t of o){let o;if(e.method==="get"){o=await a(t,r)}else{o=await s(t,r)}if(r===true&&o===false){logError(`${t.id} 导出失败`)}}}return{export:{sendRpc:n}}}})(); |