Skip to content

Commit

Permalink
refactor: remove DropImageDecodeError event
Browse files Browse the repository at this point in the history
BREAKING CHANGE: remove `DropImageDecodeError` event

Error event is throw when a non-image file is dropped/picked in
QrcodeDropDown/QrcodeCapture. The validation step is now outsourced to
the BarcodeDetector polyfill which instead throws a standard
DOMException.
  • Loading branch information
gruhn committed Apr 7, 2021
1 parent 2c29d31 commit dea620e
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 25 deletions.
8 changes: 0 additions & 8 deletions src/misc/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ export class DropImageFetchError extends Error {
}
}

export class DropImageDecodeError extends Error {
constructor() {
super("drag-and-dropped file is not of type image and can't be decoded");

this.name = "DropImageDecodeError";
}
}

export class StreamApiNotSupportedError extends Error {
constructor() {
super("this browser has no Stream API support");
Expand Down
18 changes: 1 addition & 17 deletions src/misc/scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,9 @@ const imageElementFromUrl = async url => {
return image;
}

const imageElementFromFile = async file => {
if (/image.*/.test(file.type)) {
const reader = new FileReader();

reader.readAsDataURL(file);

const result = await eventOn(reader, "load");
const dataURL = result.target.result;

return imageElementFromUrl(dataURL);
} else {
throw new DropImageDecodeError();
}
}

export const processFile = async file => {
const barcodeDetector = new BarcodeDetector({ formats: ["qr_code"] })
const image = await imageElementFromFile(file);
const detectedCodes = await barcodeDetector.detect(image)
const detectedCodes = await barcodeDetector.detect(file)

return adaptOldFormat(detectedCodes)
}
Expand Down

0 comments on commit dea620e

Please sign in to comment.