mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-05-24 01:54:02 +02:00
hide sha in the file tree
This commit is contained in:
@@ -55,8 +55,9 @@ export default class AnonymizedFile {
|
|||||||
|
|
||||||
const paths = this.anonymizedPath.trim().split("/");
|
const paths = this.anonymizedPath.trim().split("/");
|
||||||
|
|
||||||
let currentAnonymized: TreeElement =
|
let currentAnonymized: TreeElement = await this.repository.anonymizedFiles({
|
||||||
await this.repository.anonymizedFiles();
|
includeSha: true,
|
||||||
|
});
|
||||||
let currentOriginal: TreeElement = await this.repository.files();
|
let currentOriginal: TreeElement = await this.repository.files();
|
||||||
let currentOriginalPath = "";
|
let currentOriginalPath = "";
|
||||||
let isAmbiguous = false;
|
let isAmbiguous = false;
|
||||||
|
|||||||
+8
-6
@@ -40,20 +40,22 @@ export default class Repository {
|
|||||||
* @param opt force to get an updated list of files
|
* @param opt force to get an updated list of files
|
||||||
* @returns The anonymized file tree
|
* @returns The anonymized file tree
|
||||||
*/
|
*/
|
||||||
async anonymizedFiles(opt?: { force?: boolean }): Promise<Tree> {
|
async anonymizedFiles(opt?: {
|
||||||
|
/** Force to refresh the file tree */
|
||||||
|
force?: boolean;
|
||||||
|
/** Include the file sha in the response */
|
||||||
|
includeSha: boolean;
|
||||||
|
}): Promise<Tree> {
|
||||||
const terms = this._model.options.terms || [];
|
const terms = this._model.options.terms || [];
|
||||||
|
|
||||||
function anonymizeTreeRecursive(tree: TreeElement): TreeElement {
|
function anonymizeTreeRecursive(tree: TreeElement): TreeElement {
|
||||||
if (Number.isInteger(tree.size) && tree.sha !== undefined) {
|
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 = {};
|
const output: Tree = {};
|
||||||
for (const file in tree) {
|
for (const file in tree) {
|
||||||
const anonymizedPath = anonymizePath(file, terms);
|
const anonymizedPath = anonymizePath(file, terms);
|
||||||
if (output[anonymizedPath]) {
|
|
||||||
// file anonymization conflict
|
|
||||||
|
|
||||||
}
|
|
||||||
output[anonymizedPath] = anonymizeTreeRecursive(tree[file]);
|
output[anonymizedPath] = anonymizeTreeRecursive(tree[file]);
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ router.get(
|
|||||||
const repo = await getRepo(req, res);
|
const repo = await getRepo(req, res);
|
||||||
if (!repo) return;
|
if (!repo) return;
|
||||||
try {
|
try {
|
||||||
res.json(await repo.anonymizedFiles({ force: true }));
|
res.json(await repo.anonymizedFiles({ includeSha: false }));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError(error, res);
|
handleError(error, res);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user