Merge branch 'fix_download_certificate' into legacy_dev
All checks were successful
Test - Build & Deploy to Scaleway / build-and-push-images-lecoffre (push) Successful in 15s
Test - Build & Deploy to Scaleway / deploy-back-lecoffre (push) Successful in 3s
Test - Build & Deploy to Scaleway / deploy-cron-lecoffre (push) Successful in 3s

This commit is contained in:
Sosthene 2025-07-30 12:29:29 +02:00
commit c33d4faacd
2 changed files with 34 additions and 29 deletions

View File

@ -3,7 +3,7 @@ import { Controller, Get, Post } from "@ControllerPattern/index";
import ApiController from "@Common/system/controller-pattern/ApiController";
import { Service } from "typedi";
import { Document, OfficeFolder, File } from "le-coffre-resources/dist/Notary";
import { getFolderHashes, getFolderFilesUid } from "@Common/optics/notary";
import { getFolderFilesUid } from "@Common/optics/notary";
import OfficeFoldersService from "@Services/notary/OfficeFoldersService/OfficeFoldersService";
import OfficeFolderAnchorsRepository from "@Repositories/OfficeFolderAnchorsRepository";
import FilesService from "@Services/common/FilesService/FilesService";
@ -49,6 +49,27 @@ export default class OfficeFoldersController extends ApiController {
super();
}
private getValidatedDocumentHashes(officeFolder: OfficeFolder): string[] {
const documents = officeFolder.documents ?? [];
if (documents.length === 0) {
return [];
}
const folderHashes: string[] = [];
documents.forEach((document: any) => {
const documentHydrated = Document.hydrate<Document>(document, { strategy: "excludeAll" });
if (documentHydrated.document_status === "VALIDATED") {
documentHydrated.files?.forEach((file: any) => {
const fileHydrated = File.hydrate<File>(file, { strategy: "excludeAll" });
folderHashes.push(fileHydrated.hash);
});
}
});
return folderHashes.sort();
}
/**
* @description Download a folder anchoring proof document along with all accessible files
*/
@ -79,15 +100,14 @@ export default class OfficeFoldersController extends ApiController {
}
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFolderFound, { strategy: "excludeAll" });
const folderHashes = getFolderHashes(officeFolder);
const sortedHashes = this.getValidatedDocumentHashes(officeFolder);
const folderFilesUid = getFolderFilesUid(officeFolder);
if (folderHashes.length === 0) {
if (sortedHashes.length === 0) {
this.httpNotFoundRequest(response, "No file hash to anchor");
return;
}
const sortedHashes = [...folderHashes].sort();
const anchoringProof = await this.secureService.download(sortedHashes, officeFolder.office!.name);
@ -180,18 +200,13 @@ export default class OfficeFoldersController extends ApiController {
return;
}
const folderHashes: string[] = [];
documents.forEach((document: any) => {
const documentHydrated = Document.hydrate<Document>(document, { strategy: "excludeAll" });
if (documentHydrated.document_status === "VALIDATED") {
documentHydrated.files?.forEach((file: any) => {
const fileHydrated = File.hydrate<File>(file, { strategy: "excludeAll" });
folderHashes.push(fileHydrated.hash);
});
}
});
const sortedHashes = this.getValidatedDocumentHashes(officeFolder);
if (sortedHashes.length === 0) {
this.httpBadRequest(response, "No file hash to anchor");
return;
}
const sortedHashes = [...folderHashes].sort();
const data = await this.secureService.anchor(sortedHashes);
const officeFolderAnchor = hydrateOfficeFolderAnchor(data);
@ -248,23 +263,13 @@ export default class OfficeFoldersController extends ApiController {
return;
}
const folderHashes: string[] = [];
documents.forEach((document: any) => {
const documentHydrated = Document.hydrate<Document>(document, { strategy: "excludeAll" });
if (documentHydrated.document_status === "VALIDATED") {
documentHydrated.files?.forEach((file: any) => {
const fileHydrated = File.hydrate<File>(file, { strategy: "excludeAll" });
folderHashes.push(fileHydrated.hash);
});
}
});
const sortedHashes = this.getValidatedDocumentHashes(officeFolder);
if (folderHashes.length === 0) {
if (sortedHashes.length === 0) {
this.httpNotFoundRequest(response, "No file hash to anchor");
return;
}
const sortedHashes = [...folderHashes].sort();
const officeFolderAnchorFound = OfficeFolderAnchor.hydrate<OfficeFolderAnchor>(officeFolderFound.folder_anchor, {
strategy: "excludeAll",
});

View File

@ -95,7 +95,7 @@ export default class NotificationBuilder {
redirection_url: "",
created_at: new Date(),
updated_at: new Date(),
user: [user] || [],
user: user ? [user] : [],
});
}
@ -105,7 +105,7 @@ export default class NotificationBuilder {
redirection_url: "",
created_at: new Date(),
updated_at: new Date(),
user: [user] || [],
user: user ? [user] : [],
});
}