Loading editor/src/webedit_api.cpp +19 −14 Original line number Diff line number Diff line Loading @@ -5597,13 +5597,6 @@ void webedit::Api::handleImportHtml(libhttppp::HttpRequest &curreq, const size_t kMaxImages = 150; const size_t kMaxImageBytes = 15 * 1024 * 1024; std::unordered_map<std::string, UploadedExternalImage> uploaded; // Many CDNs serve every image off an opaque/generic path (or none // at all -- e.g. a query-string-only cache key), so the filename // derived below collides constantly across a real page's images. // Without disambiguation, every collision after the first // silently overwrites the previous upload in mediadb under the // same name. Counts across the whole job, not just per batch. std::unordered_map<std::string, int> filenameCounts; int imported = 0, failed = 0; size_t importCount = std::min(externalUrls.size(), kMaxImages); Loading @@ -5622,13 +5615,25 @@ void webedit::Api::handleImportHtml(libhttppp::HttpRequest &curreq, std::string filename = std::filesystem::path(url).filename().string(); if (filename.empty()) filename = "image"; if (std::filesystem::path(filename).extension().empty()) filename += "." + guessImageExtFromBytes(bytes); int seen = filenameCounts[filename]++; if (seen > 0) { std::filesystem::path p(filename); filename = p.stem().string() + "-" + std::to_string(seen + 1) + p.extension().string(); } std::string ext = std::filesystem::path(filename).extension().string(); if (ext.empty()) ext = "." + guessImageExtFromBytes(bytes); std::string stem = std::filesystem::path(filename).stem().string(); // Many CDNs (e.g. onecdn.io: /media/<uuid>/<size-variant>) // serve every image off a URL whose last path segment is // just a size-variant token shared by the whole site // ("xlg2x", "md2x", ...), not a per-image filename -- nearly // every image on a real page collides on the same handful of // names. A same-run counter alone isn't enough to fix this: // it restarts at 0 on every import, so retrying the same // page regenerates the exact same name sequence and collides // with whatever the *previous* run already left in the // album ("File with this name already exists in album"), // permanently wedging that page's import. A short id unique // to this fetch -- not just this job -- avoids both cases. uuid::uuid nameUuid; nameUuid.generate(); std::string suffix = nameUuid.c_str(); filename = stem + "-" + suffix.substr(0, 8) + ext; std::string b64 = encodeBase64(bytes); json_object *arr = json_object_new_array(); Loading Loading
editor/src/webedit_api.cpp +19 −14 Original line number Diff line number Diff line Loading @@ -5597,13 +5597,6 @@ void webedit::Api::handleImportHtml(libhttppp::HttpRequest &curreq, const size_t kMaxImages = 150; const size_t kMaxImageBytes = 15 * 1024 * 1024; std::unordered_map<std::string, UploadedExternalImage> uploaded; // Many CDNs serve every image off an opaque/generic path (or none // at all -- e.g. a query-string-only cache key), so the filename // derived below collides constantly across a real page's images. // Without disambiguation, every collision after the first // silently overwrites the previous upload in mediadb under the // same name. Counts across the whole job, not just per batch. std::unordered_map<std::string, int> filenameCounts; int imported = 0, failed = 0; size_t importCount = std::min(externalUrls.size(), kMaxImages); Loading @@ -5622,13 +5615,25 @@ void webedit::Api::handleImportHtml(libhttppp::HttpRequest &curreq, std::string filename = std::filesystem::path(url).filename().string(); if (filename.empty()) filename = "image"; if (std::filesystem::path(filename).extension().empty()) filename += "." + guessImageExtFromBytes(bytes); int seen = filenameCounts[filename]++; if (seen > 0) { std::filesystem::path p(filename); filename = p.stem().string() + "-" + std::to_string(seen + 1) + p.extension().string(); } std::string ext = std::filesystem::path(filename).extension().string(); if (ext.empty()) ext = "." + guessImageExtFromBytes(bytes); std::string stem = std::filesystem::path(filename).stem().string(); // Many CDNs (e.g. onecdn.io: /media/<uuid>/<size-variant>) // serve every image off a URL whose last path segment is // just a size-variant token shared by the whole site // ("xlg2x", "md2x", ...), not a per-image filename -- nearly // every image on a real page collides on the same handful of // names. A same-run counter alone isn't enough to fix this: // it restarts at 0 on every import, so retrying the same // page regenerates the exact same name sequence and collides // with whatever the *previous* run already left in the // album ("File with this name already exists in album"), // permanently wedging that page's import. A short id unique // to this fetch -- not just this job -- avoids both cases. uuid::uuid nameUuid; nameUuid.generate(); std::string suffix = nameUuid.c_str(); filename = stem + "-" + suffix.substr(0, 8) + ext; std::string b64 = encodeBase64(bytes); json_object *arr = json_object_new_array(); Loading