Skip to content

Commit

Permalink
what the fuck
Browse files Browse the repository at this point in the history
  • Loading branch information
dromzeh committed Mar 21, 2024
1 parent d547d7b commit 726d52d
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/v2/lib/helpers/check-image-tags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
type ModerationResponse = {
moderationLabels: {
labels: {
name: string
confidence: number
}[]
}[]
}

export async function CheckLabels(
ctx: APIContext,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
image: any // yolo
): Promise<boolean> {
if (ctx.env.ENVIRONMENT === "DEV") return

try {
const res = await fetch(
"https://aws-moderation.dromzeh.workers.dev/labels",
{
method: "POST",
body: image,
headers: {
Authorization: `Bearer ${ctx.env.REKOGNITION_LABEL_API_KEY}`,
},
}
)

if (res.status !== 200) {
throw new Error("Failed to check image labels")
}

const data = (await res.json()) as ModerationResponse

return data.moderationLabels.length > 0
} catch (error) {
throw new Error("Failed to check image labels")
}
}

0 comments on commit 726d52d

Please sign in to comment.