diff --git a/src/AnonymizedFile.ts b/src/AnonymizedFile.ts index cc9f6b0..4bb3dd6 100644 --- a/src/AnonymizedFile.ts +++ b/src/AnonymizedFile.ts @@ -55,8 +55,9 @@ export default class AnonymizedFile { const paths = this.anonymizedPath.trim().split("/"); - let currentAnonymized: TreeElement = - await this.repository.anonymizedFiles(); + let currentAnonymized: TreeElement = await this.repository.anonymizedFiles({ + includeSha: true, + }); let currentOriginal: TreeElement = await this.repository.files(); let currentOriginalPath = ""; let isAmbiguous = false; diff --git a/src/Repository.ts b/src/Repository.ts index 514acd6..95e5e3d 100644 --- a/src/Repository.ts +++ b/src/Repository.ts @@ -40,20 +40,22 @@ export default class Repository { * @param opt force to get an updated list of files * @returns The anonymized file tree */ - async anonymizedFiles(opt?: { force?: boolean }): Promise { + async anonymizedFiles(opt?: { + /** Force to refresh the file tree */ + force?: boolean; + /** Include the file sha in the response */ + includeSha: boolean; + }): Promise { const terms = this._model.options.terms || []; function anonymizeTreeRecursive(tree: TreeElement): TreeElement { if (Number.isInteger(tree.size) && tree.sha !== undefined) { - return tree as TreeFile; + if (opt?.includeSha) return tree as TreeFile; + return { size: tree.size } as TreeFile; } const output: Tree = {}; for (const file in tree) { const anonymizedPath = anonymizePath(file, terms); - if (output[anonymizedPath]) { - // file anonymization conflict - - } output[anonymizedPath] = anonymizeTreeRecursive(tree[file]); } return output; diff --git a/src/routes/repository-public.ts b/src/routes/repository-public.ts index d08ed4d..0762498 100644 --- a/src/routes/repository-public.ts +++ b/src/routes/repository-public.ts @@ -40,7 +40,7 @@ router.get( const repo = await getRepo(req, res); if (!repo) return; try { - res.json(await repo.anonymizedFiles({ force: true })); + res.json(await repo.anonymizedFiles({ includeSha: false })); } catch (error) { handleError(error, res); }