mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
feat: optimize documents printing
This commit is contained in:
25
packages/server/src/lib/Chromiumly/GotenbergUtils.ts
Normal file
25
packages/server/src/lib/Chromiumly/GotenbergUtils.ts
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user