0.3.151 • Published 1 year ago

image-service v0.3.151

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

Image Service

This service will proxy image requests through a NSFW filter, returning a placeholeder image if the original is deemed NSFW

Table of Contents

Setup

Install dependencies:

npm install

Requirements:

  • config.json file

e.g.

{
    "apiHost": "http://newapi.int.brandwatch.com",
    "apiPort": 80,
    "clientId": "clarifai-client-id",
    "clientSecret": "clarifai-client-secret"
}

Starting the app:

npm start

Using the service

This readme assumes you are running the service locally. The service is also running on integration, stage and live environments under the following domains:

environmentdomain
inthttps://imagecheck.int.brandwatch.net
stagehttps://imagecheck.stage.brandwatch.net
livehttps://imagecheck.brandwatch.com

Authentication

Requests to the image service require a valid Brandwatch API access token. This token should be sent in the Authorization header of the request. It can also be sent as a query paramater in the url, but this is not advised as it exposes your access token to the client side code.

Example:

# Access token in query params
curl 'http://localhost:6060/image?access_token=<valid API access token>'

# Access token in Authorization header
curl 'http://localhost:6060/image' -H 'Authorization: bearer <valid API access token>'

Endpoints

GET /image

Purpose: Analyses the given image url and returns the NSFW probability of the image.

Params:

  • access_token: A valid API access token
  • url: Url of the image to be analysed

Example:

curl 'http://localhost:6060/image?access_token=<valid API access token>&url=<image url to be analysed>'

GET /image-filter/

Purpose: Analyses the given image url and returns the image if it is below the given NSFW threshold or a placeholder image if it is above it.

Params:

  • access_token: A valid API access token
  • url: Url of the image to be filtered
  • threshold (optional): this is now an alias for nsfw to preserver backwards compatibility
  • placeholder (optional): Image url to be served if the image is deemed NSFW
  • gore (optional): string (strict|moderate|none) for the Gore filter threshold strictness. (none by default)
  • drug (optional): string (strict|moderate|none) for the Drug filter threshold strictness. (none by default)
  • explicit (optional): string (strict|moderate|none) for the Explicit filter threshold strictness. (none by default)
  • suggestive (optional): string (strict|moderate|none) for the Suggestive filter threshold strictness. (none by default)
  • nsfw (optional): string (strict|moderate|none) for the NSFW filter threshold strictness. (due to legacy support this will default to moderate)

Example:

<img  src="http://localhost:6060/image-filter/?access_token=<valid API access token>&url=<image url to be filtered>" />

GET /image-filter/filtered/:type

Purpose: Returns an array of images that have been filtered for a given threshold.

Params:

  • access_token: A valid API access token
  • threshold (optional): string (strict|moderate|none) for the filter threshold strictness.

URL Params:

  • type: (optional): string (gore, drug,explicit,suggestive,nsfw) the filter type to look at for filtered results (defaults to nsfw)

Example:

curl 'http://localhost:6060/image-filter/filtered?access_token=<valid API access token>&threshold=<threshold>'

GET /image-filter/whitelist

Purpose: Returns array of images for a client that will not be passed through the filter, regardless of their NSFW rating.

Params:

  • access_token: A valid API access token

Example:

curl 'http://localhost:6060/image-filter/whitelist?access_token=<valid API access token>'

POST /image-filter/whitelist

Purpose: Updates array of images for a client that will not be passed through the filter.

Params:

  • access_token: A valid API access token

Body:

  • url: Image url to be added to the whitelist

Example:

curl 'http://localhost:6060/image-filter/whitelist?access_token=<valid API access token>' -d '{"url": "<image url to be whitelisted>"}'

POST /image-filter/whitelist/remove

Purpose: Removes an image from a client's whitelisted images.

Params:

  • access_token: A valid API access token

Body:

  • url: Image url to be removed from the whitelist

Example:

curl 'http://localhost:6060/image-filter/whitelist/remove?access_token=<valid API access token>' -d '{"url": "<image url to be removed from whitelist>"}'

GET /image-filter/blacklist

Purpose: Returns array of images for a client that will not ever be returned from the service, regardless of their NSFW rating. The placeholder image will always be returned for images in this array

Params:

  • access_token: A valid API access token

Example:

curl 'http://localhost:6060/image-filter/blacklist?access_token=<valid API access token>'

POST /image-filter/blacklist

Purpose: Updates array of images for a client that will not be returned from the service.

Params:

  • access_token: A valid API access token

Body:

  • url: Image url to be added to the blacklist

Example:

curl 'http://localhost:6060/image-filter/blacklist?access_token=<valid API access token>' -d '{"url": "<image url to be blacklisted>"}'

POST /image-filter/blacklist/remove

Purpose: Removes an image from a client's blacklisted images.

Params:

  • access_token: A valid API access token

Body:

  • url: Image url to be removed from the blacklist

Example:

curl 'http://localhost:6060/image-filter/blacklist/remove?access_token=<valid API access token>' -d '{"url": "<image url to be removed from blacklist>"}'

Logs

By default the app will log to stdout. If NODE_ENV is set to production the app will log to disk. The app will produce a daily rotated requests.log. and image-service.log. log file.

Tests

npm test

CI build

npm run ci

Code coverage

npm run coverage

Code linter

npm run lint