feat: add support for adding torrents by raw hash values (#2608)

* Add support for adding torrents by raw hash values

Co-authored-by: vjunk <vjunk@mail.ru>
This commit is contained in:
Charles Kerr
2022-02-12 22:16:55 -06:00
committed by GitHub
parent dfe79af34c
commit 96178b1a9f
17 changed files with 210 additions and 270 deletions

View File

@@ -33,43 +33,34 @@ QString getNameFromMetainfo(QByteArray const& benc)
int AddData::set(QString const& key)
{
if (Utils::isMagnetLink(key))
if (auto const key_std = key.toStdString(); tr_urlIsValid(key_std))
{
magnet = key;
type = MAGNET;
}
else if (Utils::isUriWithSupportedScheme(key))
{
url = key;
this->url = key;
type = URL;
}
else if (QFile(key).exists())
{
filename = QDir::fromNativeSeparators(key);
this->filename = QDir::fromNativeSeparators(key);
type = FILENAME;
QFile file(key);
auto file = QFile{ key };
file.open(QIODevice::ReadOnly);
metainfo = file.readAll();
this->metainfo = file.readAll();
file.close();
}
else if (Utils::isHexHashcode(key))
else if (tr_magnet_metainfo{}.parseMagnet(key_std))
{
magnet = QStringLiteral("magnet:?xt=urn:btih:") + key;
type = MAGNET;
this->magnet = key;
this->type = MAGNET;
}
else if (auto const raw = QByteArray::fromBase64(key.toUtf8()); !raw.isEmpty())
{
this->metainfo.append(raw);
this->type = METAINFO;
}
else
{
auto raw = QByteArray::fromBase64(key.toUtf8());
if (!raw.isEmpty())
{
metainfo.append(raw);
type = METAINFO;
}
else
{
type = NONE;
}
this->type = NONE;
}
return type;