
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Typescript library for aria2. You could use JSON RPC to communicate easily with aria2. You could download aria2 easily according to your os.
TavaScript library for aria2.
Although there have been some lib or implement for aria2 in javascript and typescript. For lib, there are :
For other implement, often they are electron or web wrapper of aria2:
aria2.js might be the best in libs. It provide a general method call
and some specificed methods.
However, there are still some flaws:
call
, I have no idea about any method provided by aria2 and I could input any string rather than defined by aria2, such as aria2.call("addUri123", [magnet], { dir: "/tmp" });
, only when running I could know the issue.[x] notification event response.
[x] websocket supported - what should we do to switch http and websocket? Through one method or change url directly?
[x] returned type - However, options parameter might not be right
[] encrypt RPC traffic with SSL/TLS supported
[] Options in methods might not be all, some options could not be used.
you can install aria2 through any one from following ways:
pacman S aria2
in arch linux
aria2c --enable-rpc
Here I will give some usefule advice for how to use aria2(at least for myself). Offical document is always much more recommanded.
Just download again. Aria would continur its job! At least three ways:
aria2c 'https://github.com/aria2/aria2/releases/download/release-1.35.0/aria2-1.35.0-aarch64-linux-android-build1.zip'
# some thing happeds, maybe you stop it or aria2 shut down, anyway, downloading is stopped.
aria2c 'https://github.com/aria2/aria2/releases/download/release-1.35.0/aria2-1.35.0-aarch64-linux-android-build1.zip'
adduri
.await res = tmpClient.addUri(['https://github.com/aria2/aria2/releases/download/release-1.35.0/aria2-1.35.0-aarch64-linux-android-build1.zip'])
# some thing happeds, maybe you stop it or aria2 shut down, anyway, downloading is stopped.
await res = tmpClient.addUri(['https://github.com/aria2/aria2/releases/download/release-1.35.0/aria2-1.35.0-aarch64-linux-android-build1.zip'])
unpause
. When downloading one resource, aria2 will return a gid, unpause could use this gid to restart download. However, if you restart aria2 bin, there are more things to be discussed:
await res = tmpClient.addUri(['https://github.com/aria2/aria2/releases/download/release-1.35.0/aria2-1.35.0-aarch64-linux-android-build1.zip'])
let gid = await res.json().result;
// some thing happeds, maybe you stop it or aria2 shut down, anyway, downloading is stopped.
await res = tmpClient.unpause(gid);
// dedault endpoint is http://localhost:6800/jsonrpc
var defaultClient = new JsonRpcClient();
var httpClient = new JsonRpcClient('http://localhost:6800/jsonrpc');
var websocketClient = new JsonRpcClient('ws://localhost:6800/jsonrpc');
secure is not supported for temp.
There are total 36 methods in aria2 rpc methods, such as aria2.addUri
, aria2.getOption
, system.listMethods
.
You can learn more on Aria2 document. The parameter type imitates the document.
Just call through client directly, all parameters(but not response, for now) have types. For example:
await res = tmpClient.addUri(['https://github.com/aria2/aria2/releases/download/release-1.35.0/aria2-1.35.0-aarch64-linux-android-build1.zip'], { dir: './' }, 2)
websocket could add event listener : 'close', 'error', 'message', 'open'.
thanks to typescript, you could only input these types, and there would be intellisense You could add them by following code:
client.addEventListenerForWebSocket('message', ({ data }) => {
console.log(data);
});
Aria2 provides some notifications: 'aria2.onDownloadStart','aria2.onDownloadPause','aria2.onDownloadStop','aria2.onDownloadComplete','aria2.onDownloadError','aria2.onBtDownloadComplete'.
thanks to typescript, you could only input these types, and there would be intellisense In low level, these are some specail case for 'message' event. you could add them by following code:
client.notification('aria2.onDownloadStop', (res) => {
console.log('stop');
console.log(res.gid);
});
Almost all comments are from aria2 offical site, and I use two scripts to produce code.
Just go to the web, and press F12, copy code and run them in the console. Then you could see the code.
However, some modification are still needed. these script still need to improved.
No, there is not any real test that you expect.
For now, I use them manually to check whether function behaves as expected. But I clean the side effects(if any) by myself.
To hide low level, we wish to use like follows, no matter client is ws or fetch or something else.
res = await client.method();
However, websocket use eventlistener, which is necessary for it could not expect request returns in order.
So, we need a convention to recognise message pair. For aria2 this is a property called 'id', but generally, it may be something like sendMessage.recogniseResponseId()
, receivedMessage.getId()
, the returned values should be the same and unique(bijection, so there will only be one pair for one sentMessage and one receivedMessage)
Then we need two function to judge when to mark Promise as resolved or rejected, like receivedMessage.success()
and receiveMessage.fail()
Finally we could code:
const websocket = new WebSocket('url');
let defferTask={};
websocket.addEventListener('message',(receivedMessage)=>{
b = receivedMessage.getId()
if(defferedTask[b]) == undefined throw new Error("this task not existed.")
if(receivedMessage.success())
defferedTask[b].resolvePromise(receivedMessage);
else if(receiveMessage.fail())
defferedTask[b].rejectPromise("some error")
else defferedTask[b].rejectPromise("strange error")
})
function send(message){
let websocket;
websocket.send('message');
return new Promise((resolve,reject)=>{
a = sendMessage.recogniseResponseId()
defferedTask[a]={
resolvePromise:(para)=>{
resolve(para);
},
rejectPromise:(para)=>{
reject(para);
}
}
});
}
FAQs
Typescript library for aria2. You could use JSON RPC to communicate easily with aria2. You could download aria2 easily according to your os.
The npm package aria2ts receives a total of 14 weekly downloads. As such, aria2ts popularity was classified as not popular.
We found that aria2ts demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.