Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

perf(api): load pdf-lib and archiver only when used

Hampus7914f48ba1c3
diff --git a/fluxer_api/pkgs/email/src/EmailService.ts b/fluxer_api/pkgs/email/src/EmailService.ts
index 0d76c07df..c32cdeb42 100644
--- a/fluxer_api/pkgs/email/src/EmailService.ts
+++ b/fluxer_api/pkgs/email/src/EmailService.ts
@@ -794,6 +794,9 @@ export class EmailService implements IEmailService {
private async renderTermsAttachment(locale: string | null): Promise<EmailAttachment | null> {
const language = resolveOperatorPassTermsLanguage(locale);
try {
+ const {getOperatorPassTermsPdfFilename, renderOperatorPassTermsPdf} = await import(
+ '@pkgs/email/src/operator_pass_terms/OperatorPassTermsPdf'
+ );
return {
filename: getOperatorPassTermsPdfFilename(language),
content: await renderOperatorPassTermsPdf(language, this.config.marketingBaseUrl),
diff --git a/fluxer_api/src/api/worker/utils/ArchiveFile.ts b/fluxer_api/src/api/worker/utils/ArchiveFile.ts
index cb3469b11..177b7465b 100644
--- a/fluxer_api/src/api/worker/utils/ArchiveFile.ts
+++ b/fluxer_api/src/api/worker/utils/ArchiveFile.ts
@@ -3,7 +3,7 @@ import {lstat, opendir, readlink} from 'node:fs/promises';
import path from 'node:path';
import type {Readable} from 'node:stream';
import {finished, pipeline} from 'node:stream/promises';
-import {type Archiver, type EntryData, ZipArchive} from 'archiver';
+import type {Archiver, EntryData} from 'archiver';
export interface ArchiveEntryWriter {
append(source: Readable | Buffer | string, data: EntryData): Promise<void>;
@@ -27,6 +27,7 @@ export async function writeZipArchive(
filePath: string,
produce: (archive: ArchiveFileWriter) => void | Promise<void>,
): Promise<void> {
+ const {ZipArchive} = await import('archiver');
const archive: Archiver = new ZipArchive({zlib: {level: 6}});
const output = createWriteStream(filePath);
const outputClosed = new Promise<void>((resolve) => output.once('close', resolve));