fix: filter paginated results (#3216)
This commit is contained in:
@ -251,7 +251,7 @@ export default class BitbucketBackend implements Implementation {
|
|||||||
|
|
||||||
const listFiles = () =>
|
const listFiles = () =>
|
||||||
this.api!.listFiles(folder, depth).then(({ entries, cursor: c }) => {
|
this.api!.listFiles(folder, depth).then(({ entries, cursor: c }) => {
|
||||||
cursor = c;
|
cursor = c.mergeMeta({ extension });
|
||||||
return filterByPropExtension(extension, 'path')(entries);
|
return filterByPropExtension(extension, 'path')(entries);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -397,16 +397,21 @@ export default class BitbucketBackend implements Implementation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
traverseCursor(cursor: Cursor, action: string) {
|
traverseCursor(cursor: Cursor, action: string) {
|
||||||
return this.api!.traverseCursor(cursor, action).then(
|
return this.api!.traverseCursor(cursor, action).then(async ({ entries, cursor: newCursor }) => {
|
||||||
async ({ entries, cursor: newCursor }) => ({
|
const extension = cursor.meta?.get('extension');
|
||||||
|
if (extension) {
|
||||||
|
entries = filterByPropExtension(extension as string, 'path')(entries);
|
||||||
|
newCursor = newCursor.mergeMeta({ extension });
|
||||||
|
}
|
||||||
|
return {
|
||||||
entries: await Promise.all(
|
entries: await Promise.all(
|
||||||
entries.map(file =>
|
entries.map(file =>
|
||||||
this.api!.readFile(file.path, file.id).then(data => ({ file, data: data as string })),
|
this.api!.readFile(file.path, file.id).then(data => ({ file, data: data as string })),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
cursor: newCursor,
|
cursor: newCursor,
|
||||||
}),
|
};
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
loadMediaFile(branch: string, file: UnpublishedEntryMediaFile) {
|
loadMediaFile(branch: string, file: UnpublishedEntryMediaFile) {
|
||||||
|
@ -141,7 +141,7 @@ export default class GitLab implements Implementation {
|
|||||||
|
|
||||||
const listFiles = () =>
|
const listFiles = () =>
|
||||||
this.api!.listFiles(folder, depth > 1).then(({ files, cursor: c }) => {
|
this.api!.listFiles(folder, depth > 1).then(({ files, cursor: c }) => {
|
||||||
cursor = c;
|
cursor = c.mergeMeta({ folder, extension, depth });
|
||||||
return files.filter(file => this.filterFile(folder, file, extension, depth));
|
return files.filter(file => this.filterFile(folder, file, extension, depth));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -245,16 +245,25 @@ export default class GitLab implements Implementation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
traverseCursor(cursor: Cursor, action: string) {
|
traverseCursor(cursor: Cursor, action: string) {
|
||||||
return this.api!.traverseCursor(cursor, action).then(
|
return this.api!.traverseCursor(cursor, action).then(async ({ entries, cursor: newCursor }) => {
|
||||||
async ({ entries, cursor: newCursor }) => ({
|
const [folder, depth, extension] = [
|
||||||
|
cursor.meta?.get('folder') as string,
|
||||||
|
cursor.meta?.get('depth') as number,
|
||||||
|
cursor.meta?.get('extension') as string,
|
||||||
|
];
|
||||||
|
if (folder && depth && extension) {
|
||||||
|
entries = entries.filter(f => this.filterFile(folder, f, extension, depth));
|
||||||
|
newCursor = newCursor.mergeMeta({ folder, extension, depth });
|
||||||
|
}
|
||||||
|
return {
|
||||||
entries: await Promise.all(
|
entries: await Promise.all(
|
||||||
entries.map(file =>
|
entries.map(file =>
|
||||||
this.api!.readFile(file.path, file.id).then(data => ({ file, data: data as string })),
|
this.api!.readFile(file.path, file.id).then(data => ({ file, data: data as string })),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
cursor: newCursor,
|
cursor: newCursor,
|
||||||
}),
|
};
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
loadMediaFile(branch: string, file: UnpublishedEntryMediaFile) {
|
loadMediaFile(branch: string, file: UnpublishedEntryMediaFile) {
|
||||||
|
@ -38,7 +38,16 @@ const jsToMap = (obj: {}) => {
|
|||||||
return immutableObj;
|
return immutableObj;
|
||||||
};
|
};
|
||||||
|
|
||||||
const knownMetaKeys = Set(['index', 'count', 'pageSize', 'pageCount', 'usingOldPaginationAPI']);
|
const knownMetaKeys = Set([
|
||||||
|
'index',
|
||||||
|
'count',
|
||||||
|
'pageSize',
|
||||||
|
'pageCount',
|
||||||
|
'usingOldPaginationAPI',
|
||||||
|
'extension',
|
||||||
|
'folder',
|
||||||
|
'depth',
|
||||||
|
]);
|
||||||
const filterUnknownMetaKeys = (meta: Map<string, string>) =>
|
const filterUnknownMetaKeys = (meta: Map<string, string>) =>
|
||||||
meta.filter((_v, k) => knownMetaKeys.has(k as string));
|
meta.filter((_v, k) => knownMetaKeys.has(k as string));
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user