Skip to content

Commit

Permalink
Added polyfill. 📰
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbeutler committed Oct 23, 2022
1 parent 2494e0f commit 5f5c744
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pages/api/ocr.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from "next";

const atobPolyfill = (a: any) => Buffer.from(a, "base64").toString("binary");

import vision from "@google-cloud/vision";
import { GoogleAuth } from "google-auth-library";

Expand All @@ -16,7 +18,7 @@ const client: any = new vision.ImageAnnotatorClient({
const dataURLtoBlob = (dataurl: string) => {
let arr = dataurl.split(","),
mime = (arr as any)[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]),
bstr = atobPolyfill(arr[1]),
n = bstr.length,
u8arr = new Uint8Array(n);
while (n--) {
Expand Down
4 changes: 3 additions & 1 deletion pages/api/predict.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from "next";

const atobPolyfill = (a: any) => Buffer.from(a, "base64").toString("binary");

import vision from "@google-cloud/vision";

const client: any = new vision.ImageAnnotatorClient({
Expand All @@ -13,7 +15,7 @@ const client: any = new vision.ImageAnnotatorClient({
const dataURLtoBlob = (dataurl: string) => {
let arr = dataurl.split(","),
mime = (arr as any)[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]),
bstr = atobPolyfill(arr[1]),
n = bstr.length,
u8arr = new Uint8Array(n);
while (n--) {
Expand Down

2 comments on commit 5f5c744

@vercel
Copy link

@vercel vercel bot commented on 5f5c744 Oct 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

app-7rq9 – ./

app-7rq9-git-main-baselhack2022.vercel.app
app-7rq9.vercel.app
app-7rq9-baselhack2022.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 5f5c744 Oct 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

app – ./

app-coral-phi.vercel.app
app-baselhack2022.vercel.app
app-git-main-baselhack2022.vercel.app

Please sign in to comment.