Reverting to old anchor proof method

This commit is contained in:
Vins 2024-10-23 09:48:36 +02:00
parent 0ffbe8a375
commit ea9ed5f4e7

View File

@ -17,33 +17,7 @@ export default class AnchoringProofService extends BaseService {
super(); super();
} }
/** private static svgTemplate = `<svg width="842" height="595" viewBox="0 0 842 595" fill="none" xmlns="http://www.w3.org/2000/svg">
* @description : Generate a PDF file from a SVG template from anchoring proof data
*/
public async generate(data: AnchoringProofData): Promise<Buffer> {
const browser = await puppeteer.launch({
executablePath: `/usr/bin/chromium`,
args: ["--no-sandbox", "--disable-setuid-sandbox"],
});
const page = await browser.newPage();
// const proofTemplateSvg = proofTemplate({
// rootHash: data.rootHash,
// anchoringTime: data.anchoringTime,
// officeName: data.office_name,
// txLink: data.txLink,
// });
const rootHash = data.rootHash;
const anchoringTime = data.anchoringTime;
const officeName = data.office_name;
const txLink = data.txLink;
var htmlContent = `
<html>
<body>
<svg width="842" height="595" viewBox="0 0 842 595" fill="none" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_523_25027)"> <g clip-path="url(#clip0_523_25027)">
<rect width="842" height="595" fill="#EFF0F6"/> <rect width="842" height="595" fill="#EFF0F6"/>
<g filter="url(#filter0_d_523_25027)"> <g filter="url(#filter0_d_523_25027)">
@ -62,18 +36,18 @@ export default class AnchoringProofService extends BaseService {
<path d="M361.804 54.869C361.892 55.0166 362.072 55.0884 362.24 55.0392L365.036 54.2109C365.185 54.1693 365.284 54.0331 365.284 53.8856V48.6695C365.284 48.2988 364.982 48 364.607 48H341.566C341.226 48 341.019 48.227 341.019 48.556L341 60.5012V71.3305C341 71.7012 341.302 72 341.677 72H364.718C365.059 72 365.265 71.7731 365.265 71.4402L365.284 59.4988V59.461C365.284 59.0184 365.219 58.7121 364.611 58.8823L363.514 59.2038C363.338 59.2567 363.223 59.4194 363.23 59.5972L363.25 59.9981C363.25 64.7527 360.744 68.1645 356.323 69.5036C349.09 71.6936 342.492 66.0804 343.077 59.1319C343.482 54.3622 347.361 50.4889 352.18 50.0501C356.258 49.6794 359.887 51.7031 361.8 54.8615L361.804 54.869Z" fill="#005BCB"/> <path d="M361.804 54.869C361.892 55.0166 362.072 55.0884 362.24 55.0392L365.036 54.2109C365.185 54.1693 365.284 54.0331 365.284 53.8856V48.6695C365.284 48.2988 364.982 48 364.607 48H341.566C341.226 48 341.019 48.227 341.019 48.556L341 60.5012V71.3305C341 71.7012 341.302 72 341.677 72H364.718C365.059 72 365.265 71.7731 365.265 71.4402L365.284 59.4988V59.461C365.284 59.0184 365.219 58.7121 364.611 58.8823L363.514 59.2038C363.338 59.2567 363.223 59.4194 363.23 59.5972L363.25 59.9981C363.25 64.7527 360.744 68.1645 356.323 69.5036C349.09 71.6936 342.492 66.0804 343.077 59.1319C343.482 54.3622 347.361 50.4889 352.18 50.0501C356.258 49.6794 359.887 51.7031 361.8 54.8615L361.804 54.869Z" fill="#005BCB"/>
<path d="M356.938 64.7943C357.96 64.0984 358.747 63.0922 359.164 61.9158C359.275 61.5943 359.363 61.2577 359.417 60.9135C359.451 60.7055 359.252 60.5315 359.05 60.5958L357.172 61.1783C357.091 61.2048 357.026 61.2653 356.996 61.3447C356.403 62.8085 354.873 63.7958 353.144 63.5877C351.457 63.3835 350.107 61.9991 349.958 60.3272C349.908 59.7674 349.988 59.2303 350.168 58.7423C350.685 57.3655 352.027 56.3821 353.599 56.3821C354.487 56.3821 355.301 56.696 355.936 57.218C356.009 57.2785 356.108 57.3012 356.204 57.2709L357.986 56.7187C358.086 56.6884 358.151 56.6128 358.178 56.5296C358.201 56.4426 358.189 56.3442 358.124 56.2686C356.973 54.9031 355.198 54.0672 353.228 54.1844C353.205 54.1882 353.182 54.192 353.159 54.192L352.551 52.278C352.475 52.0284 352.207 51.8884 351.954 51.9641L350.57 52.3915C350.317 52.4709 350.176 52.7357 350.256 52.9854L350.707 54.4114C350.788 54.661 350.688 54.9334 350.467 55.0733C349.369 55.7617 348.508 56.7981 348.061 58.0237C347.877 58.5154 347.762 59.0374 347.724 59.5783C347.713 59.7787 347.709 59.9754 347.716 60.1683C347.728 60.4293 347.556 60.6638 347.303 60.7433L345.781 61.2275C345.529 61.3069 345.387 61.5716 345.463 61.8213L345.896 63.1906C345.976 63.4402 346.244 63.5764 346.496 63.5007L348.045 63.0052C348.29 62.9296 348.562 63.0166 348.703 63.2284C349.759 64.7906 351.557 65.8232 353.599 65.8232C353.687 65.8232 353.771 65.8232 353.855 65.8232C354.123 65.8081 354.364 65.9783 354.444 66.2279L354.915 67.7258C354.995 67.9754 355.263 68.1154 355.515 68.036L356.9 67.6085C357.152 67.5329 357.29 67.2643 357.214 67.0147L356.716 65.4487C356.64 65.2066 356.728 64.9419 356.938 64.7981V64.7943Z" fill="#005BCB"/> <path d="M356.938 64.7943C357.96 64.0984 358.747 63.0922 359.164 61.9158C359.275 61.5943 359.363 61.2577 359.417 60.9135C359.451 60.7055 359.252 60.5315 359.05 60.5958L357.172 61.1783C357.091 61.2048 357.026 61.2653 356.996 61.3447C356.403 62.8085 354.873 63.7958 353.144 63.5877C351.457 63.3835 350.107 61.9991 349.958 60.3272C349.908 59.7674 349.988 59.2303 350.168 58.7423C350.685 57.3655 352.027 56.3821 353.599 56.3821C354.487 56.3821 355.301 56.696 355.936 57.218C356.009 57.2785 356.108 57.3012 356.204 57.2709L357.986 56.7187C358.086 56.6884 358.151 56.6128 358.178 56.5296C358.201 56.4426 358.189 56.3442 358.124 56.2686C356.973 54.9031 355.198 54.0672 353.228 54.1844C353.205 54.1882 353.182 54.192 353.159 54.192L352.551 52.278C352.475 52.0284 352.207 51.8884 351.954 51.9641L350.57 52.3915C350.317 52.4709 350.176 52.7357 350.256 52.9854L350.707 54.4114C350.788 54.661 350.688 54.9334 350.467 55.0733C349.369 55.7617 348.508 56.7981 348.061 58.0237C347.877 58.5154 347.762 59.0374 347.724 59.5783C347.713 59.7787 347.709 59.9754 347.716 60.1683C347.728 60.4293 347.556 60.6638 347.303 60.7433L345.781 61.2275C345.529 61.3069 345.387 61.5716 345.463 61.8213L345.896 63.1906C345.976 63.4402 346.244 63.5764 346.496 63.5007L348.045 63.0052C348.29 62.9296 348.562 63.0166 348.703 63.2284C349.759 64.7906 351.557 65.8232 353.599 65.8232C353.687 65.8232 353.771 65.8232 353.855 65.8232C354.123 65.8081 354.364 65.9783 354.444 66.2279L354.915 67.7258C354.995 67.9754 355.263 68.1154 355.515 68.036L356.9 67.6085C357.152 67.5329 357.29 67.2643 357.214 67.0147L356.716 65.4487C356.64 65.2066 356.728 64.9419 356.938 64.7981V64.7943Z" fill="#005BCB"/>
<text fill="black" xml:space="preserve" style="white-space: pre" font-family="Poppins" font-size="20" letter-spacing="-0.02em"><tspan x="266.5" y="110">Certificat de d&#xe9;p&#xf4;t international</tspan></text> <text fill="black" xml:space="preserve" style="white-space: pre" font-family="Poppins" font-size="20" letter-spacing="-0.02em"><tspan x="266.5" y="110">Certificat de d&#xe9;p&#xf4;t international</tspan></text>
<text fill="black" xml:space="preserve" style="white-space: pre" font-family="Poppins" font-size="16" font-weight="300" letter-spacing="0.005em"><tspan x="333" y="139.6">${anchoringTime}</tspan></text> <text fill="black" xml:space="preserve" style="white-space: pre" font-family="Poppins" font-size="16" font-weight="300" letter-spacing="0.005em"><tspan x="333" y="139.6">[[ANCHORING_TIME]]</tspan></text>
<text fill="#005BCB" xml:space="preserve" style="white-space: pre" font-family="Poppins" font-size="14" font-weight="600" letter-spacing="0.005em"><tspan x="48" y="200.4">Nom de l&#39;office</tspan></text> <text fill="#005BCB" xml:space="preserve" style="white-space: pre" font-family="Poppins" font-size="14" font-weight="600" letter-spacing="0.005em"><tspan x="48" y="200.4">Nom de l&#39;office</tspan></text>
<text fill="black" xml:space="preserve" style="white-space: pre" font-family="Poppins" font-size="12" font-weight="300" letter-spacing="0.005em"><tspan x="242" y="198.2">${officeName}</tspan></text> <text fill="black" xml:space="preserve" style="white-space: pre" font-family="Poppins" font-size="12" font-weight="300" letter-spacing="0.005em"><tspan x="242" y="198.2">[[OFFICE_NAME]]</tspan></text>
<path d="M32 214H810" stroke="#D7DCE0"/> <path d="M32 214H810" stroke="#D7DCE0"/>
<text fill="#005BCB" xml:space="preserve" style="white-space: pre" font-family="Poppins" font-size="14" font-weight="600" letter-spacing="0.005em"><tspan x="48" y="237.4">D&#xe9;posant(s)</tspan></text> <text fill="#005BCB" xml:space="preserve" style="white-space: pre" font-family="Poppins" font-size="14" font-weight="600" letter-spacing="0.005em"><tspan x="48" y="237.4">D&#xe9;posant(s)</tspan></text>
<text fill="black" xml:space="preserve" style="white-space: pre" font-family="Poppins" font-size="12" font-weight="300" letter-spacing="0.005em"><tspan x="242" y="235.2">LEcoffre.io</tspan></text> <text fill="black" xml:space="preserve" style="white-space: pre" font-family="Poppins" font-size="12" font-weight="300" letter-spacing="0.005em"><tspan x="242" y="235.2">LEcoffre.io</tspan></text>
<path d="M32 251H810" stroke="#D7DCE0"/> <path d="M32 251H810" stroke="#D7DCE0"/>
<text fill="#005BCB" xml:space="preserve" style="white-space: pre" font-family="Poppins" font-size="14" font-weight="600" letter-spacing="0.005em"><tspan x="48" y="274.4">Hash </tspan></text> <text fill="#005BCB" xml:space="preserve" style="white-space: pre" font-family="Poppins" font-size="14" font-weight="600" letter-spacing="0.005em"><tspan x="48" y="274.4">Hash </tspan></text>
<text fill="black" xml:space="preserve" style="white-space: pre" font-family="Poppins" font-size="12" font-weight="300" letter-spacing="0.005em"><tspan x="242" y="272.2">${rootHash}</tspan></text> <text fill="black" xml:space="preserve" style="white-space: pre" font-family="Poppins" font-size="12" font-weight="300" letter-spacing="0.005em"><tspan x="242" y="272.2">[[ROOT_HASH]]</tspan></text>
<path d="M32 288H810" stroke="#D7DCE0"/> <path d="M32 288H810" stroke="#D7DCE0"/>
<text fill="#005BCB" xml:space="preserve" style="white-space: pre" font-family="Poppins" font-size="14" font-weight="600" letter-spacing="0.005em"><tspan x="48" y="311.4">Explorateur blockchain</tspan></text> <text fill="#005BCB" xml:space="preserve" style="white-space: pre" font-family="Poppins" font-size="14" font-weight="600" letter-spacing="0.005em"><tspan x="48" y="311.4">Explorateur blockchain</tspan></text>
<text fill="black" xml:space="preserve" style="white-space: pre" font-family="Poppins" font-size="12" font-weight="300" letter-spacing="0.005em"><tspan x="242" y="309.2"><a href="${txLink}">${txLink}</a></tspan></text> <text fill="black" xml:space="preserve" style="white-space: pre" font-family="Poppins" font-size="12" font-weight="300" letter-spacing="0.005em"><tspan x="242" y="309.2"><a href="[[TX_LINK]]">[[TX_LINK]]</a></tspan></text>
<rect x="32" y="356" width="778" height="207" rx="8" fill="#F7F8F8"/> <rect x="32" y="356" width="778" height="207" rx="8" fill="#F7F8F8"/>
<g filter="url(#filter1_d_523_25027)"> <g filter="url(#filter1_d_523_25027)">
<path d="M145 392C145 380.954 153.954 372 165 372C176.046 372 185 380.954 185 392C185 403.046 176.046 412 165 412C153.954 412 145 403.046 145 392Z" fill="white" shape-rendering="crispEdges"/> <path d="M145 392C145 380.954 153.954 372 165 372C176.046 372 185 380.954 185 392C185 403.046 176.046 412 165 412C153.954 412 145 403.046 145 392Z" fill="white" shape-rendering="crispEdges"/>
@ -140,12 +114,41 @@ export default class AnchoringProofService extends BaseService {
<rect width="842" height="595" fill="white"/> <rect width="842" height="595" fill="white"/>
</clipPath> </clipPath>
</defs> </defs>
</svg> </svg>`;
/**
* @description : Generate a PDF file from a SVG template from anchoring proof data
*/
public async generate(data: AnchoringProofData): Promise<Buffer> {
const browser = await puppeteer.launch({
executablePath: `/usr/bin/chromium`,
args: ["--no-sandbox", "--disable-setuid-sandbox"],
});
const page = await browser.newPage();
var htmlContent = `
<html>
<body>
${AnchoringProofService.svgTemplate}
</body> </body>
</html> </html>
`; `;
htmlContent = htmlContent
.replace("[[ROOT_HASH]]", data.rootHash)
.replace("[[ANCHORING_TIME]]", data.anchoringTime)
.replace("[[OFFICE_NAME]]", data.office_name)
.replace(/\[\[TX_LINK\]\]/g, data.txLink);
// const proofTemplateSvg = proofTemplate({
// rootHash: data.rootHash,
// anchoringTime: data.anchoringTime,
// officeName: data.office_name,
// txLink: data.txLink,
// });
await page.setContent(htmlContent, { waitUntil: "networkidle0", timeout: 1200000 }); await page.setContent(htmlContent, { waitUntil: "networkidle0", timeout: 1200000 });
await page.addStyleTag({ await page.addStyleTag({
content: ` content: `