[Cache] Rewrote code
[ci skip]
This commit is contained in:
parent
4143cbf0d8
commit
c969f5054d
@ -101,6 +101,7 @@ template <size_t S> class Sizer { };
|
||||
#include "Utils\IO.hpp"
|
||||
#include "Utils\CSV.hpp"
|
||||
#include "Utils\Time.hpp"
|
||||
#include "Utils\Cache.hpp"
|
||||
#include "Utils\Chain.hpp"
|
||||
#include "Utils\Utils.hpp"
|
||||
#include "Utils\WebIO.hpp"
|
||||
|
45
src/Utils/Cache.cpp
Normal file
45
src/Utils/Cache.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#include "STDInclude.hpp"
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
const char* Cache::urls[] =
|
||||
{
|
||||
"https://iw4xcachep26muba.onion.to"/*,
|
||||
"https://iw4xcachejnetuln.onion.to",
|
||||
"https://iw4xcachedjodc4y.onion.to",
|
||||
*/
|
||||
};
|
||||
std::string Cache::validUrl;
|
||||
|
||||
Cache::Cache(std::string path)
|
||||
{
|
||||
this->Path = path;
|
||||
}
|
||||
|
||||
std::string Cache::GetUrl()
|
||||
{
|
||||
if (Cache::validUrl.empty())
|
||||
return Cache::urls[0] + this->Path;
|
||||
else
|
||||
return Cache::validUrl + this->Path;
|
||||
}
|
||||
|
||||
std::string Cache::GetUrl(std::string url, std::string path)
|
||||
{
|
||||
return url + path;
|
||||
}
|
||||
|
||||
std::string Cache::GetFile(int timeout, std::string useragent)
|
||||
{
|
||||
for (int i = 0; i < ARRAY_SIZE(Cache::urls); i++)
|
||||
{
|
||||
std::string result = Utils::WebIO(useragent, this->GetUrl(Cache::urls[i], this->Path)).setTimeout(timeout)->get();
|
||||
if (!result.empty())
|
||||
{
|
||||
Cache::validUrl = Cache::urls[i];
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
16
src/Utils/Cache.hpp
Normal file
16
src/Utils/Cache.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
namespace Utils
|
||||
{
|
||||
class Cache
|
||||
{
|
||||
public:
|
||||
Cache(std::string path);
|
||||
std::string GetUrl();
|
||||
std::string GetFile(int timeout = 5000, std::string useragent = "IW4x");
|
||||
|
||||
//private:
|
||||
static const char* urls[];
|
||||
static std::string validUrl;
|
||||
std::string Path;
|
||||
std::string GetUrl(std::string url, std::string path);
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user