-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Delete DeepAI provider * Decrease functiions threshold for tests * Add triggers * Verify image * Debug 1 * Debug 2 * Debug 3 * Debug 4 * Debug 5 * Debug 6 * Debug 7 * Debug 8 * Debug 9 * Fix 2 providers * Fix 2 providers * Debug 10 * Debug 11 * Debug 12 * Debug 13 * Debug 14 * Debug 15 * Debug 16 * Debug 17 * Remove image * Rollback changes * Decrease threshold
- Loading branch information
Showing
19 changed files
with
567 additions
and
180 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
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 |
---|---|---|
@@ -1,31 +1,36 @@ | ||
--- | ||
name: 'NSFW Detection Action' | ||
name: NSFW Detection Action | ||
author: Yevhen Fabizhevskyi | ||
description: 'This GitHub action detects NSFW content in committed files.' | ||
description: This GitHub Action detects NSFW content in committed files. | ||
branding: | ||
icon: alert-octagon | ||
color: red | ||
inputs: | ||
github_token: | ||
description: 'GitHub token' | ||
required: true | ||
type: | ||
description: 'Type of committed files separated by comma.' | ||
required: false | ||
default: 'modified,added,renamed' | ||
provider: | ||
description: 'Provider identifier.' | ||
description: Provider identifier. | ||
required: true | ||
api_key: | ||
description: 'API key that should be used for chosen provider.' | ||
api-key: | ||
description: API key required for the selected provider. | ||
required: true | ||
extensions: | ||
description: 'List of extensions separated by comma.' | ||
required: false | ||
default: 'jpeg,jpg,png,gif,webp,tiff,bmp' | ||
threshold: | ||
description: 'Action will be failed in case NSFW detection value will be greater or equal to this parameter.' | ||
description: | | ||
The action will fail if the NSFW detection value is greater than or equal | ||
to this parameter. | ||
required: true | ||
extensions: | ||
description: Comma-separated list of file extensions for NSFW detection. | ||
required: false | ||
default: jpeg,jpg,png,gif,webp,tiff,bmp | ||
types: | ||
description: Comma-separated types of changes made during work on the branch. | ||
required: false | ||
default: modified,added,renamed | ||
github-token: | ||
description: | | ||
GitHub token that is used to send requests to GitHub API. Defaults to the | ||
token provided by GitHub Actions environment. | ||
required: false | ||
default: ${{ github.token }} | ||
runs: | ||
using: 'node20' | ||
main: 'dist/index.js' | ||
using: node20 | ||
main: dist/index.js |
Large diffs are not rendered by default.
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
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
49 changes: 33 additions & 16 deletions
49
src/detection/providers/CloudmersiveNsfwDetectionProvider.ts
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,25 +1,42 @@ | ||
import FormData from 'form-data' | ||
import fs from 'fs' | ||
import NsfwDetectionProviderBase from './NsfwDetectionProviderBase' | ||
import CloudmersiveImageApiClient from 'cloudmersive-image-api-client' | ||
import { Logger } from 'winston' | ||
import { getLogger } from '../../logging/LoggerFactory' | ||
import { INsfwDetectionProvider } from '../NsfwDetectionProviderFactory' | ||
|
||
type CloudmersiveResponse = { | ||
Score: number | ||
Score: number, | ||
Successful: boolean, | ||
ClassificationOutcome: string | ||
} | ||
|
||
export class CloudmersiveNsfwDetectionProvider | ||
extends NsfwDetectionProviderBase { | ||
constructor() { | ||
super('https://api.cloudmersive.com/image/nsfw/classify') | ||
} | ||
|
||
public async getScore(apiKey: string, file: fs.PathLike): Promise<number> { | ||
const body = new FormData() | ||
body.append('imageFile', fs.createReadStream(file)) | ||
|
||
const headers = body.getHeaders() | ||
headers['apikey'] = apiKey | ||
implements INsfwDetectionProvider { | ||
private readonly logger: Logger = getLogger() | ||
|
||
const resp = await this.request<CloudmersiveResponse>(body, headers) | ||
return resp.Score | ||
public async getScore(apiKey: string, file: fs.PathLike): Promise<number | null> { | ||
const defaultClient = CloudmersiveImageApiClient.ApiClient.instance | ||
const Apikey = defaultClient.authentications['Apikey'] | ||
Apikey.apiKey = apiKey | ||
const apiInstance = new CloudmersiveImageApiClient.NsfwApi() | ||
const imageFile = Buffer.from(fs.readFileSync(file).buffer) | ||
return new Promise<number | null>((resolve, reject) => { | ||
const callback = (error, { Successful, Score }: CloudmersiveResponse, response) => { | ||
if (error) { | ||
if (!response.ok) { | ||
this.logger.error(`Status: ${response.status}. Reason: ${response.statusText}`) | ||
} | ||
reject(error) | ||
} else { | ||
if (!Successful) { | ||
this.logger.warning(`There was a problem during ${file} file classification`) | ||
resolve(null) | ||
} else { | ||
resolve(Score) | ||
} | ||
} | ||
} | ||
apiInstance.nsfwClassify(imageFile, callback) | ||
}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.