-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate data builder and QRcode generator
- Loading branch information
1 parent
628767e
commit 857c62c
Showing
3 changed files
with
34 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import QRCode from "qrcode"; | ||
|
||
import { DataUrl } from "../types/types"; | ||
import { TranslatableError } from "./error"; | ||
|
||
|
||
class QRCodeGenerator { | ||
|
||
protected readonly inputString: string; | ||
|
||
// TODO: make it configurable | ||
protected readonly quality = { | ||
margin: 1, | ||
width: 500 | ||
} | ||
|
||
public constructor(inputString: string) { | ||
this.inputString = inputString; | ||
} | ||
|
||
public async generate(): Promise<DataUrl> { | ||
try { | ||
return QRCode.toDataURL(this.inputString, this.quality); | ||
} | ||
catch (e: unknown) { | ||
throw new TranslatableError("generation.unknown_error") | ||
} | ||
} | ||
|
||
} | ||
|
||
export async function generateQR(inputString: string): Promise<DataUrl> { | ||
return await (new QRCodeGenerator(inputString)).generate(); | ||
} |
Empty file.
This file was deleted.
Oops, something went wrong.