npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

image-service

v0.3.151

Published

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

Downloads

4

Readme

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:

| environment | domain | | ----------- | --------------------------------------- | | int | https://imagecheck.int.brandwatch.net | | stage | https://imagecheck.stage.brandwatch.net | | live | https://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