| 277 | } |
| 278 | |
| 279 | std::string CmdListRemoteAppFiles(const std::string& provider, const std::string& accountId, const std::string& appId) { |
| 280 | std::string tokenPath = GetTokenPath(provider); |
| 281 | if (tokenPath.empty()) { |
| 282 | return JsonError("Cannot determine config directory"); |
| 283 | } |
| 284 | |
| 285 | auto prov = CreateCloudProvider(provider); |
| 286 | if (!prov) { |
| 287 | return JsonError("Unknown provider: " + provider); |
| 288 | } |
| 289 | |
| 290 | if (!prov->Init(tokenPath)) { |
| 291 | return JsonError("Failed to initialize provider"); |
| 292 | } |
| 293 | |
| 294 | if (!prov->IsAuthenticated()) { |
| 295 | prov->Shutdown(); |
| 296 | return JsonError("Not authenticated"); |
| 297 | } |
| 298 | |
| 299 | std::string prefix = accountId + "/" + appId + "/"; |
| 300 | std::vector<ICloudProvider::FileInfo> files; |
| 301 | bool complete = false; |
| 302 | if (!prov->ListChecked(prefix, files, &complete)) { |
| 303 | prov->Shutdown(); |
| 304 | return JsonObject({ |
| 305 | {"success", JsonBool(false)}, |
| 306 | {"complete", JsonBool(false)}, |
| 307 | {"error", JsonString("Failed to list remote app files")}, |
| 308 | {"files", "[]"} |
| 309 | }); |
| 310 | } |
| 311 | prov->Shutdown(); |
| 312 | |
| 313 | std::ostringstream out; |
| 314 | out << "["; |
| 315 | bool first = true; |
| 316 | for (const auto& f : files) { |
| 317 | if (!first) out << ","; |
| 318 | out << JsonObject({ |
| 319 | {"path", JsonString(f.path)}, |
| 320 | {"size", JsonInt(static_cast<int64_t>(f.size))}, |
| 321 | {"modified_time", JsonInt(static_cast<int64_t>(f.modifiedTime))} |
| 322 | }); |
| 323 | first = false; |
| 324 | } |
| 325 | out << "]"; |
| 326 | |
| 327 | return JsonObject({ |
| 328 | {"success", JsonBool(true)}, |
| 329 | {"complete", JsonBool(complete)}, |
| 330 | {"files", out.str()} |
| 331 | }); |
| 332 | } |
| 333 | |
| 334 | std::string CmdDeleteRemoteApp(const std::string& provider, const std::string& accountId, const std::string& appId) { |
| 335 | std::string tokenPath = GetTokenPath(provider); |
no test coverage detected