Add frontend 2.0
This commit is contained in:
51
frontend/src/lib/covergen.ts
Normal file
51
frontend/src/lib/covergen.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
interface CoverArgs {
|
||||
customer: string;
|
||||
number: string;
|
||||
numberPrefix?: string;
|
||||
hlColor?: string;
|
||||
}
|
||||
|
||||
interface CoverError {
|
||||
error: string;
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
generateCover(args: CoverArgs): Uint8Array | CoverError;
|
||||
|
||||
generateSplitCover(
|
||||
args: CoverArgs
|
||||
): { front: Uint8Array; back: Uint8Array } | CoverError;
|
||||
}
|
||||
}
|
||||
|
||||
const go = new Go();
|
||||
WebAssembly.instantiateStreaming(fetch('covergen.wasm'), go.importObject).then(
|
||||
(result) => {
|
||||
go.run(result.instance);
|
||||
}
|
||||
);
|
||||
|
||||
export function generateCover(args: CoverArgs): File {
|
||||
const result = window.generateCover(args);
|
||||
if ('error' in result) {
|
||||
throw result.error;
|
||||
}
|
||||
|
||||
return new File([result], 'cover.pdf', { type: 'application/pdf' });
|
||||
}
|
||||
|
||||
export function generateSplitCover(args: CoverArgs): {
|
||||
front: File;
|
||||
back: File;
|
||||
} {
|
||||
const result = window.generateSplitCover(args);
|
||||
if ('error' in result) {
|
||||
throw result.error;
|
||||
}
|
||||
|
||||
return {
|
||||
front: new File([result.front], 'front.pdf', { type: 'application/pdf' }),
|
||||
back: new File([result.back], 'back.pdf', { type: 'application/pdf' }),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user