Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion apps/api/src/file-storage/file-config-s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ export async function listObjects(params: {
target,
false,
monthShardPrefixesList,
params.imageOnly ?? false,
);
}

Expand All @@ -309,10 +310,12 @@ export async function listObjects(params: {
),
),
);
const imageOnly = params.imageOnly ?? false;
const seen = new Map<string, ListedObject>();
for (const res of monthResponses) {
for (const obj of res.Contents ?? []) {
if (!obj.Key || obj.Key.endsWith("/") || seen.has(obj.Key)) continue;
if (imageOnly && !isImageKey(obj.Key)) continue;
seen.set(obj.Key, toListedObject(obj, params.ctx));
}
}
Expand All @@ -331,6 +334,7 @@ export async function listObjects(params: {
if (!obj.Key || obj.Key.endsWith("/") || seen.has(obj.Key)) continue;
// Month-shard keys were already pulled via dedicated probes; skip to avoid duping.
if (monthShardPrefixesList.some((p) => obj.Key!.startsWith(p))) continue;
if (imageOnly && !isImageKey(obj.Key)) continue;
seen.set(obj.Key, toListedObject(obj, params.ctx));
}
const nextCursor = broadRes.IsTruncated
Expand Down Expand Up @@ -507,13 +511,15 @@ function finalize(
target: number,
sort: boolean,
skipPrefixes: readonly string[] = [],
imageOnly = false,
): ListObjectsResult {
const items = (response.Contents ?? [])
.filter(
(obj) =>
obj.Key &&
!obj.Key.endsWith("/") &&
!skipPrefixes.some((p) => obj.Key!.startsWith(p)),
!skipPrefixes.some((p) => obj.Key!.startsWith(p)) &&
(!imageOnly || isImageKey(obj.Key)),
)
.slice(0, target)
.map((obj) => toListedObject(obj, ctx));
Expand Down
Loading