added admin option for configuring Aria2 globally;option for diallowing aria2 settings for non-privileged users;cleanining up

This commit is contained in:
huangjx
2022-07-31 22:30:32 +08:00
parent e85b8b87ba
commit b1b8bcf988
16 changed files with 284 additions and 129 deletions

82
lib/Aria2/RunOptions.php Normal file
View File

@@ -0,0 +1,82 @@
<?php
namespace OCA\NCDownloader\Aria2;
class RunOptions
{
protected $options = [
'--continue',
'--daemon=true',
'--enable-rpc=true',
'--rpc-secret=ncdownloader123',
'--listen-port=51413',
'--rpc-listen-port=6800',
'--follow-torrent=true',
'--enable-dht=true',
'--enable-peer-exchange=true',
'--peer-id-prefix=-TR2770-',
'--user-agent=Transmission/2.77',
'--log-level=notice',
'--seed-ratio=1.0',
'--bt-seed-unverified=true',
// '--max-overall-upload-limit=' . $this->upSpeed,
// '--max-overall-download-limit=' . $this->dlSpeed,
'--max-connection-per-server=4',
'--max-concurrent-downloads=10',
'--check-certificate=false',
];
public function __construct($options)
{
foreach ($options as $name => $value) {
$name = trim($name);
$value = trim($value);
if (!str_starts_with($value, "--")) {
$name = "--" . $name;
}
if ($value) {
$option = $name . "=" . $value;
} else {
$option = $name;
}
$this->add($option);
}
}
public function add($option)
{
$option = trim($option);
if ($i = $this->find($option)) {
$this->options[$i] = $option;
return $this;
}
array_push($this->options, $option);
return $this;
}
protected function find($option)
{
if (!str_starts_with($option, "--")) {
$option = "--" . $option;
}
if (($i = stripos($option, '=')) === false) {
return $i;
}
$name = substr($option, 0, $i);
foreach ($this->options as $index => $value) {
list($optionName,) = explode("=", $value);
if ($name == $optionName) {
return $index;
}
}
return false;
}
public function has($option)
{
return (bool) array_search($option, $this->options);
}
public function getOptions()
{
return $this->options;
}
}