diff --git a/CHANGELOG.md b/CHANGELOG.md index da3b809..ccdfa9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), ## [Unreleased] +## [0.3.2] - 2026-11-16 + +### Fixed + +- One trophy list or image the server refuses no longer stops the whole sync. The console skips it and sends the rest, so large libraries finish syncing. The server now also accepts images up to 40 MiB, enough for 4K key art. + ## [0.3.1] - 2026-11-15 ### Added @@ -94,7 +100,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), - Diagnostic endpoints, off by default (`"debug": true`). - Builds take their version from the git tag. -[Unreleased]: https://github.com/marcelorsdd/OpenPSApp/compare/v0.3.1...HEAD +[Unreleased]: https://github.com/marcelorsdd/OpenPSApp/compare/v0.3.2...HEAD +[0.3.2]: https://github.com/marcelorsdd/OpenPSApp/compare/v0.3.1...v0.3.2 [0.3.1]: https://github.com/marcelorsdd/OpenPSApp/compare/v0.3.0...v0.3.1 [0.3.0]: https://github.com/marcelorsdd/OpenPSApp/compare/v0.2.0...v0.3.0 [0.2.0]: https://github.com/marcelorsdd/OpenPSApp/compare/v0.1.0...v0.2.0 diff --git a/SYNC.md b/SYNC.md index d5ec747..0c2b97a 100644 --- a/SYNC.md +++ b/SYNC.md @@ -35,7 +35,7 @@ The console's token can only send data. It cannot read your account or change an - Within about a minute after a trophy or playtime changes, for example after you earn a trophy. Once a minute the console rebuilds the summary below and compares it with the last one it sent. - When you choose **Sync now** on the console. -If a sync fails, the console tries again a minute later. Each time, the console first sends a summary. The server answers with what it does not have yet, and the console uploads only that. +If a sync fails, the console tries again a minute later. Each time, the console first sends a summary. The server answers with what it does not have yet, and the console uploads only that. If the server refuses one trophy list or image (too large, a format it does not convert, or not one the account uses), the console skips it, goes on with the rest and offers it again on a later sync. ## What is sent diff --git a/payload/src/cloud/client.cpp b/payload/src/cloud/client.cpp index f4d0795..d318e6f 100644 --- a/payload/src/cloud/client.cpp +++ b/payload/src/cloud/client.cpp @@ -13,6 +13,10 @@ std::string Failure(const net::HttpsResponse &r) { return "HTTP " + std::to_string(r.status); } +bool Refused(const net::HttpsResponse &r) { + return r.ok() && (r.status == 400 || r.status == 409 || r.status == 413 || r.status == 415); +} + std::vector StringArray(const cJSON *obj, const char *name) { std::vector out; const cJSON *item = nullptr; @@ -113,6 +117,10 @@ SyncResult CloudClient::Sync(const std::string &token, const Snapshot &snapshot, auto set = snapshot.sets.find(id); if (set == snapshot.sets.end()) continue; net::HttpsResponse r = Call("PUT", "/api/v1/sync/sets/" + id, set->second, token, kJson); + if (Refused(r)) { + out.refused_sets++; + continue; + } if (!r.ok() || r.status / 100 != 2) return fail(r); out.sets++; } @@ -126,6 +134,10 @@ SyncResult CloudClient::Sync(const std::string &token, const Snapshot &snapshot, } net::HttpsResponse r = Call("PUT", "/api/v1/sync/assets/" + id, std::move(bytes), token, "application/octet-stream", kAssetTimeoutMs); + if (Refused(r)) { + out.refused_assets++; + continue; + } if (!r.ok() || r.status / 100 != 2) return fail(r); out.assets++; } diff --git a/payload/src/cloud/client.hpp b/payload/src/cloud/client.hpp index fba57c1..4966fb1 100644 --- a/payload/src/cloud/client.hpp +++ b/payload/src/cloud/client.hpp @@ -33,6 +33,8 @@ struct SyncResult { bool unauthorized = false; int sets = 0; int assets = 0; + int refused_sets = 0; + int refused_assets = 0; int unread_assets = 0; std::string error; }; diff --git a/payload/src/cloud/controller.cpp b/payload/src/cloud/controller.cpp index d54724f..cf5c582 100644 --- a/payload/src/cloud/controller.cpp +++ b/payload/src/cloud/controller.cpp @@ -175,6 +175,9 @@ void CloudController::TickSync(int64_t now_ms, const std::string &user_key) { retry_at_ms_ = 0; if (result.unread_assets > 0) log::Error("cloud: %d image(s) could not be read; retrying", result.unread_assets); + if (result.refused_sets > 0 || result.refused_assets > 0) + log::Error("cloud: the server refused %d trophy list(s) and %d image(s); skipped them", result.refused_sets, + result.refused_assets); } else if (result.unauthorized) { store_->Remove(user_key); ResetSchedule(); diff --git a/payload/tests/host/test_cloud.cpp b/payload/tests/host/test_cloud.cpp index f0aa7af..b4d7473 100644 --- a/payload/tests/host/test_cloud.cpp +++ b/payload/tests/host/test_cloud.cpp @@ -280,6 +280,61 @@ TEST(cloud_client_uploads_only_what_the_server_asks_for) { } } +TEST(cloud_client_skips_sets_and_images_the_server_refuses) { + std::string image = TempPath("refused.png"); + CHECK(fs::WriteFileAtomic(image, "image-bytes")); + std::string big(64, 'a'), odd(64, 'b'), stray(64, 'c'), fine(64, 'd'); + Snapshot snap; + snap.manifest = "{}"; + snap.sets = {{"NPWR00001_00", "{}"}, {"NPWR00002_00", "{}"}}; + for (const std::string &id : {big, odd, stray, fine}) snap.assets[id] = {image, 0, -1, "1-1"}; + + FakeServer server; + server.handler = [&](const net::HttpsRequest &r) { + if (r.url.find("/sync/manifest") != std::string::npos) + return Reply(200, R"({"needSets":["NPWR00001_00","NPWR00002_00"],"needAssets":[")" + big + R"(",")" + odd + + R"(",")" + stray + R"(",")" + fine + R"("]})"); + if (r.url.find("NPWR00001_00") != std::string::npos) return Reply(400, R"({"error":"invalid_set"})"); + if (r.url.find("/sync/sets/") != std::string::npos) return Reply(204); + if (r.url.find(big) != std::string::npos) return Reply(413, R"({"error":"too_large"})"); + if (r.url.find(odd) != std::string::npos) return Reply(415, R"({"error":"unsupported_image"})"); + if (r.url.find(stray) != std::string::npos) return Reply(409, R"({"error":"not_referenced"})"); + return Reply(201); + }; + CloudClient client("https://api.openpsapp.test", server.transport()); + auto read = [](const icons::Location &where, std::string *out) { return fs::ReadFile(where.path, out); }; + SyncResult result = client.Sync("opsa_tok", snap, read); + CHECK(result.ok); + CHECK_EQ(result.sets, 1); + CHECK_EQ(result.refused_sets, 1); + CHECK_EQ(result.assets, 1); + CHECK_EQ(result.refused_assets, 3); + CHECK_EQ(server.seen.size(), size_t(7)); +} + +TEST(cloud_client_stops_when_the_server_cannot_take_more) { + std::string image = TempPath("stop.png"); + CHECK(fs::WriteFileAtomic(image, "image-bytes")); + std::string first(64, 'a'), second(64, 'b'); + Snapshot snap; + snap.manifest = "{}"; + snap.assets = {{first, {image, 0, -1, "1-1"}}, {second, {image, 0, -1, "1-1"}}}; + auto read = [](const icons::Location &where, std::string *out) { return fs::ReadFile(where.path, out); }; + for (int status : {429, 500, 507}) { + FakeServer server; + server.handler = [&](const net::HttpsRequest &r) { + if (r.url.find("/sync/manifest") != std::string::npos) + return Reply(200, R"({"needSets":[],"needAssets":[")" + first + R"(",")" + second + R"("]})"); + return Reply(status, R"({"error":"x"})"); + }; + CloudClient client("https://api.openpsapp.test", server.transport()); + SyncResult result = client.Sync("opsa_tok", snap, read); + CHECK(!result.ok); + CHECK_EQ(result.refused_assets, 0); + CHECK_EQ(server.seen.size(), size_t(2)); + } +} + TEST(cloud_client_reports_revoked_tokens_and_failures) { Snapshot snap; snap.manifest = "{}";