mirror of
https://github.com/transmission/transmission.git
synced 2026-04-18 07:56:33 +01:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user