Skip to content

Commit

Permalink
Debug 10
Browse files Browse the repository at this point in the history
  • Loading branch information
fabasoad committed Jan 3, 2025
1 parent 42ff1bc commit aed3993
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

38 changes: 27 additions & 11 deletions src/detection/providers/SightEngineNsfwDetectionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@ import FormData from 'form-data'
import fs from 'fs'
import NsfwDetectionProviderBase from './NsfwDetectionProviderBase'

type SightEngineError = {
type: string,
code: number,
message: string
}

type SightEngineNudity = {
sexual_activity: number,
sexual_display: number,
erotica: number
}

type SightEngineResponse = {
status: string
nudity: {
sexual_activity: number,
sexual_display: number,
erotica: number,
}
status: string,
nudity?: SightEngineNudity,
error?: SightEngineError
}

export class SightEngineNsfwDetectionProvider
Expand All @@ -21,14 +30,21 @@ export class SightEngineNsfwDetectionProvider
const apiKeys: string[] = apiKey.split(',')
const body = new FormData()
body.append('media', fs.createReadStream(file))
body.append('models', 'nudity-2.1')
body.append('api_user', apiKeys[0])
body.append('api_secret', apiKeys[1])
body.append('models', 'nudity-2.1')

const { status, nudity } = await this.request<SightEngineResponse>(body)
if (status !== 'success') {
this.logger.warning(`There was a problem during ${file} file classification`)
const { status, nudity, error } = await this.request<SightEngineResponse>(body)
if (status === 'failure') {
const { type, code, message }: SightEngineError = error!
this.logger.warning(
`There was a problem during ${file} file classification. Type: ${type}.`
+ ` Code: ${code}. Reason: ${message}`
)
return 0
} else {
const { sexual_activity, sexual_display, erotica } = nudity!
return Math.max(sexual_activity, sexual_display, erotica)
}
return Math.max(nudity.sexual_activity, nudity.sexual_display, nudity.erotica)
}
}

0 comments on commit aed3993

Please sign in to comment.