ClashApi.h 809 B

1234567891011121314151617181920212223242526272829303132333435
  1. #pragma once
  2. #include <cpr/cpr.h>
  3. struct Response
  4. {
  5. uint32_t statusCode;
  6. std::string data;
  7. };
  8. using u16milliseconds = std::chrono::duration<uint16_t, std::milli>;
  9. class ClashApi
  10. {
  11. public:
  12. ClashApi();
  13. ~ClashApi();
  14. void SetProt(int port);
  15. std::string GetVersion();
  16. ClashConfig GetConfig();
  17. std::optional<std::wstring> RequestConfigUpdate(std::filesystem::path configPath);
  18. bool UpdateProxyMode(ClashProxyMode mode);
  19. bool UpdateLogLevel(ClashLogLevel level);
  20. bool UpdateAllowLan(bool allow);
  21. //L"http://cp.cloudflare.com/generate_204"
  22. u16milliseconds GetProxyDelay(std::string_view proxyName);
  23. ClashProxies GetProxies();
  24. bool UpdateProxyGroup(std::string_view group, std::string_view selectProxy);
  25. private:
  26. cpr::Session m_cpr_session;
  27. int m_port;
  28. std::string m_api_base_url;
  29. };