Repository navigation
✨ Feature(gui): group album photos by uploader config - #1452
Conversation
uploader-context.spec.ts asserted the generated clipboard image path against a POSIX-only regex (/^\/picgo-base\/.../), but path.join produces backslashes on Windows, so the test failed there and the husky pre-push hook (which runs the full suite) blocked every push from a Windows checkout. Accept either separator. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The album sidebar only grouped photos by picbed type, so photos from different configs of the same picbed (e.g. two S3 buckets) were mixed into one node. Record the active config on upload, and expose a second sidebar level per picbed listing its configs with per-config counts: - snapshot _configId / _configName in Uploader.upload() before the upload runs, so switching configs mid-upload cannot mis-attribute items; all four AlbumDB insert paths go through it - infer the config of pre-existing items from their url prefix (longest match, originImgUrl preferred over a rewritten imgUrl); inference is recomputed on load and never persisted, so renaming a config or changing its domain re-buckets old photos immediately - add an "unsorted" bucket for items no config claims - resolve display names from live config, falling back to the upload-time snapshot when the config is gone Cloud album items carry no config id, so cloud mode is unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Molunerfinn
left a comment
There was a problem hiding this comment.
Two correctness issues in the config grouping logic should be addressed before merging. This review is based on static inspection; I have not run this PR's tests or exercised the sidebar locally.
| name: config.name, | ||
| count: typeImages.filter((image) => image.configId === config.id).length | ||
| })), | ||
| unknownCount: typeImages.filter((image) => !image.configId).length |
There was a problem hiding this comment.
[P2] Keep photos from deleted configs reachable through a child filter. Upload a photo with config A, then delete A from the uploader config list. buildAlbumPhotos preserves the photo's non-empty _configId, but this function creates child nodes only from the current config list and counts only empty IDs as Unsorted. The photo is consequently included in the provider total but in neither a config child nor Unsorted; retaining its snapshotted name does not create a sidebar entry. Please handle IDs that no longer exist in the current config list consistently in both sidebar counts and filtering, and add a regression test for deleting a config after uploading a photo. Every photo counted in the provider total should remain reachable through a child filter.
| const prefix = normalizeUrlPrefix(config.urlPrefix) | ||
| if (!prefix || !url.startsWith(prefix)) { |
There was a problem hiding this comment.
[P2] Match URL components and preserve case-sensitive paths. Lowercasing the entire URL and applying startsWith can assign legacy photos to the wrong config. For example, a configured prefix https://cdn.example.org/foo also claims https://cdn.example.org/foobar/photo.png, and a host-only prefix https://cdn.example.org claims https://cdn.example.org.other.net/photo.png. Likewise, configs using /Photos/ and /photos/ become indistinguishable even though object-storage paths can be case-sensitive. Please compare parsed origins and case-preserving paths with the appropriate path boundary, retaining longest-prefix selection among valid matches. Add regression cases for host boundaries, sibling path prefixes, and paths differing only by case.
Both from review on Molunerfinn#1452. - buildAlbumProviderFilters built child nodes only from the current config list and counted only empty config ids as Unsorted, so a photo uploaded with a config that was later deleted appeared in the provider total but under no child at all. Such photos now get a child of their own, labelled with the upload-time name snapshot, which keeps configs + unknownCount a partition of count and makes every counted photo reachable. - inferConfigIdFromUrl lowercased the whole url and used startsWith, so https://cdn.example.org/foo also claimed /foobar/photo.png, a host-only prefix claimed lookalike hosts such as cdn.example.org.other.net, and /Photos/ was indistinguishable from /photos/ even though object-storage paths can be case-sensitive. Origins are now compared case-insensitively and paths case-sensitively, with a required segment boundary. Co-Authored-By: Claude Code <noreply@anthropic.com>
|
Both are real bugs — thanks for catching them. Fixed in a5ac554. Deleted configs. You are right that the photo ended up counted in the provider total but reachable through no child. URL matching. Also correct on all three counts. One scope note: a config field holding a bare host with no scheme ( Validation: 7 new cases (33 in the file), full suite 189 passed, |
Molunerfinn
left a comment
There was a problem hiding this comment.
Re-reviewed the latest commit. The deleted-config child nodes and URL origin/path matching address the two earlier findings, with regression tests added. One additional upload-attribution issue remains below. This is a static review of the PR head and the installed PicGo Core 3.1.0 implementation; I have not run the PR tests or exercised the UI locally.
| const configSnapshot = getActiveUploaderConfigSnapshot() | ||
| const output = await picgo.upload(capturedTask.input, capturedTask.options) | ||
| if (Array.isArray(output) && output.some((item: ImgInfo) => item.imgUrl)) { | ||
| applyUploaderConfigSnapshot(output, configSnapshot) |
There was a problem hiding this comment.
[P1] Snapshot the config resolved for this upload request. getActiveUploaderConfigSnapshot() reads only the global picBed.current and picBed.<type>, while picgo.upload(..., capturedTask.options) can select a different uploader/profile through the Server API's uploader, configId, or configName options. For example, leave S3 config A active and upload through /upload?configId=<config-B-id>: Core uploads with B in a request-local context, but this wrapper stamps the result with A's ID/name and uploadSelectedFilesWithInfo persists that incorrect attribution. The album then trusts the stored ID over the URL, so reloading cannot correct it. Please derive the snapshot from the effective per-request config (Core exports resolveUploadOptions) and use the global active config only when appropriate for an upload without overrides. If the selected uploader has no saved config, do not borrow another uploader's global ID. Add coverage for configId, configName, and uploader overrides, ideally including concurrent requests selecting different profiles.
|
One P1 issue remains and should be fixed before merging: uploads that select a profile through the Server API can be saved with the wrong config attribution. For example, with config A globally active, a request specifying config B uploads using B, but the wrapper snapshots A and persists A's Please snapshot the effective config resolved for each request, accounting for The detailed inline review is here: #1452 (comment) |
Resolve request-specific uploader profiles before recording album metadata. Pin only stable defaults and clear uncertain legacy attribution. Add regression tests for request overrides, concurrent uploads, fallback uploaders, profile switches, and stale metadata. Co-Authored-By: Claude Code <noreply@anthropic.com>
|
Fixed in 3281acc.
Known limitation: the tests assert the object handed to |
Molunerfinn
left a comment
There was a problem hiding this comment.
Re-reviewed 3281acc. The previous P1 request-override attribution issue is fixed for path uploads and explicit profile selectors, and the earlier renderer findings remain addressed. I ran the PR head locally: all 200 tests passed and pnpm check passed. One narrower clipboard race remains below. The GitHub CI run has now been approved and is running; this is not a merge approval.
| const canPinDefaultConfig = configSnapshot && !capturedTask.options?.uploader && !capturedTask.options?.configId && !capturedTask.options?.configName && | ||
| picgo.helper.uploader.get(configSnapshot.uploader) && | ||
| picgo.uploaderConfig.getConfigList(configSnapshot.uploader).some(config => | ||
| config._id === configSnapshot.configId && isEqual(config, picgo.getConfig(`picBed.${configSnapshot.uploader}`)) | ||
| ) | ||
| const uploadOptions = canPinDefaultConfig | ||
| ? { ...capturedTask.options, uploader: configSnapshot.uploader, configId: configSnapshot.configId } | ||
| : capturedTask.options |
There was a problem hiding this comment.
[P2] Pin uploader-only overrides before the asynchronous clipboard read. With settings.useBuiltinClipboard=false, a clipboard upload requesting only uploader=<type> snapshots that uploader's active profile A here, but options.uploader excludes it from pinning and the original options reach Core. Core 3.1.0's PicGo.upload awaits the OS clipboard reader before Lifecycle.start resolves the options again. If the user switches that uploader's active profile to B during the wait, the upload uses B while line 273 stamps A's ID/name. Calling the real resolveUploadOptions before and after changing the active profile confirms that the same uploader-only options resolve to different IDs. Please pin an explicitly resolved saved profile by ID as well, rather than restricting pinning to requests without selectors, and add a test with the non-builtin clipboard reader delayed across an active-profile switch. The integration tests currently set useBuiltinClipboard: true, so the existing mid-upload switch tests do not exercise this interval.
There was a problem hiding this comment.
Confirmed - fixed in 04cee84.
Change (src/main/apis/app/uploader/index.ts)
- Pinning is no longer restricted to requests without selectors. Whenever
resolveUploadOptionsresolves a saved profile beforepicgo.upload, we now passuploader + configIdto Core, so it resolves the same profile on both sides of the clipboard wait. - Selector-less requests keep the existing
isEqualmirror guard: we pin only when the active mirror is identical to that saved profile, and otherwise leave resolution to Core and stamp nothing afterwards. That guard is what keeps a legacy mirror from being attributed to a saved profile (covered by the existingpreserves the active mirror upload target...anddoes not attribute a legacy mirror...tests). - The post-upload attribution condition now shares a single expression with the pin condition, so the two cannot drift apart.
Test (src/__tests__/main/server-upload-options.integration.spec.ts)
- Added
pins an uploader-only clipboard request across an active-profile switch, parameterized withit.each([false, true])to cover a matching and a diverging active mirror. - It exercises the real
settings.useBuiltinClipboard = falsepath. The only stub on the clipboard path itself isnode:child_process.spawn(launching the OS clipboard helper); the HTTP route, the snapshot,resolveUploadOptions,lifecycle.start, the uploader plugin and the album write all run for real. The test switches the active profile while the clipboard read is pending, then lets the helper return the path. - Verified red/green: with the fix removed both variants fail (
Expected b-default/Received b-selected); restored, they pass. - Timing re-confirmed independently against
picgo@3.1.0:PicGo.uploadcallsresolveUploadOptionsfirst but discards the result, then awaits the OS clipboard read, and the resolution that actually takes effect happens insidelifecycle.start- matching your analysis.
Verification: pnpm test - 202 passed; pnpm check - clean.
Two intentional narrowings worth flagging
- For
uploader=<type>requests the profile is now frozen at request time rather than at Core resolution time. This matches the semantics the existing mid-transform switch tests already establish. - If a pinned profile is deleted during the clipboard wait, the upload now fails (
UPLOAD_CONFIG_NOT_FOUNDfrom Core) instead of falling back toconfigList[0]. The window is sub-second and the failure is safe - the old behaviour is exactly what produced a B upload stamped with A's ID.
Core resolves upload options twice: once before awaiting the OS clipboard read, and again inside lifecycle.start, where the resolution that actually takes effect happens. A request carrying only an uploader selector was therefore uploaded with whichever profile was active when the clipboard read finished, while the album item was stamped with the profile resolved before it. Pin any profile resolved from an explicit selector to uploader + configId before the clipboard read. Requests without a selector keep the existing mirror equality guard, so a legacy mirror is never attributed to a saved profile. The attribution condition now shares one expression with the pin condition so the two cannot drift apart. Verified red/green: with the fix removed, the new integration test fails with the switched profile; with it, the full suite (202 tests) passes. Co-Authored-By: Claude Code <noreply@anthropic.com>
|
Thanks for your contribution |
Background
The album sidebar grouped photos by picbed type only. A picbed can hold several configs — two S3 buckets, or two COS buckets on different domains — and photos from all of them landed in the same node, with no way to tell them apart.
Changes
Uploader.upload()resolves the config selected for that request through Core'sresolveUploadOptions, so a Server API request naming a profile is attributed to that profile instead of the globally active one, and a plain upload follows Core'spicBed.uploaderprecedence. When the active mirror matches a saved profile exactly the request is pinned to it, so the upload target and the attribution cannot drift apart; when that cannot be proven stable (a legacy mirror with no config list, or a mirror differing from the saved profile) the upload runs exactly as before and no_configIdis written, leaving the item to url inference. Every album insert that follows an upload reaches this method (the clipboard path goes throughuploadWithBuildInClipboard, which calls it), so they are all covered.urlPrefixfor S3,customUrlfor COS/OSS/GitHub,urlfor Qiniu/Upyun), so several field names are probed; the longest prefix wins, andoriginImgUrlis preferred over a rewrittenimgUrl. Inference is recomputed on load and never persisted, so renaming a config or changing its domain re-buckets old photos immediately instead of leaving stale data behind.ALBUM_CONFIG_UNKNOWNto en / zh-CN / zh-TW / ja / ko;i18n.d.tsis regenerated by the build.The first commit is independent of the feature.
uploader-context.spec.tsasserted the generated clipboard path against a POSIX-only regex whilepath.joinyields backslashes on Windows, so the huskypre-pushhook (which runs the full suite) blocked every push from a Windows checkout. Say the word and I will split it into its own PR.Validation
album-config-grouping.spec.ts(33 cases) coversbuildAlbumConfigMap,inferConfigIdFromUrl,buildAlbumPhotosandbuildAlbumProviderFilters: longest-prefix matching, configs that differ only by host,originImgUrlpreferred over a rewrittenimgUrl, falling back to the snapshotted name after a config is deleted, and the empty map when no uploader config exists.server-upload-options.integration.spec.tsanduploader-context.spec.tscover request overrides (configId,configName,uploader), concurrent requests selecting different profiles, mid-upload profile switches, mirror/list mismatch, legacy configs without a config list, fallback from an unregistered uploader, and stale metadata on re-uploaded items. They assert the object handed toAlbumDB.insert; reading back from the on-disk album database is not covered.pnpm test— 200 passed (34 files).pnpm run tscandpnpm lint(eslint + dpdm) — pass.pnpm exec commitlint --from upstream/dev --to HEAD— pass.Also exercised by hand in
pnpm devagainst a 233-photo S3 album with two configs: each config lists its own photos, and after deleting a config the photos uploaded with it stay reachable under a child named from the upload-time snapshot, with the counts still summing to the provider total.