Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(api): 保留响应体读取期间的请求取消

longmeidao1a7384bf5203
diff --git a/frontend/src/api.ts b/frontend/src/api.ts
index 26b13f83b..ae485dae8 100644
--- a/frontend/src/api.ts
+++ b/frontend/src/api.ts
@@ -52,6 +52,7 @@ export async function apiGet<T>(path: string, signal?: AbortSignal): Promise<T>
try {
payload = await response.json();
} catch {
+ signal?.throwIfAborted();
// 失败响应不一定是 JSON(例如 401 的登录页),下面用状态码兜底。
}
if (!response.ok) {
@@ -73,6 +74,7 @@ export async function apiSend<T>(path: string, body: unknown, method = 'POST', s
try {
payload = await response.json();
} catch {
+ signal?.throwIfAborted();
// 同上:失败响应不一定是 JSON。
}
if (!response.ok) {
diff --git a/frontend/test/api-library.test.ts b/frontend/test/api-library.test.ts
index bd6267fbe..e2494de8e 100644
--- a/frontend/test/api-library.test.ts
+++ b/frontend/test/api-library.test.ts
@@ -44,3 +44,24 @@ describe('媒体库查询范围', () => {
]);
});
});
+
+describe('响应体读取期间取消请求', () => {
+ afterEach(() => { vi.unstubAllGlobals() });
+
+ for (const method of ['GET', 'POST'] as const) {
+ it(`${method} 保留取消原因`, async () => {
+ const controller = new AbortController();
+ const cancelled = new DOMException('已中止', 'AbortError');
+ let rejectBody!: (reason: unknown) => void;
+ const body = new Promise<never>((_resolve, reject) => { rejectBody = reject });
+ vi.stubGlobal('fetch', vi.fn(async () => ({ ok: true, json: () => body })));
+ const pending = method === 'GET'
+ ? apiGet('/api/duplicates', controller.signal)
+ : apiSend('/api/batch', { ids: [1] }, 'POST', controller.signal);
+ const rejected = expect(pending).rejects.toBe(cancelled);
+ controller.abort(cancelled);
+ rejectBody(cancelled);
+ await rejected;
+ });
+ }
+});
diff --git a/web/dist/peach-app.js b/web/dist/peach-app.js
index 1a6ec1743..67f7d45e3 100644
--- a/web/dist/peach-app.js
+++ b/web/dist/peach-app.js
@@ -2,7 +2,7 @@
(function() {
try {
var e = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, t = new e.Error().stack;
- t && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[t] = "cb0761ee-80aa-463e-bdd7-cefd7220b3d5", e._sentryDebugIdIdentifier = "sentry-dbid-cb0761ee-80aa-463e-bdd7-cefd7220b3d5");
+ t && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[t] = "dc0d1d22-a6c2-4ee3-89a3-4220fcd1d0e9", e._sentryDebugIdIdentifier = "sentry-dbid-dc0d1d22-a6c2-4ee3-89a3-4220fcd1d0e9");
} catch {}
})();
var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescriptor, r = Object.getOwnPropertyNames, i = Object.getPrototypeOf, a = Object.prototype.hasOwnProperty, o = (e, t) => () => (t || (e((t = { exports: {} }).exports, t, t.exports), e = null), t.exports), s = (e, n) => {
@@ -11521,7 +11521,9 @@ async function B(e, t) {
}), r = null;
try {
r = await n.json();
- } catch {}
+ } catch {
+ t?.throwIfAborted();
+ }
if (!n.ok) throw new Hn(Un(r) || `请求失败(${n.status})`, n.status);
return qt(e, r), r;
}
@@ -11538,7 +11540,9 @@ async function V(e, t, n = "POST", r) {
}), a = null;
try {
a = await i.json();
- } catch {}
+ } catch {
+ r?.throwIfAborted();
+ }
if (!i.ok) throw new Hn(Un(a) || `请求失败(${i.status})`, i.status, a);
return a;
}
@@ -80124,4 +80128,4 @@ if (!$9) throw Error("主界面宿主缺失");
XPe($9);
export { NI as $2ec61d1d4f780267$export$a8a3e93435678ff9, VI as $3a442827418ebe87$export$eb2fcfdbd7ba97d4, iR as $542a13ca2fa5b484$export$5b6b19405a83ff9d, uT as $72abaeab4d80592f$export$78efe591171d7d45, XR as $76d00c5a4edb230a$export$76ccd210b9029917, qR as $76d00c5a4edb230a$export$816b5d811295e6bc, $R as $76d00c5a4edb230a$export$b59bdbef9ce70de2, tz as $76d00c5a4edb230a$export$f6f0c3fe4ec306ea, KR as $76d00c5a4edb230a$export$f850895b287ef28e, gfe as $b4f18e3395fe64d7$export$3d96ec278d3efce4, hfe as $b4f18e3395fe64d7$export$3e41faf802a29e71, ffe as $b4f18e3395fe64d7$export$b2539bed5023c21c, az as $b4f18e3395fe64d7$export$e51a686c67fdaa2d, yfe as $bd263d78e9bf3c56$export$f5c9f3c2c4054eec, ZC as $ea3928288112382f$export$439d29a4e110a164, _R as $f2ff30fde7b014be$export$3ddf2d174ce01153, wR as $fe21c36db05242bb$export$a98f0dcb43a68a25, TR as $fe21c36db05242bb$export$d7b12c4107be0d61, tpe as $l, Wk as ACCENTS, jTe as AMANE_BRIDGE_CHECK_URL, X$ as AMANE_BRIDGE_KEY, MTe as AMANE_BRIDGE_REBUILD_URL, Hn as ApiError, RW as ArtSlot, q as Button, dI as ButtonLink, upe as Bx, Qt as CLOUD_LOCATIONS, X1 as CLOUD_PROXY_HELP, Dr as COLUMN_SORT, c1 as CONFIGURATION_KEY, qY as CONFIGURATION_URL, NTe as COOKIE_TEXT_LIMIT, Y$ as COVER_JOB_KEY, Ai as CREDENTIAL_STATE, G$ as CUSTOM_SOURCES_KEY, W$ as CUSTOM_SOURCES_URL, aV as Checkbox, iV as CheckboxGlyph, YB as ChevronSortDown, sZ as Chip, q2 as CloudDownloadDialog, qH as CollapseChevron, KH as CollapseRegion, f$ as CollectionSummary, mbe as DEFAULT_CATEGORY, Kn as DEFAULT_SORT, jQ as DIAGNOSTICS_KEY, dxe as DIRECTORY_TEMPLATE_ERROR, j0 as DISCOVERY_SORTS, V2 as DOWNLOADS_KEY, B2 as DOWNLOADS_URL, _Y as DUPLICATES_KEY, QJ as DataTableFooter, JJ as DataTableFrame, ZJ as DataTableSort, $H as Disclosure, HOe as DownloadsPanel, Kfe as E3, hbe as ENTITY_REVIEW_KINDS, J1 as ENTRY_LINKS_HELP, Y1 as ENTRY_LINKS_HINT, ipe as Ea, xpe as EmptyFocusButton, Lz as EmptyState, ZH as ErrorText, ige as ExternalLink, Sr as FEEDS_KEY, tX as FEED_SCHEDULE_KEY, VAe as FLOW_LABEL_X, R3 as FLOW_VIEWBOX, br as FOLLOW_CHECK_KEY, yr as FOLLOW_CREDENTIALS_KEY, N8 as FOLLOW_INITIAL_RANGE_OPTIONS, vr as FOLLOW_MANAGE_KEY, FZ as FOLLOW_MANAGE_NAV, xr as FOLLOW_RESOLVE_KEY, eX as FOLLOW_SCHEDULE_KEY, oge as Fact, age as FactList, QH as FieldLabel, L$ as Fieldset, I$ as FieldsetTitle, pue as FilterGlass, iI as FilterGlassRows, rI as FilterIconButton, aI as FilterPill, rge as Footer, xz as Gg, oI as GlassPill, XH as Help, Oz as HintText, NAe as IDLE_POLL_MS, rbe as IDLE_REPAIR, $F as IconButton, Nz as Input, Mz as InputBase, cA as JAV_LAYOUTS, N0 as JAV_RECOMMENDATION_GRID, wX as JUNK_KEY, Z3 as JavHeader, Zye as KEEP_LABELS, wr as LAYOUTS, q1 as LIBRARY_FOLDER_HELP, fH as LIBRARY_PROCESSING_KEY, zY as LINKS_KEY, BY as LINK_CHECK_KEY, Lbe as LINK_KINDS, VY as LINK_PRUNE_KEY, Ln as LOC, Dz as Label, B$ as LibraryProcessingCard, eB as LibraryShortcuts, OH as LinkButton, VH as LoadingDots, Jfe as M6, Hbe as MEDIA_PROCESSING_KEY, rX as MEDIA_PROCESSING_URL, SY as MEDIA_REPAIR_KEY, xY as MEDIA_REPAIR_URL, er as MEDIA_SOURCES_KEY, Zo as MEDIA_SOURCE_ICONS, Xt as MEDIA_SOURCE_OPTIONS, $B as MENU_ITEM, eV as MENU_ITEM_INTERACTIVE, QB as MENU_POPOVER_SURFACE, MH as MenuDialog, PG as MixCard, Pz as ModalFrame, Qv as MotionConfigContext, Ez as NR, Iz as Note, _pe as OA, oX as ORGANIZE_KEY, lX as ORPHAN_RECORDS_KEY, bz as OV, pz as P7, Ywe as PHASES, JY as PICK_FOLDER_URL, H$ as PLAYLISTS_KEY, NEe as POLICY_COLUMNS, FEe as POLICY_COVER_NOTE, PEe as POLICY_MATRIX, K1 as POLICY_SUMMARY, XJ as Pagination, z$ as PathLine, AF as PillTabList, UH as Progress, DY as QUALITY_GOALS_KEY, A$ as REPAIR_CARD_TEXT, CY as REPAIR_LIBRARIES_KEY, mX as RESOURCE_APPLY_KEY, pX as RESOURCE_SCAN_KEY, cTe as RESULT_PANEL, lTe as RESULT_SECTION, pbe as REVIEW_CATEGORIES, CX as REVIEW_COUNTS_KEY, AY as REVIEW_KEY, jY as REVIEW_LABELS, LW as RetryNote, gpe as Rf, ege as Rows, kTe as SCRAPING_CHECK_URL, q$ as SCRAPING_COVER_URL, J$ as SCRAPING_KEY, OTe as SCRAPING_SETTINGS_URL, IU as SEGMENT, FU as SEGMENTED_TRACK, $Y as SETTINGS_KEY, YY as SETTINGS_URL, qn as SORT_DEFAULT_DIR, Gn as SORT_OPTIONS, $t as SOURCE_LABELS, l3 as STATS_KEY, $he as Section, nge as SectionSkeleton, PU as SegmentedRadioGroup, Xge as SegmentedTabList, hW as Segments, YJ as Select, DU as Select$1, f1 as SelectField, OU as SelectItem, aY as SelectionActions, Sk as SelectionDock, oY as SelectionPopover, JH as SettingsCard, Qhe as SettingsRow, YH as SettingsSectionLabel, uge as SiteLabel, VU as SortDirectionIcon, vW as SortKeys, mQ as SourceAvatar, rU as SourceLabel, eU as SourceMark, tge as Stack, R$ as StatusLabel, P2 as Switch, zF as TASKS_KEY, SAe as TASTE_REFRESH_KEY, CAe as TASTE_WINDOWS, nX as THUMBNAIL_JOBS_KEY, EX as TRASH_KEY, qle as TRIGGER_LABELS, zJ as Table, sY as TableColumnControls, cY as TableColumnResizer, uY as TableSelectionHeader, t$ as TagManager, WH as TaskProgress, Az as TextField, kz as TextFieldContext, yz as Un, g$ as WANTS_KEY, r4 as WantMagnets, hp as WithPromise, mz as Wt, vz as Xc, Tz as Xf, Xfe as Xt, qfe as _8, o as __commonJSMin, s as __exportAll, l as __toESM, hpe as aB, si as addAlias, oi as addSource, v$ as addWant, B as apiGet, V as apiSend, nA as appSettingsStore, Axe as applyConfirmText, SX as applyLeftovers, kxe as applyPlanText, Mxe as applyText, oA as applyTheme, Xg as asNumber, vxe as attachOrphan, Ur as authorAvatar, Gr as authorGroups, Hr as authorInitial, Vr as authorName, Dq as autoResetPageIndex, Za as avatarInner, h3 as bandRows, fxe as baseName, nbe as batchOperate, Dk as boundedPreference, $ye as bulkCloudPreferences, Vz as busyProps, mpe as cB, QOe as cachedMagnetStates, ap as calcGeneratorVelocity, xbe as canApprove, kf as cancelFrame, Cxe as candidateText, BH as cardClass, xA as cardRatio, _z as cc, Ei as checkEvidenceGap, Ti as checkFailures, gi as checkFeeds, Vbe as checkLine, Ci as checkReceipt, wi as checkSummary, FTe as checkText, Di as checkedText, oG as clickedBlank, Gye as cloudLocations, D0 as cloudProxySkeleton, vx as clsx, spe as cn, ph as collectMotionValues, qq as columnVisibilityFeature, PJ as column_getCanSort, AJ as column_getSortFn, ybe as commonReviewSources, lV as configurationSection, DAe as configureTasteBrowser, Vc as confirmModal, lq as copyInstancePropertiesWithoutMemos, Wa as coverUrl, Rq as createColumnHelper, STe as createPlaylist, ji as credentialDone, C0 as credentialsSkeleton, Abe as currentReviewRow, DF as cx, Cz as dZ, Dbe as decisionPayload, Obe as decisionReceipt, Ebe as defaultChoice, wTe as deletePlaylist, x as diagnosticHeaders, G1 as diagnosticsSkeleton, rTe as discoveryArtwork, C$ as discoveryKey, aDe as discoveryScore, Yye as distinctName, Nbe as dropReviewRows, xi as dropSources, ppe as du, ebe as duplicateVictims, KF as elapsedText, Xa as entityFaceImg, hn as entityPath, Ir as errorHeadline, Wn as errorMessage, z as esc, Eq as expandRowModel, uz as f1, Fr as feedIntervalText, $$ as fetchAmaneBridge, $r as fetchCheckJob, l1 as fetchConfiguration, Q$ as fetchCoverJob, Qr as fetchCredentials, K$ as fetchCustomSources, MQ as fetchDiagnostics, w$ as fetchDiscoveries, yY as fetchDuplicates, Hle as fetchEarlier, Gbe as fetchFeedSchedule, pi as fetchFeeds, Zr as fetchFollow, Wbe as fetchFollowSchedule, OX as fetchJunkSummary, WY as fetchLinkCheck, GY as fetchLinkPrune, UY as fetchLinkStats, Ube as fetchMediaProcessing, wY as fetchMediaRepair, tr as fetchMediaSources, sX as fetchOrganize, ixe as fetchOrganizeExample, uX as fetchOrphanRecords, fi as fetchPending, U$ as fetchPlaylists, OY as fetchQualityGoals, TY as fetchRepairLibraries, ei as fetchResolveJob, gX as fetchResourceApply, hX as fetchResourceScan, IY as fetchReview, DX as fetchReviewCounts, iX as fetchSettings, Z$ as fetchSources, u3 as fetchStats, ti as fetchSuggestions, VF as fetchTasks, F3 as fetchTaste, OAe as fetchTasteJob, Kbe as fetchThumbnailJobs, kX as fetchTrashSummary, _$ as fetchWants, _be as filterReviewRows, Fn as firstGrapheme, BK as flexRender, UAe as flowGraph, WAe as flowLabel, Hke as fmtCount, kn as fmtDur, jn as fmtSize, nue as foldRoutine, vi as followFeedByName, Cr as followSuggestKey, iue as followupDetail, Of as frame, Lfe as g4, Xq as getDefaultPaginationState, bA as gridLayout, Wr as groupByAuthor, tue as groupFollowups, NY as groupReviewRows, Dxe as hasChanges, _X as hasResourceRoots, UF as hasResultProblems, PAe as historySpan, dz as i2, MAe as importTasteExport, w0 as indexersSkeleton, Zf as interpolate, b$ as invalidateWants, GF as isActive, Pr as isBroken, Or as isLayout, Rh as isMotionValue, MY as isReviewCategory, rue as isRoutine, T0 as javBrowserSkeleton, F0 as javContentSkeleton, pA as javLayout, P0 as javTagSkeleton, Lxe as junkBreakdown, TTe as keepPlaylist, ke as keepPreviousData, Jr as keepSelected, d3 as known, Vfe as l7, eue as latestOfKind, eAe as lengthRows, ir as localTime, _i as lookupFeedActor, Wfe as m7, Sz as mM, cn as mapLimit, di as markItem, g3 as max, Qke as mediumRows, Ule as mergeFinished, _3 as min, Fbe as mirrorText, obe as missingToolText, bY as mixedCloudPreferences, XF as momentText, By as motion, hh as motionValue, mxe as organizeOutcome, X0 as overlayHost, kr as pageSizeOf, qr as pageWindow, Xn as paginationRange, bi as patchSource, ZV as peachHistory, ZV as peachHistory$1, Tbe as pendingGenres, Wke as percentText, sxe as pickOrganizeFolder, pxe as planSummary, f3 as playedFor, Kke as playedItemUrl, BF as pollInterval, ks as popCount, xTe as posterUrl, nG as previewLibraryColor, oxe as previewOrganize, lbe as previewUrl, $le as problemDestination, qF as progressText, nU as providerIcon, Bbe as pruneText, yX as purgeCount, yxe as purgeOrphan, wz as pv, fpe as qE, H as queryClient, fz as r2, BAe as radarRows, Yke as radialArc, Xke as radialBarSize, Jke as radialCeiling, qke as radialSlices, Ij as randomId, RAe as rankDetail, zAe as rankShares, m3 as reachedShare, JF as readableErrorHeadline, oDe as recommendationScore, jbe as recordGenre, xxe as recordsText, ETe as recreatePlaylist, yTe as refreshPlaylists, xl as relayoutCovers, Si as reloadFollowManage, Pbe as reloadReview, REe as rememberShape, lxe as rememberTemplates, ci as removeAlias, hi as removeFeed, ai as removeSource, jAe as removeTasteSource, y$ as removeWants, li as renameAliasGroup, CTe as renamePlaylist, nAe as replayRows, ie as require_jsx_runtime, A as require_react, te as require_react_dom, aq as require_with_selector, Qwe as resetWants, Yn as resolveFollowSort, dp as resolveStartTime, bTe as resumeAssetId, gbe as reviewGroupingOptions, Ixe as reviewSummary, vbe as reviewWindow, Cbe as rowEvidence, FY as rowFieldName, rJ as rowPaginationFeature, wJ as rowSelectionFeature, LJ as rowSortingFeature, PY as rowSubject, wbe as rowTags, Sbe as rowTitle, Rfe as s5, ui as saveCredential, Oxe as scanLine, Zbe as schedulePollInterval, eTe as searchNote, bbe as selectReviewRange, Yr as selectionState, mi as setFeedEnabled, ii as setSourceEnabled, pV as settingsPath, Jye as sharedNamePrefix, QV as shellNavigate, b8 as showToast, xn as siteMarkUrl, _q as skipFirstRun, OF as sortCx, jr as sortLabel, en as sourceDefaultCost, ki as sourceIconUrl, jxe as sourceMeta, bs as spinnerHtml, Jf as spring, zz as spriteGlyph, ni as startCheck, Rbe as startLinkCheck, zbe as startLinkPrune, cxe as startOrganize, ri as startResolve, Txe as startResourceApply, wxe as startResourceScan, AAe as startTasteRefresh, Yle as statusLabel, abe as statusLine, Nr as statusText, SA as storeJavLayout, kbe as submitDecision, ZF as summaryItems, zq as tableFeatures, vq as tableMemo, Kr as tableRows, Qle as taskIssues, I3 as tasteDate, IAe as tasteDimensions, FAe as tasteHours, P3 as tasteKey, TAe as tasteRefetchInterval, EAe as tasteTime, PF as textLang, ld as time, epe as tl, Xr as toggleGroup, L3 as topScores, rpe as uo, kH as useAction, AZ as useBackgroundJob, bU as useClientUpdates, xu as useConstant, nI as useHorizontalScroller, Su as useIsomorphicLayoutEffect, iG as useLibraryTints, Ft as useMutation, oV as useOverlayScrollbar, Pt as useQuery, oe as useQueryClient, My as useReducedMotion, Xbe as useRunSchedule, Jbe as useSaveFollowSchedule, aX as useSaveSettings, Qbe as useSaveThumbnailMode, RJ as useTable, tY as useTablePreferences, tbe as victimBytes, $we as wantName, Gke as watchNote, p3 as watchedShare, cc as wireHorizontalScroller, uxe as withOrganizeJob };
-//# debugId=cb0761ee-80aa-463e-bdd7-cefd7220b3d5
\ No newline at end of file
+//# debugId=dc0d1d22-a6c2-4ee3-89a3-4220fcd1d0e9
\ No newline at end of file