fix: ignore images and files that are bigger than/equal 200k

Signed-off-by: Djamaile Rahamat <drahamat@bol.com>
This commit is contained in:
Djamaile Rahamat
2021-06-18 15:24:17 +02:00
committed by Patrik Oldsberg
parent 6817492aa9
commit 3ecd591475
3 changed files with 28 additions and 2 deletions
@@ -98,6 +98,11 @@ export class TarArchiveResponse implements ReadTreeResponse {
}
}
if (entry.size && entry.size >= 20000) {
entry.resume();
return;
}
const content = new Promise<Buffer>(async resolve => {
await pipeline(entry, concatStream(resolve));
});
@@ -68,6 +68,11 @@ export class ZipArchiveResponse implements ReadTreeResponse {
private shouldBeIncluded(entry: Entry): boolean {
const strippedPath = stripFirstDirectoryFromPath(entry.path);
const size = entry.vars.compressedSize;
if (size >= 20000) {
return false;
}
if (this.subPath) {
if (!strippedPath.startsWith(this.subPath)) {
@@ -27,6 +27,7 @@ import {
} from './types';
import { Config } from '@backstage/config';
import { createTodoParser } from './createTodoParser';
import path from 'path';
type Options = {
logger: Logger;
@@ -80,10 +81,25 @@ export class TodoScmReader implements TodoReader {
{ url }: ReadTodosOptions,
etag?: string,
): Promise<CacheItem> {
const shouldNotInclude = [
'.png',
'.svg',
'.jpg',
'.jpeg',
'.gif',
'.raw',
'.lock',
'.ico',
];
const tree = await this.reader.readTree(url, {
etag,
filter(path) {
return !path.startsWith('.') && !path.includes('/.');
filter(filePath) {
const extname = path.extname(filePath);
return (
!filePath.startsWith('.') &&
!filePath.includes('/.') &&
!shouldNotInclude.includes(extname)
);
},
});