Exemple #1
0
api_return QueueApi::handleAddFileBundle(ApiRequest& aRequest) {
    const auto& reqJson = aRequest.getRequestBody();

    string targetDirectory, targetFileName;
    TargetUtil::TargetType targetType;
    QueueItemBase::Priority prio;
    Deserializer::deserializeDownloadParams(aRequest.getRequestBody(), targetDirectory, targetFileName, targetType, prio);

    BundlePtr b = nullptr;
    try {
        b = QueueManager::getInstance()->createFileBundle(
                targetDirectory + targetFileName,
                JsonUtil::getField<int64_t>("size", reqJson, false),
                Deserializer::deserializeTTH(reqJson),
                Deserializer::deserializeHintedUser(reqJson),
                JsonUtil::getField<time_t>("time", reqJson, false),
                0,
                prio
            );
    }
    catch (const Exception& e) {
        aRequest.setResponseErrorStr(e.getError());
        return websocketpp::http::status_code::internal_server_error;
    }

    if (b) {
        json retJson = {
            { "id", b->getToken() }
        };

        aRequest.setResponseBody(retJson);
    }

    return websocketpp::http::status_code::ok;
}
Exemple #2
0
void BundleQueue::removeBundle(BundlePtr& aBundle) noexcept{
	if (aBundle->getStatus() == Bundle::STATUS_NEW) {
		return;
	}

	{
		auto infoPtr = getPathInfos(aBundle->getTarget());
		if (infoPtr) {
			auto pathInfos = *infoPtr;
			for (const auto& p : pathInfos) {
				removePathInfo(p);
			}
		}
	}

	dcassert(aBundle->getFinishedFiles().empty());
	dcassert(aBundle->getQueueItems().empty());

	removeSearchPrio(aBundle);
	bundles.erase(aBundle->getToken());

	dcassert(bundlePaths.size() == static_cast<size_t>(boost::count_if(bundles | map_values, [](const BundlePtr& b) { return !b->isFileBundle(); })));

	aBundle->deleteXmlFile();
}
Exemple #3
0
void BundleQueue::addBundle(BundlePtr& aBundle) noexcept {
	bundles[aBundle->getToken()] = aBundle;

	if (aBundle->filesCompleted()) {
		aBundle->setStatus(Bundle::STATUS_COMPLETED);
		return;
	}

	aBundle->setStatus(Bundle::STATUS_QUEUED);
	aBundle->setDownloadedBytes(0); //sets to downloaded segments

	addSearchPrio(aBundle);
}
Exemple #4
0
api_return QueueApi::handleAddDirectoryBundle(ApiRequest& aRequest) {
    const auto& reqJson = aRequest.getRequestBody();

    BundleFileInfo::List files;
    for (const auto& fileJson : reqJson["files"]) {
        files.push_back(BundleFileInfo(
                            JsonUtil::getField<string>("name", reqJson),
                            Deserializer::deserializeTTH(fileJson),
                            JsonUtil::getField<int64_t>("size", reqJson),
                            JsonUtil::getField<time_t>("time", reqJson),
                            Deserializer::deserializePriority(fileJson, true))
                       );
    }

    BundlePtr b = nullptr;
    std::string errors;
    try {
        b = QueueManager::getInstance()->createDirectoryBundle(
                JsonUtil::getField<string>("target", reqJson),
                Deserializer::deserializeHintedUser(reqJson),
                files,
                Deserializer::deserializePriority(reqJson, true),
                JsonUtil::getField<time_t>("time", reqJson),
                errors
            );
    }
    catch (const QueueException& e) {
        aRequest.setResponseErrorStr(e.getError());
        return websocketpp::http::status_code::internal_server_error;
    }

    if (b) {
        json retJson = {
            { "id", b->getToken() },
            { "errors", errors }
        };

        aRequest.setResponseBody(retJson);
    }

    return websocketpp::http::status_code::ok;
}