-
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.
Merge pull request #55 from techstartucalgary/feature/backend-scanner
Feature/backend scanner
- Loading branch information
Showing
20 changed files
with
163 additions
and
206 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,15 @@ | ||
version: "3" | ||
|
||
services: | ||
mysql: | ||
image: mysql | ||
environment: | ||
MYSQL_ROOT_PASSWORD: root | ||
MYSQL_DATABASE: rethread | ||
ports: | ||
- "3306:3306" | ||
volumes: | ||
- mysql:/var/lib/mysql | ||
|
||
volumes: | ||
mysql: |
Binary file not shown.
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
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,9 @@ | ||
import { Tag } from "../../types"; | ||
|
||
abstract class ScannerProvider { | ||
abstract getMaterials(text: string): Tag[]; | ||
|
||
abstract getTextFromImage(imagePath: string): Promise<string>; | ||
} | ||
|
||
export default ScannerProvider; |
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,30 +1,25 @@ | ||
import { Request, Response, NextFunction, response } from "express"; | ||
import ScannerService from "../services/scanner.service.js"; | ||
import { Tag } from "../../types.js"; | ||
import ScannerProvider from "../abstracts/scanner.abstract.js"; | ||
import { Request, Response, NextFunction } from "express"; | ||
|
||
class ScannerController { | ||
constructor(private service: ScannerService) { | ||
this.service = service; | ||
} | ||
postMaterials = async (//must send image as tag "image" and value base64 string. Returns JSON with the percentage and material of each material found on the tag | ||
req: Request, | ||
res: Response, | ||
next: NextFunction | ||
): Promise<Response<any, Record<string, any>> | void> => { | ||
constructor(private service: ScannerProvider) { | ||
this.service = service; | ||
} | ||
|
||
public postMaterials = async ( | ||
req: Request, | ||
res: Response, | ||
next: NextFunction | ||
): Promise<Response<any, Record<string, any>> | void> => { | ||
try { | ||
console.log("postMaterials called"); | ||
let materials = await (async () => { | ||
var str; | ||
str = await this.service.getMaterials(await this.service.getTextFromImage(req.body.image)); | ||
// console.log("Fuck: ", await str); | ||
return str; | ||
})(); | ||
console.log("materials: ",materials); | ||
return res.status(201).json(JSON.parse(materials)); | ||
const text: string = await this.service.getTextFromImage(req.body.image); | ||
const materials: Tag[] = this.service.getMaterials(text); | ||
return res.status(201).json(materials); | ||
} catch (e) { | ||
console.log("Error: ", e); | ||
next(e); | ||
next(e); | ||
} | ||
}; | ||
}; | ||
} | ||
|
||
export default ScannerController; | ||
export default ScannerController; |
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 @@ | ||
export class TesseractServiceError extends Error {} |
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
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
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
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,23 @@ | ||
import { createWorker } from "tesseract.js"; | ||
import { Tag } from "../../types.js"; | ||
import ScannerProvider from "../abstracts/scanner.abstract.js"; | ||
import { TesseractServiceError } from "../errors/tesseract.error.js"; | ||
|
||
class ScannerRepository implements ScannerProvider { | ||
public getMaterials = (_: string): Tag[] => { | ||
throw new Error("Method not implemented."); | ||
}; | ||
|
||
public getTextFromImage = async (imagePath: string): Promise<string> => { | ||
try { | ||
const worker: Tesseract.Worker = await createWorker("eng"); | ||
const ret: Tesseract.RecognizeResult = await worker.recognize(imagePath); | ||
await worker.terminate(); | ||
return ret.data.text; | ||
} catch (e) { | ||
throw new TesseractServiceError(); | ||
} | ||
}; | ||
} | ||
|
||
export default ScannerRepository; |
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import { Router } from "express"; | ||
import ScannerController from "../controllers/scanner.controller.js"; | ||
import ScannerService from "../services/scanner.service.js"; | ||
import ScannerRepository from "../repositories/scanner.repository.js"; | ||
import { Router } from "express"; | ||
|
||
const scannerRouter = Router(); | ||
|
||
const scannerController = new ScannerController(new ScannerService()); | ||
const scannerController = new ScannerController( | ||
new ScannerService(new ScannerRepository()) | ||
); | ||
|
||
scannerRouter.post("/", scannerController.postMaterials); | ||
|
||
export default scannerRouter; | ||
export default scannerRouter; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.