build: Fix web service functionality. (#6903)

This commit is contained in:
Steveice10 2023-08-19 17:34:35 -07:00 committed by GitHub
parent 6ddf4b241f
commit b2092de871
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 15 additions and 19 deletions

View file

@ -1,8 +1,6 @@
add_library(web_service STATIC
announce_room_json.cpp
announce_room_json.h
nus_download.cpp
nus_download.h
precompiled_headers.h
telemetry_json.cpp
telemetry_json.h

View file

@ -1,49 +0,0 @@
// Copyright 2020 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <memory>
#include <httplib.h>
#include "common/logging/log.h"
#include "web_service/nus_download.h"
namespace WebService::NUS {
std::optional<std::vector<u8>> Download(const std::string& path) {
constexpr auto HOST = "http://nus.cdn.c.shop.nintendowifi.net";
std::unique_ptr<httplib::Client> client = std::make_unique<httplib::Client>(HOST);
if (client == nullptr) {
LOG_ERROR(WebService, "Invalid URL {}{}", HOST, path);
return {};
}
httplib::Request request{
.method = "GET",
.path = path,
// Needed when httplib is included on android
.matches = httplib::Match(),
};
client->set_follow_location(true);
const auto result = client->send(request);
if (!result) {
LOG_ERROR(WebService, "GET to {}{} returned null", HOST, path);
return {};
}
const auto& response = result.value();
if (response.status >= 400) {
LOG_ERROR(WebService, "GET to {}{} returned error status code: {}", HOST, path,
response.status);
return {};
}
if (!response.headers.contains("content-type")) {
LOG_ERROR(WebService, "GET to {}{} returned no content", HOST, path);
return {};
}
return std::vector<u8>(response.body.begin(), response.body.end());
}
} // namespace WebService::NUS

View file

@ -1,15 +0,0 @@
// Copyright 2020 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include <optional>
#include <vector>
#include "common/common_types.h"
namespace WebService::NUS {
std::optional<std::vector<u8>> Download(const std::string& path);
}