feat: optimize documents printing

This commit is contained in:
Ahmed Bouhuolia
2023-10-31 02:08:20 +02:00
parent 078a7ea51c
commit 6634144d82
9 changed files with 259 additions and 1 deletions

View File

@@ -0,0 +1,25 @@
import FormData from 'form-data';
import fetch from 'node-fetch';
export class GotenbergUtils {
public static assert(condition: boolean, message: string): asserts condition {
if (!condition) {
throw new Error(message);
}
}
public static async fetch(endpoint: string, data: FormData): Promise<Buffer> {
const response = await fetch(endpoint, {
method: 'post',
body: data,
headers: {
...data.getHeaders(),
},
});
if (!response.ok) {
throw new Error(`${response.status} ${response.statusText}`);
}
return response.buffer();
}
}