Functioning Module
This commit is contained in:
commit
2c45c7325e
8 changed files with 222 additions and 0 deletions
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
node_modules/
|
||||||
|
build/
|
||||||
|
|
||||||
|
test.*
|
||||||
|
image.png
|
3
.npmignore
Normal file
3
.npmignore
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
test.*
|
||||||
|
node_modules/
|
||||||
|
image.png
|
7
README.md
Normal file
7
README.md
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# Fuzzysearch
|
||||||
|
|
||||||
|
API Wrapper for the [Fuzzysearch API], making it easier to programatically request the sources of an Image.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[fuzzysearch API]:https://api.fuzzysearch.net
|
22
package.json
Normal file
22
package.json
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
{
|
||||||
|
"name": "@thaldrin/fuzzysearch",
|
||||||
|
"version": "0.0.3",
|
||||||
|
"description": "API Wrapper for the Fuzzysearch API",
|
||||||
|
"main": "build/src/index.js",
|
||||||
|
"scripts": {
|
||||||
|
"build": "rm -rf build && tsc && echo Build Finished",
|
||||||
|
"test": "pnpm build && node test.js",
|
||||||
|
"prepublishOnly": "pnpm test"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"axios": "^0.27.2",
|
||||||
|
"form-data": "^4.0.0",
|
||||||
|
"node-fetch": "3.1.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^18.0.6"
|
||||||
|
}
|
||||||
|
}
|
116
pnpm-lock.yaml
generated
Normal file
116
pnpm-lock.yaml
generated
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
lockfileVersion: 5.4
|
||||||
|
|
||||||
|
specifiers:
|
||||||
|
'@types/node': ^18.0.6
|
||||||
|
axios: ^0.27.2
|
||||||
|
form-data: ^4.0.0
|
||||||
|
node-fetch: 3.1.1
|
||||||
|
|
||||||
|
dependencies:
|
||||||
|
axios: 0.27.2
|
||||||
|
form-data: 4.0.0
|
||||||
|
node-fetch: 3.1.1
|
||||||
|
|
||||||
|
devDependencies:
|
||||||
|
'@types/node': 18.0.6
|
||||||
|
|
||||||
|
packages:
|
||||||
|
|
||||||
|
/@types/node/18.0.6:
|
||||||
|
resolution: {integrity: sha512-/xUq6H2aQm261exT6iZTMifUySEt4GR5KX8eYyY+C4MSNPqSh9oNIP7tz2GLKTlFaiBbgZNxffoR3CVRG+cljw==}
|
||||||
|
dev: true
|
||||||
|
|
||||||
|
/asynckit/0.4.0:
|
||||||
|
resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/axios/0.27.2:
|
||||||
|
resolution: {integrity: sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==}
|
||||||
|
dependencies:
|
||||||
|
follow-redirects: 1.15.1
|
||||||
|
form-data: 4.0.0
|
||||||
|
transitivePeerDependencies:
|
||||||
|
- debug
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/combined-stream/1.0.8:
|
||||||
|
resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==}
|
||||||
|
engines: {node: '>= 0.8'}
|
||||||
|
dependencies:
|
||||||
|
delayed-stream: 1.0.0
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/data-uri-to-buffer/4.0.0:
|
||||||
|
resolution: {integrity: sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA==}
|
||||||
|
engines: {node: '>= 12'}
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/delayed-stream/1.0.0:
|
||||||
|
resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==}
|
||||||
|
engines: {node: '>=0.4.0'}
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/fetch-blob/3.2.0:
|
||||||
|
resolution: {integrity: sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==}
|
||||||
|
engines: {node: ^12.20 || >= 14.13}
|
||||||
|
dependencies:
|
||||||
|
node-domexception: 1.0.0
|
||||||
|
web-streams-polyfill: 3.2.1
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/follow-redirects/1.15.1:
|
||||||
|
resolution: {integrity: sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==}
|
||||||
|
engines: {node: '>=4.0'}
|
||||||
|
peerDependencies:
|
||||||
|
debug: '*'
|
||||||
|
peerDependenciesMeta:
|
||||||
|
debug:
|
||||||
|
optional: true
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/form-data/4.0.0:
|
||||||
|
resolution: {integrity: sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==}
|
||||||
|
engines: {node: '>= 6'}
|
||||||
|
dependencies:
|
||||||
|
asynckit: 0.4.0
|
||||||
|
combined-stream: 1.0.8
|
||||||
|
mime-types: 2.1.35
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/formdata-polyfill/4.0.10:
|
||||||
|
resolution: {integrity: sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==}
|
||||||
|
engines: {node: '>=12.20.0'}
|
||||||
|
dependencies:
|
||||||
|
fetch-blob: 3.2.0
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/mime-db/1.52.0:
|
||||||
|
resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==}
|
||||||
|
engines: {node: '>= 0.6'}
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/mime-types/2.1.35:
|
||||||
|
resolution: {integrity: sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==}
|
||||||
|
engines: {node: '>= 0.6'}
|
||||||
|
dependencies:
|
||||||
|
mime-db: 1.52.0
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/node-domexception/1.0.0:
|
||||||
|
resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==}
|
||||||
|
engines: {node: '>=10.5.0'}
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/node-fetch/3.1.1:
|
||||||
|
resolution: {integrity: sha512-SMk+vKgU77PYotRdWzqZGTZeuFKlsJ0hu4KPviQKkfY+N3vn2MIzr0rvpnYpR8MtB3IEuhlEcuOLbGvLRlA+yg==}
|
||||||
|
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
|
||||||
|
dependencies:
|
||||||
|
data-uri-to-buffer: 4.0.0
|
||||||
|
fetch-blob: 3.2.0
|
||||||
|
formdata-polyfill: 4.0.10
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/web-streams-polyfill/3.2.1:
|
||||||
|
resolution: {integrity: sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==}
|
||||||
|
engines: {node: '>= 8'}
|
||||||
|
dev: false
|
46
src/index.ts
Normal file
46
src/index.ts
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
import * as pkg from "../package.json";
|
||||||
|
import { ConstructorOptions } from "./utils/typings";
|
||||||
|
import axios from 'axios'
|
||||||
|
import FormData from 'form-data'
|
||||||
|
|
||||||
|
|
||||||
|
function useragent(ua?) {
|
||||||
|
return `${ua ? ua : ""} ${pkg.name}/v${pkg.version}`.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
function apibase(api) {
|
||||||
|
if (api !== undefined) return api;
|
||||||
|
else return "https://api.fuzzysearch.net";
|
||||||
|
}
|
||||||
|
class Fuzzysearch {
|
||||||
|
private api: string;
|
||||||
|
private ua: string;
|
||||||
|
private key: string;
|
||||||
|
|
||||||
|
constructor(options: ConstructorOptions) {
|
||||||
|
this.api = apibase(options.apibase);
|
||||||
|
this.key = options.apikey;
|
||||||
|
this.ua = useragent(options.useragent);
|
||||||
|
}
|
||||||
|
|
||||||
|
async find(image: Buffer, type: "close" | "exact" | "force" = "close") {
|
||||||
|
try {
|
||||||
|
let data = new FormData()
|
||||||
|
data.append("image",image, "probably_porn.png")
|
||||||
|
|
||||||
|
let req = await axios.post(`${this.api}/image?${type}`,data, {
|
||||||
|
headers: {
|
||||||
|
'accept': 'application/json',
|
||||||
|
'Content-Type': `multipart/form-data; boundary=${data.getBoundary()}`,
|
||||||
|
"X-API-KEY": this.key
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return req.data;
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Fuzzysearch;
|
||||||
|
module.exports = Fuzzysearch
|
5
src/utils/typings.ts
Normal file
5
src/utils/typings.ts
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
export type ConstructorOptions = {
|
||||||
|
apibase?: string
|
||||||
|
useragent?: string
|
||||||
|
apikey: string
|
||||||
|
}
|
18
tsconfig.json
Normal file
18
tsconfig.json
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
"$schema": "http://json.schemastore.org/tsconfig",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "./build",
|
||||||
|
"target": "ESNext",
|
||||||
|
"baseUrl": "src",
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"allowSyntheticDefaultImports": true,
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"module": "commonjs",
|
||||||
|
"paths": {},
|
||||||
|
"declaration": true,
|
||||||
|
"experimentalDecorators": true
|
||||||
|
},
|
||||||
|
"include": ["**/*"],
|
||||||
|
"exclude": ["node_modules", "build", "out", "test*", "tmp", "logs"]
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue