Skip to content

✨ Feature(gui): group album photos by uploader config - #1452

Merged
Molunerfinn merged 5 commits into
Molunerfinn:devfrom
2669731003:feat/album-config-grouping
Oct 17, 2026
Merged

Molunerfinn merged 5 commits into
Molunerfinn:devfrom
2669731003:feat/album-config-grouping

Conversation

@2669731003

@2669731003 2669731003 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Record which config produced each upload. Uploader.upload() resolves the config selected for that request through Core's resolveUploadOptions, 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's picBed.uploader precedence. 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 _configId is written, leaving the item to url inference. Every album insert that follows an upload reaches this method (the clipboard path goes through uploadWithBuildInClipboard, which calls it), so they are all covered.
  • Infer the config of items uploaded before this change from their url prefix. Picbeds name their public url differently (urlPrefix for S3, customUrl for COS/OSS/GitHub, url for Qiniu/Upyun), so several field names are probed; the longest prefix wins, and originImgUrl is 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 instead of leaving stale data behind.
  • Add a second sidebar level: each picbed expands into its configs with per-config counts, plus an "Unsorted" bucket for items no config claims.
  • Resolve display names from the live config, falling back to the name snapshotted at upload time when the config no longer exists.
  • Add ALBUM_CONFIG_UNKNOWN to en / zh-CN / zh-TW / ja / ko; i18n.d.ts is regenerated by the build.
  • Cloud album items carry no config id, so cloud mode is unchanged.

The first commit is independent of the feature. uploader-context.spec.ts asserted the generated clipboard path against a POSIX-only regex while path.join yields backslashes on Windows, so the husky pre-push hook (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) covers buildAlbumConfigMap, inferConfigIdFromUrl, buildAlbumPhotos and buildAlbumProviderFilters: longest-prefix matching, configs that differ only by host, originImgUrl preferred over a rewritten imgUrl, 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.ts and uploader-context.spec.ts cover 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 to AlbumDB.insert; reading back from the on-disk album database is not covered.
  • pnpm test — 200 passed (34 files).
  • pnpm run tsc and pnpm lint (eslint + dpdm) — pass.
  • pnpm exec commitlint --from upstream/dev --to HEAD — pass.

Also exercised by hand in pnpm dev against 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.

2669731003 and others added 2 commits October 7, 2026 23:51
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 Molunerfinn left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Comment on lines +248 to +249
const prefix = normalizeUrlPrefix(config.urlPrefix)
if (!prefix || !url.startsWith(prefix)) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

@Molunerfinn
Molunerfinn self-requested a review October 10, 2026 00:23
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>
@2669731003

Copy link
Copy Markdown
Contributor Author

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. buildAlbumProviderFilters now collects the photos whose configId is no longer in the current config list into child nodes of their own, labelled with the _configName snapshot taken at upload time, falling back to the id when there is none. configs + unknownCount is now a partition of count, and since filtering matches on configId those children filter correctly without any extra wiring. The tests cover a deleted config both with and without a snapshot, and assert explicitly that the child counts plus the unsorted bucket equal the provider total.

URL matching. Also correct on all three counts. inferConfigIdFromUrl now parses the prefix and the photo url into an origin and a path: the origin is compared case-insensitively (scheme and host are case-insensitive), the path case-sensitively, and a path prefix must end on a segment boundary. So …/foo no longer claims …/foobar/photo.png, a host-only prefix no longer claims cdn.example.org.other.net, and /Photos and /photos stay distinct. Longest prefix still wins among valid matches. Added the three regression cases you asked for.

One scope note: a config field holding a bare host with no scheme (host, domain) still matches nothing, because it cannot be compared as a URL. That was already the case before this change, and I left it alone rather than widen the behaviour in this PR — happy to revisit separately if you would prefer it to work.

Validation: 7 new cases (33 in the file), full suite 189 passed, pnpm run tsc and pnpm lint clean. I also exercised the sidebar by hand in pnpm dev against 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 snapshot, with the counts still summing to the provider total.

@Molunerfinn Molunerfinn left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/main/apis/app/uploader/index.ts Outdated
Comment on lines +254 to +257
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)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

@Molunerfinn

Copy link
Copy Markdown
Owner

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 _configId on the resulting album item. Reloading does not fix this because the album prioritizes the stored ID over URL inference.

Please snapshot the effective config resolved for each request, accounting for configId, configName, and uploader overrides, and add regression coverage for those overrides and concurrent requests selecting different profiles.

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>
@2669731003

Copy link
Copy Markdown
Contributor Author

Fixed in 3281acc.

  • Request overrides (configId, configName, uploader) now resolve through Core's resolveUploadOptions, so the album records the config that was actually selected instead of the globally active one.
  • Plain uploads follow Core's picBed.uploader precedence. When the active mirror matches a saved profile exactly, the request is pinned to that profile so the upload target and the attribution stay consistent; when that cannot be proven stable — a legacy mirror with no config list, or a mirror that differs from the saved profile — the upload runs exactly as before and no _configId is written.
  • An uploader that is unregistered now falls back without carrying the old profile's _configId/_configName, and re-uploaded items no longer inherit metadata from the input object. Those items fall back to the album's url inference.
  • Tests cover request overrides, concurrent requests, mid-upload profile switches (A→B→A and A→B), mirror/list mismatch, legacy configs, fallback uploaders, and stale metadata. pnpm test — 200 passed; pnpm check — passes.

Known limitation: the tests assert the object handed to AlbumDB.insert; reading back from the on-disk album database is not covered.

@Molunerfinn Molunerfinn left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/main/apis/app/uploader/index.ts Outdated
Comment on lines +263 to +270
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

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed - fixed in 04cee84.

Change (src/main/apis/app/uploader/index.ts)

  • Pinning is no longer restricted to requests without selectors. Whenever resolveUploadOptions resolves a saved profile before picgo.upload, we now pass uploader + configId to Core, so it resolves the same profile on both sides of the clipboard wait.
  • Selector-less requests keep the existing isEqual mirror 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 existing preserves the active mirror upload target... and does 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 with it.each([false, true]) to cover a matching and a diverging active mirror.
  • It exercises the real settings.useBuiltinClipboard = false path. The only stub on the clipboard path itself is node: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.upload calls resolveUploadOptions first but discards the result, then awaits the OS clipboard read, and the resolution that actually takes effect happens inside lifecycle.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_FOUND from Core) instead of falling back to configList[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>
@Molunerfinn

Copy link
Copy Markdown
Owner

Thanks for your contribution

@Molunerfinn
Molunerfinn merged commit 78283f4 into Molunerfinn:dev Oct 17, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants