Skip to content

Commit

Permalink
platerecognizer init
Browse files Browse the repository at this point in the history
  • Loading branch information
luancazarine committed May 14, 2024
1 parent 13d2bf3 commit 39a6c25
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import platerecognizer from "../../platerecognizer.app.mjs";
import { axios } from "@pipedream/platform";

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: platerecognizer.propDefinitions.imageFileOrUrl,
regions: platerecognizer.propDefinitions.regions,
cameraId: platerecognizer.propDefinitions.cameraId,
mmc: platerecognizer.propDefinitions.mmc,
config: platerecognizer.propDefinitions.config,
},
async run({ $ }) {
const formData = new FormData();
if (this.imageFileOrUrl.startsWith("http")) {
formData.append("upload", this.imageFileOrUrl);
} else {
const fs = require("fs");
formData.append("upload", fs.createReadStream(this.imageFileOrUrl));
}
if (this.regions) formData.append("regions", this.regions.join(","));
if (this.cameraId) formData.append("camera_id", this.cameraId);
if (this.mmc !== undefined) formData.append("mmc", this.mmc);
if (this.config) formData.append("config", this.config);

const response = await axios(this, {
method: "POST",
url: `${this.platerecognizer._baseUrl()}/plate-reader/`,
headers: {
"Authorization": `Token ${this.platerecognizer.$auth.api_key}`,
"Content-Type": "multipart/form-data",
},
data: formData,
maxContentLength: Infinity,
maxBodyLength: Infinity,
});

$.export("$summary", "Recognition process triggered successfully");
return response;
},
};
2 changes: 1 addition & 1 deletion components/platerecognizer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
"publishConfig": {
"access": "public"
}
}
}
69 changes: 66 additions & 3 deletions components/platerecognizer/platerecognizer.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,74 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "platerecognizer",
propDefinitions: {},
propDefinitions: {
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. Use comma-separated values for multiple regions (e.g., us-ca,us-ny).",
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: "string",
label: "Config",
description: "Additional configuration in JSON format.",
optional: true,
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
},
_baseUrl() {
return "https://api.platerecognizer.com/v1";
},
async triggerRecognition({
imageFileOrUrl, regions, cameraId, mmc, config,
}) {
const formData = new FormData();
if (imageFileOrUrl.startsWith("http")) {
formData.append("upload", imageFileOrUrl);
} else {
// Assuming the use of Node.js environment, fs should be used for local files
// And since the file needs to be read as a stream, ensure fs is properly imported
const fs = require("fs");
formData.append("upload", fs.createReadStream(imageFileOrUrl));
}
if (regions) formData.append("regions", regions.join(","));
if (cameraId) formData.append("camera_id", cameraId);
if (mmc !== undefined) formData.append("mmc", mmc);
if (config) formData.append("config", config);

return axios(this, {
method: "POST",
url: `${this._baseUrl()}/plate-reader/`,
headers: {
"Authorization": `Token ${this.$auth.api_key}`,
"Content-Type": "multipart/form-data",
},
data: formData,
maxContentLength: Infinity,
maxBodyLength: Infinity,
});
},
},
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { axios } from "@pipedream/platform";

Check failure on line 1 in components/platerecognizer/sources/new-recognition-instant/new-recognition-instant.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

'axios' is defined but never used
import platerecognizer from "../../platerecognizer.app.mjs";

export default {
key: "platerecognizer-new-recognition-instant",
name: "New Recognition Instant",
description: "Emits new event when a cloud webhook event is broadcasted.",
version: "0.0.{{ts}}",
type: "source",
dedupe: "unique",
props: {
platerecognizer,
db: "$.service.db",
http: {
type: "$.interface.http",
customResponse: true,
},
},
hooks: {
async deploy() {
console.log("Deploying new recognition instant source");
},
async activate() {
console.log("Activating new recognition instant source");
},
async deactivate() {
console.log("Deactivating new recognition instant source");
},
},
async run(event) {
const body = event.body;
if (!body) {
this.http.respond({
status: 400,
body: "No data received",
});
return;
}

this.http.respond({
status: 200,
body: "Success",
});

const eventData = {
hook: body.hook,
data: body.data,
};

this.$emit(eventData, {
id: eventData.data.timestamp,
summary: `New Recognition: ${eventData.data.results.map((result) => result.plate).join(", ")}`,
ts: Date.parse(eventData.data.timestamp),
});
},
};

0 comments on commit 39a6c25

Please sign in to comment.