-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3897a1d
Showing
17 changed files
with
543 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
github: ["Rstacx", "RsnLabs"] |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: "publish npm" | ||
|
||
on: push | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v2 | ||
- name: node | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 16 | ||
registry-url: https://registry.npmjs.org | ||
- name: install dependencies | ||
run: npm install | ||
- name: Build typescript | ||
run: npm run compile | ||
- name: publish | ||
run: npm publish --access public | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.npm_token }} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
package-lock.json |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN} | ||
registry=https://registry.npmjs.org/ | ||
always-auth=true |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 R Nilaweera | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<h1 align="center"><b>RsnFilter</b> <img src="https://i.ibb.co/0J89TrT/rsn-bot-1.png" width="30" style="border-radius: 50%; margin-bottom: -5px"></h1> | ||
<p align="center"><i>Advanced NSFW Image Detection Package</i></p> | ||
|
||
<p align="center"> <a href="https://www.digitalocean.com/?refcode=52756eb13d44&utm_campaign=Referral_Invite&utm_medium=Referral_Program&utm_source=badge"><img width=200 height=90 src="https://web-platforms.sfo2.cdn.digitaloceanspaces.com/WWW/Badge%203.svg" alt="DigitalOcean Referral Badge" /></a> </p> | ||
|
||
A comprehensive NSFW image detection npm package, equipped with advanced algorithms to ensure the safety and integrity of online platforms by swiftly identifying and filtering explicit content | ||
|
||
## Installation | ||
|
||
**Installation** | ||
|
||
```bash | ||
npm i rsn-filter | ||
``` | ||
|
||
# APIKEY | ||
|
||
Discord : [https://discord.gg/r5QWdKfQxr](https://discord.gg/r5QWdKfQxr) | ||
|
||
Join discord server and create account with **/new** slash command and get your apikey with **/key** slash command for free! | ||
|
||
## Usage Filter | ||
|
||
```javascript | ||
const { RsnFilter } = require("rsn-filter"); | ||
|
||
const rsnfilter = new RsnFilter("rsnai_××××××××××××××××××××××"); | ||
|
||
(async () => { | ||
const imageUrl = ""; | ||
|
||
try { | ||
const response = await rsnfilter.filter(imageUrl); | ||
|
||
if (response.result === true) { | ||
console.log(response.message); | ||
} | ||
|
||
if (response.result === false) { | ||
console.log(response.message); | ||
} | ||
} catch (error) { | ||
console.error("RsnFilter Error:", error); | ||
} | ||
})(); | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RsnFilter = void 0; | ||
const axios_1 = __importDefault(require("axios")); | ||
const apiUrl = "https://api.rsnai.org/api/v1/user"; | ||
class RsnFilter { | ||
constructor(apikey) { | ||
this.headers = { | ||
Authorization: "", | ||
}; | ||
if (!apikey) { | ||
throw new Error("Please provide API key"); | ||
} | ||
this.validateApiKey(apikey); | ||
this.headers = { | ||
Authorization: `Bearer ${apikey}`, | ||
}; | ||
} | ||
validateApiKey(apikey) { | ||
const validateUrl = `${apiUrl}/validate`; | ||
axios_1.default.post(validateUrl, { | ||
key: apikey | ||
}).then((res) => { | ||
if (res.status !== 200) { | ||
throw new Error(`Invalid API Key: ${apikey}`); | ||
} | ||
}).catch((error) => { | ||
if (error.response && error.response.status === 403) { | ||
throw new Error(`Invalid API Key (403 Forbidden): ${apikey}`); | ||
} | ||
else { | ||
throw new Error(`API Key Validation Error: ${error.message}`); | ||
} | ||
}); | ||
} | ||
filter(imageUrl) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!imageUrl.match(/\.(png|jpg|jpeg)$/)) { | ||
throw new Error("Invalid image URL. Only PNG, JPG, and JPEG formats are supported."); | ||
} | ||
try { | ||
const payload = { | ||
imageUrl: imageUrl, | ||
}; | ||
const response = yield axios_1.default.post(`${apiUrl}/nsfw-detect`, payload, { | ||
headers: this.headers, | ||
}); | ||
if (response.data.data.classification === "sfw") { | ||
return { | ||
result: false, | ||
message: "Image contains SFW content" | ||
}; | ||
} | ||
else { | ||
return { | ||
result: true, | ||
message: "Image contains NSFW content" | ||
}; | ||
} | ||
} | ||
catch (error) { | ||
throw new Error(`Nsfw Detect Error: ${error}`); | ||
} | ||
}); | ||
} | ||
} | ||
exports.RsnFilter = RsnFilter; |
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
import axios from "axios"; | ||
const apiUrl = "https://api.rsnai.org/api/v1/user"; | ||
class RsnFilter { | ||
constructor(apikey) { | ||
this.headers = { | ||
Authorization: "", | ||
}; | ||
if (!apikey) { | ||
throw new Error("Please provide API key"); | ||
} | ||
this.validateApiKey(apikey); | ||
this.headers = { | ||
Authorization: `Bearer ${apikey}`, | ||
}; | ||
} | ||
validateApiKey(apikey) { | ||
const validateUrl = `${apiUrl}/validate`; | ||
axios.post(validateUrl, { | ||
key: apikey | ||
}).then((res) => { | ||
if (res.status !== 200) { | ||
throw new Error(`Invalid API Key: ${apikey}`); | ||
} | ||
}).catch((error) => { | ||
if (error.response && error.response.status === 403) { | ||
throw new Error(`Invalid API Key (403 Forbidden): ${apikey}`); | ||
} | ||
else { | ||
throw new Error(`API Key Validation Error: ${error.message}`); | ||
} | ||
}); | ||
} | ||
filter(imageUrl) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!imageUrl.match(/\.(png|jpg|jpeg)$/)) { | ||
throw new Error("Invalid image URL. Only PNG, JPG, and JPEG formats are supported."); | ||
} | ||
try { | ||
const payload = { | ||
imageUrl: imageUrl, | ||
}; | ||
const response = yield axios.post(`${apiUrl}/nsfw-detect`, payload, { | ||
headers: this.headers, | ||
}); | ||
if (response.data.data.classification === "sfw") { | ||
return { | ||
result: false, | ||
message: "Image contains SFW content" | ||
}; | ||
} | ||
else { | ||
return { | ||
result: true, | ||
message: "Image contains NSFW content" | ||
}; | ||
} | ||
} | ||
catch (error) { | ||
throw new Error(`Nsfw Detect Error: ${error}`); | ||
} | ||
}); | ||
} | ||
} | ||
export { RsnFilter }; |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { renameSync, readdirSync } from "fs"; | ||
|
||
readdirSync("./build/cjs").forEach((e) => { | ||
renameSync(`./build/cjs/${e}`, `./build/cjs/${e.replace(".js", ".cjs")}`); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const { RsnFilter } = require("../build/cjs/index.cjs"); | ||
|
||
const rsnfilter = new RsnFilter("rsnai_××××××××××××××××××××××"); | ||
|
||
(async () => { | ||
const imageUrl = ""; | ||
|
||
try { | ||
const response = await rsnfilter.filter(imageUrl); | ||
|
||
if (response.result === true) { | ||
console.log(response.message); | ||
} | ||
|
||
if (response.result === false) { | ||
console.log(response.message); | ||
} | ||
} catch (error) { | ||
console.error("RsnFilter Error:", error); | ||
} | ||
})(); |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"name": "rsn-filter", | ||
"version": "1.0.0", | ||
"description": "A comprehensive NSFW image detection npm package, equipped with advanced algorithms to ensure the safety and integrity of online platforms by swiftly identifying and filtering explicit content", | ||
"type": "module", | ||
"types": "./types/index.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./types/index.d.ts", | ||
"require": "./build/cjs/index.cjs", | ||
"import": "./build/esm/index.js", | ||
"default": "./build/esm/index.js" | ||
}, | ||
"./*": { | ||
"types": "./types/*.d.ts", | ||
"require": "./build/cjs/*.cjs", | ||
"import": "./build/esm/*.js", | ||
"default": "./build/esm/*.js" | ||
} | ||
}, | ||
"scripts": { | ||
"test": "node example/test.cjs", | ||
"compile": "tsc -b ./tsconfig.cjs.json ./tsconfig.esm.json ./tsconfig.types.json && node compilec.js", | ||
"build:clean": "rm -rf ./build", | ||
"build": "npm-run-all build:clean compile" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/RsnLabs/rsn-filter" | ||
}, | ||
"funding": { | ||
"type": "buymeacoffee", | ||
"url": "https://www.buymeacoffee.com/rnilaweera" | ||
}, | ||
"author": "rnilaweera", | ||
"license": "MIT", | ||
"keywords": [ | ||
"ai", | ||
"image recognition", | ||
"content moderation", | ||
"online safety", | ||
"nsfw filtering", | ||
"explicit content detection", | ||
"image analysis", | ||
"content categorization", | ||
"image moderation", | ||
"online platform safety" | ||
], | ||
"dependencies": { | ||
"axios": "^1.6.3", | ||
"colors": "^1.4.0", | ||
"readline": "^1.3.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.11.6", | ||
"npm-run-all": "^4.1.5", | ||
"typescript": "^5.3.3", | ||
"undici-types": "^6.4.0" | ||
} | ||
} |
Oops, something went wrong.