Esempio n. 1
0
BtsApiNotifier *BtsApi::getFolderPeers(const QString &secret)
{
	QueryList ql;

	ql << QueryPair("secret", secret);

	QUrl apiUrl = getApiUrl(p, "get_folder_peers", ql);

	QNetworkReply *reply = p->nam->get(QNetworkRequest(apiUrl));
	BtsApiNotifier *notifier = new BtsApiNotifier(this);

	connect(reply, &QNetworkReply::finished, [this, reply, notifier, secret]()
	{
		notifier->deleteLater();

		if(checkForError(reply, notifier))
			return;

		QJsonDocument doc = QJsonDocument::fromJson(reply->readAll());

		if(checkForError(doc, notifier))
			return;

		QJsonArray arr = doc.array();
		QVector<BtsGetFolderPeersResult> res;
		res.reserve(arr.size());

		for(const QJsonValue &val: arr)
		{
			QJsonObject peerObj = val.toObject();

			if(peerObj.isEmpty())
			{
				emit error("Got an unexpected get_folder_peers reply format");
				return;
			}

			BtsGetFolderPeersResult resObj;

			resObj.id = peerObj.value("id").toString();
			resObj.connection = peerObj.value("connection").toString();
			resObj.name = peerObj.value("name").toString();
			resObj.synced = peerObj.value("synced").toVariant().toLongLong();
			resObj.download = peerObj.value("download").toVariant().toLongLong();
			resObj.upload = peerObj.value("upload").toVariant().toLongLong();

			res << resObj;
		}

		emit getFolderPeersResult(res, secret);
		emit notifier->getFolderPeersResult(res, secret);
	});

	return notifier;
}
Esempio n. 2
0
BtsApiNotifier *BtsApi::getFiles(const QString &secret, const QString &path)
{
	QueryList ql;

	ql << QueryPair("secret", secret);

	if(!path.isEmpty())
		ql << QueryPair("path", path);

	QUrl apiUrl = getApiUrl(p, "get_files", ql);

	QNetworkReply *reply = p->nam->get(QNetworkRequest(apiUrl));
	BtsApiNotifier *notifier = new BtsApiNotifier(this);

	connect(reply, &QNetworkReply::finished, [this, reply, notifier, secret]()
	{
		notifier->deleteLater();

		if(checkForError(reply, notifier))
			return;

		QJsonDocument doc = QJsonDocument::fromJson(reply->readAll());

		if(checkForError(doc, notifier))
			return;

		QJsonArray arr = doc.array();
		QVector<BtsGetFilesResult> res;
		res.reserve(arr.size());

		for(const QJsonValue &val: arr)
		{
			QJsonObject fileObj = val.toObject();

			if(fileObj.isEmpty())
			{
				emit error("Got an unexpected get_files reply format");
				return;
			}

			BtsGetFilesResult resObj;

			parseGetFilesResult(fileObj, resObj);

			res << resObj;
		}

		emit getFilesResult(res, secret);
		emit notifier->getFilesResult(res, secret);
	});

	return notifier;
}
Esempio n. 3
0
BtsApiNotifier *BtsApi::getSecrets(bool encryption, const QString &secret, const QUuid &uuid)
{
	QueryList ql;

	if(!secret.isEmpty())
		ql << QueryPair("secret", secret);

	if(encryption)
		ql << QueryPair("type", "encryption");

	QUrl apiUrl = getApiUrl(p, "get_secrets", ql);

	QNetworkReply *reply = p->nam->get(QNetworkRequest(apiUrl));
	BtsApiNotifier *notifier = new BtsApiNotifier(this);

	connect(reply, &QNetworkReply::finished, [this, reply, notifier, uuid]()
	{
		notifier->deleteLater();

		if(checkForError(reply, notifier))
			return;

		QJsonDocument doc = QJsonDocument::fromJson(reply->readAll());

		if(checkForError(doc, notifier))
			return;

		QJsonObject obj = doc.object();

		QString rw = obj.value("read_write").toString();
		QString ro = obj.value("read_only").toString();
		QString ec = obj.value("encryption").toString();

		if(uuid.isNull())
		{
			emit getSecretsResult(rw, ro, ec);
			emit notifier->getSecretsResult(rw, ro, ec);
		}
		else
		{
			emit getSecretsResultUuid(uuid, rw, ro, ec);
			emit notifier->getSecretsResultUuid(uuid, rw, ro, ec);
		}
	});

	return notifier;
}
Esempio n. 4
0
BtsApiNotifier *BtsApi::setFolderHosts(const QString &secret, const QStringList &hosts)
{
	QueryList ql;

	ql << QueryPair("secret", secret)
	   << QueryPair("hosts", hosts.join(','));

	QUrl apiUrl = getApiUrl(p, "set_folder_hosts", ql);

	QString queryString = apiUrl.query(QUrl::FullyEncoded);

	QNetworkReply *reply = p->nam->get(QNetworkRequest(apiUrl));
	BtsApiNotifier *notifier = new BtsApiNotifier(this);

	connect(reply, &QNetworkReply::finished, [this, reply, notifier, secret]()
	{
		notifier->deleteLater();

		if(checkForError(reply, notifier))
			return;

		QJsonDocument doc = QJsonDocument::fromJson(reply->readAll());

		if(checkForError(doc, notifier))
			return;

		QJsonObject obj = doc.object();
		QJsonArray arr = obj.value("hosts").toArray();
		QStringList res;

		for(const QJsonValue &val: arr)
			res << val.toString();

		emit setFolderHostsResult(res, secret);
		emit notifier->setFolderHostsResult(res, secret);
	});

	return notifier;
}
Esempio n. 5
0
BtsApiNotifier *BtsApi::setFolderPrefs(const QString &secret, const QVariantHash &prefs)
{
	QueryList ql;

	ql << QueryPair("secret", secret);

	for(auto it = prefs.constBegin(); it != prefs.constEnd(); ++it)
		ql << QueryPair(it.key(), it.value().toString());

	QUrl apiUrl = getApiUrl(p, "set_folder_prefs", ql);

	QNetworkReply *reply = p->nam->get(QNetworkRequest(apiUrl));
	BtsApiNotifier *notifier = new BtsApiNotifier(this);

	connect(reply, &QNetworkReply::finished, [this, reply, notifier, secret]()
	{
		notifier->deleteLater();

		if(checkForError(reply, notifier))
			return;

		QJsonDocument doc = QJsonDocument::fromJson(reply->readAll());

		if(checkForError(doc, notifier))
			return;

		QJsonObject obj = doc.object();
		QVariantHash res;

		for(auto it = obj.constBegin(); it != obj.constEnd(); ++it)
			res[it.key()] = it.value().toVariant();

		emit setFolderPrefsResult(res, secret);
		emit notifier->setFolderPrefsResult(res, secret);
	});

	return notifier;
}
Esempio n. 6
0
std::string ZDvidUrl::getApiLoadUrl() const
{
  return GetFullUrl(getApiUrl(), "load");
}
Esempio n. 7
0
std::string ZDvidUrl::getRepoInfoUrl() const
{
  return GetFullUrl(getApiUrl(), "/repos/info");
}
Esempio n. 8
0
std::string ZDvidUrl::getServerInfoUrl() const
{
  return GetFullUrl(getApiUrl(), "server/info");
}
Esempio n. 9
0
std::string ZDvidUrl::getHelpUrl() const
{
  return GetFullUrl(getApiUrl(), "help");
}
Esempio n. 10
0
std::string ZDvidUrl::getServerInfoUrl() const
{
  return getApiUrl() + "/server/info";
}
Esempio n. 11
0
std::string ZDvidUrl::getHelpUrl() const
{
  return getApiUrl() + "/help";
}
Esempio n. 12
0
std::string ZDvidUrl::getRepoInfoUrl() const
{
  return getApiUrl() + "/repos/info";
}
Esempio n. 13
0
std::string ZDvidUrl::getRepoUrl() const
{
  return getApiUrl() + "/repo/" + m_dvidTarget.getUuid();
}