11#pragma once
22
33#include < filesystem>
4+ #include < nlohmann/json.hpp>
45#include < sstream>
56#include < string>
67
78enum class DownloadType { Model, Engine, Miscellaneous, CudaToolkit, Cortex };
9+ using namespace nlohmann ;
810
911struct DownloadItem {
1012 std::string id;
@@ -33,6 +35,23 @@ struct DownloadItem {
3335 }
3436};
3537
38+ inline std::string DownloadTypeToString (DownloadType type) {
39+ switch (type) {
40+ case DownloadType::Model:
41+ return " Model" ;
42+ case DownloadType::Engine:
43+ return " Engine" ;
44+ case DownloadType::Miscellaneous:
45+ return " Miscellaneous" ;
46+ case DownloadType::CudaToolkit:
47+ return " CudaToolkit" ;
48+ case DownloadType::Cortex:
49+ return " Cortex" ;
50+ default :
51+ return " Unknown" ;
52+ }
53+ }
54+
3655struct DownloadTask {
3756 std::string id;
3857
@@ -50,21 +69,21 @@ struct DownloadTask {
5069 output << " ]}" ;
5170 return output.str ();
5271 }
53- };
5472
55- inline std::string DownloadTypeToString (DownloadType type) {
56- switch (type) {
57- case DownloadType::Model:
58- return " Model" ;
59- case DownloadType::Engine:
60- return " Engine" ;
61- case DownloadType::Miscellaneous:
62- return " Miscellaneous" ;
63- case DownloadType::CudaToolkit:
64- return " CudaToolkit" ;
65- case DownloadType::Cortex:
66- return " Cortex" ;
67- default :
68- return " Unknown" ;
73+ json ToJson () const {
74+ json dl_items = json::array ();
75+
76+ for (const auto & item : items) {
77+ json dl_item{{" id" , item.id },
78+ {" downloadUrl" , item.downloadUrl },
79+ {" localPath" , item.localPath },
80+ {" checksum" , item.checksum .value_or (" N/A" )},
81+ {" bytes" , item.bytes .value_or (0 )},
82+ {" downloadedBytes" , item.downloadedBytes .value_or (0 )}};
83+ dl_items.push_back (dl_item);
84+ }
85+
86+ return json{
87+ {" id" , id}, {" type" , DownloadTypeToString (type)}, {" items" , dl_items}};
6988 }
70- }
89+ };
0 commit comments