diff --git a/components/platerecognizer/actions/run-recognition/run-recognition.mjs b/components/platerecognizer/actions/run-recognition/run-recognition.mjs new file mode 100644 index 0000000000000..e424d3541f8bf --- /dev/null +++ b/components/platerecognizer/actions/run-recognition/run-recognition.mjs @@ -0,0 +1,67 @@ +import fs from "fs"; +import { checkTmp } from "../../common/utils.mjs"; +import platerecognizer from "../../platerecognizer.app.mjs"; + +export default { + key: "platerecognizer-run-recognition", + name: "Run Recognition", + description: "Triggers a recognition process using the Plate Recognizer SDK.", + version: "0.0.1", + type: "action", + props: { + platerecognizer, + imageFileOrUrl: { + type: "string", + label: "Image File or URL", + description: "The image file or URL to be recognized.", + }, + regions: { + type: "string[]", + label: "Regions", + description: "Regions to select specific license plate patterns. [See further details here](https://guides.platerecognizer.com/docs/other/country-codes/#country-codes)", + optional: true, + }, + cameraId: { + type: "string", + label: "Camera ID", + description: "The ID of the camera that took the image.", + optional: true, + }, + mmc: { + type: "boolean", + label: "MMC", + description: "Whether to detect vehicle make, model, and color.", + optional: true, + }, + config: { + type: "object", + label: "Config", + description: "Additional configuration. [See further details here](https://guides.platerecognizer.com/docs/snapshot/api-reference/#engine-configuration)", + optional: true, + }, + }, + async run({ $ }) { + const fileObj = {}; + + if (this.imageFileOrUrl.startsWith("http")) { + fileObj.upload_url = this.imageFileOrUrl; + } else { + const file = fs.readFileSync(checkTmp(this.imageFileOrUrl)); + fileObj.upload = Buffer(file).toString("base64"); + } + + const response = await this.platerecognizer.runRecognition({ + $, + data: { + ...fileObj, + regions: this.regions, + camera_id: this.cameraId, + mmc: this.mmc, + config: this.config, + }, + }); + + $.export("$summary", "Recognition process triggered successfully"); + return response; + }, +}; diff --git a/components/platerecognizer/common/utils.mjs b/components/platerecognizer/common/utils.mjs new file mode 100644 index 0000000000000..1a5e36f32a603 --- /dev/null +++ b/components/platerecognizer/common/utils.mjs @@ -0,0 +1,6 @@ +export const checkTmp = (filename) => { + if (!filename.startsWith("/tmp")) { + return `/tmp/${filename}`; + } + return filename; +}; diff --git a/components/platerecognizer/package.json b/components/platerecognizer/package.json index 61e75bdaccd64..763385296dc5f 100644 --- a/components/platerecognizer/package.json +++ b/components/platerecognizer/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/platerecognizer", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Plate Recognizer Components", "main": "platerecognizer.app.mjs", "keywords": [ @@ -11,5 +11,9 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^1.6.5" } -} \ No newline at end of file +} + diff --git a/components/platerecognizer/platerecognizer.app.mjs b/components/platerecognizer/platerecognizer.app.mjs index eb436c25ff5aa..5c83ad58b5f5e 100644 --- a/components/platerecognizer/platerecognizer.app.mjs +++ b/components/platerecognizer/platerecognizer.app.mjs @@ -1,11 +1,33 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "platerecognizer", - propDefinitions: {}, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.platerecognizer.com/v1"; + }, + _headers(headers) { + return { + "Authorization": `Token ${this.$auth.api_token}`, + ...headers, + }; + }, + _makeRequest({ + $ = this, path, headers = {}, ...opts + }) { + return axios($, { + url: `${this._baseUrl()}${path}`, + headers: this._headers(headers), + ...opts, + }); + }, + runRecognition(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/plate-reader/", + ...opts, + }); }, }, -}; \ No newline at end of file +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e33968d60512f..31449f797c40d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6323,7 +6323,10 @@ importers: specifiers: {} components/platerecognizer: - specifiers: {} + specifiers: + '@pipedream/platform': ^1.6.5 + dependencies: + '@pipedream/platform': 1.6.5 components/platform_ly: specifiers: {}